All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.crypto.xmss.XMSSAddress Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8. Note: this package includes the NTRU encryption algorithms.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.pqc.crypto.xmss;

import org.bouncycastle.pqc.crypto.xmss.XMSSUtil;

/**
 * XMSS address.
 *
 */
public abstract class XMSSAddress {

	private final int layerAddress;
	private final long treeAddress;
	private final int type;
	private final int keyAndMask;

	protected XMSSAddress(Builder builder) {
		layerAddress = builder.layerAddress;
		treeAddress = builder.treeAddress;
		type = builder.type;
		keyAndMask = builder.keyAndMask;
	}

	protected static abstract class Builder {

		/* mandatory */
		private final int type;
		/* optional */
		private int layerAddress = 0;
		private long treeAddress = 0L;
		private int keyAndMask = 0;

		protected Builder(int type) {
			super();
			this.type = type;
		}

		protected T withLayerAddress(int val) {
			layerAddress = val;
			return getThis();
		}
		
		protected T withTreeAddress(long val) {
			treeAddress = val;
			return getThis();
		}
		
		protected T withKeyAndMask(int val) {
			keyAndMask = val;
			return getThis();
		}
		
		protected abstract XMSSAddress build();
		protected abstract T getThis();
	}

	protected byte[] toByteArray() {
		byte[] byteRepresentation = new byte[32];
		XMSSUtil.intToBytesBigEndianOffset(byteRepresentation, layerAddress, 0);
		XMSSUtil.longToBytesBigEndianOffset(byteRepresentation, treeAddress, 4);
		XMSSUtil.intToBytesBigEndianOffset(byteRepresentation, type, 12);
		XMSSUtil.intToBytesBigEndianOffset(byteRepresentation, keyAndMask, 28);
		return byteRepresentation;
	}

	protected final int getLayerAddress() {
		return layerAddress;
	}

	protected final long getTreeAddress() {
		return treeAddress;
	}

	public final int getType() {
		return type;
	}

	public final int getKeyAndMask() {
		return keyAndMask;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy