protected Digest getDigest() { return xmssParams.getDigest(); }
/** * Getter digest size. * * @return Digest size. */ public int getDigestSize() { return xmssParams.getDigestSize(); }
/** * Place holder BDS for when state is exhausted. * * @param params tree parameters * @param index the index that has been reached. */ BDS(XMSSParameters params, int index) { this(params.getWOTSPlus(), params.getHeight(), params.getK()); this.index = index; this.used = true; }
private WOTSPlusSignature wotsSign(byte[] messageDigest, OTSHashAddress otsHashAddress) { if (messageDigest.length != params.getDigestSize()) { throw new IllegalArgumentException("size of messageDigest needs to be equal to size of digest"); } if (otsHashAddress == null) { throw new NullPointerException("otsHashAddress == null"); } /* (re)initialize WOTS+ instance */ params.getWOTSPlus().importKeys(params.getWOTSPlus().getWOTSPlusSecretKey(privateKey.getSecretKeySeed(), otsHashAddress), privateKey.getPublicSeed()); /* create WOTS+ signature */ return params.getWOTSPlus().sign(messageDigest, otsHashAddress); } }
public Builder withSignature(byte[] val) { if (val == null) { throw new NullPointerException("signature == null"); } int n = params.getDigestSize(); int len = params.getWOTSPlus().getParams().getLen(); int height = params.getHeight(); int indexSize = 4; int randomSize = n; int signatureSize = len * n; int authPathSize = height * n; int position = 0; /* extract index */ index = Pack.bigEndianToInt(val, position); position += indexSize; /* extract random */ random = XMSSUtil.extractBytesAtOffset(val, position, randomSize); position += randomSize; withReducedSignature(XMSSUtil.extractBytesAtOffset(val, position, signatureSize + authPathSize)); return this; }
/** * XMSS Constructor... * * @param height Height of tree. * @param digest Digest to use. */ public XMSSParameters(int height, Digest digest) { super(); if (height < 2) { throw new IllegalArgumentException("height must be >= 2"); } if (digest == null) { throw new NullPointerException("digest == null"); } wotsPlus = new WOTSPlus(new WOTSPlusParameters(digest)); this.height = height; this.k = determineMinK(); oid = DefaultXMSSOid.lookup(getDigest().getAlgorithmName(), getDigestSize(), getWinternitzParameter(), wotsPlus.getParams().getLen(), height); /* * if (oid == null) { throw new InvalidParameterException(); } */ }
private XMSSPrivateKeyParameters(Builder builder) super(true, builder.params.getDigest().getAlgorithmName()); params = builder.params; if (params == null) int n = params.getDigestSize(); byte[] privateKey = builder.privateKey; if (privateKey != null) int height = params.getHeight(); int indexSize = 4; int secretKeySize = n; bdsState = bdsImport.withWOTSDigest(DigestUtil.getDigestOID(builder.xmss.getDigest().getAlgorithmName())); if (builder.index < ((1 << params.getHeight()) - 2) && tmpPublicSeed != null && tmpSecretKeySeed != null)
public int getHeight() { return keyParams.getParameters().getHeight(); }
private static XMSSPrivateKey xmssCreateKeyStructure(XMSSPrivateKeyParameters keyParams) { byte[] keyData = keyParams.toByteArray(); int n = keyParams.getParameters().getDigestSize(); int totalHeight = keyParams.getParameters().getHeight(); int indexSize = 4; int secretKeySize = n; int secretKeyPRFSize = n; int publicSeedSize = n; int rootSize = n; int position = 0; int index = (int)XMSSUtil.bytesToXBigEndian(keyData, position, indexSize); if (!XMSSUtil.isIndexValid(totalHeight, index)) { throw new IllegalArgumentException("index out of bounds"); } position += indexSize; byte[] secretKeySeed = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeySize); position += secretKeySize; byte[] secretKeyPRF = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeyPRFSize); position += secretKeyPRFSize; byte[] publicSeed = XMSSUtil.extractBytesAtOffset(keyData, position, publicSeedSize); position += publicSeedSize; byte[] root = XMSSUtil.extractBytesAtOffset(keyData, position, rootSize); position += rootSize; /* import BDS state */ byte[] bdsStateBinary = XMSSUtil.extractBytesAtOffset(keyData, position, keyData.length - position); return new XMSSPrivateKey(index, secretKeySeed, secretKeyPRF, publicSeed, root, bdsStateBinary); }
protected WOTSPlus getWOTSPlus() { return xmssParams.getWOTSPlus(); }
param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHA256Digest()), random); param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHA512Digest()), random); param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHAKEDigest(128)), random); param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHAKEDigest(256)), random);
private XMSSPublicKeyParameters(Builder builder) super(false, builder.params.getDigest().getAlgorithmName()); params = builder.params; if (params == null) int n = params.getDigestSize(); byte[] publicKey = builder.publicKey; if (publicKey != null)
/** * Getter Winternitz parameter. * * @return Winternitz parameter. */ public int getWinternitzParameter() { return xmssParams.getWinternitzParameter(); }
public byte[] toByteArray() { /* signature || authentication path */ int n = params.getDigestSize(); int signatureSize = params.getWOTSPlus().getParams().getLen() * n; int authPathSize = params.getHeight() * n; int totalSize = signatureSize + authPathSize; byte[] out = new byte[totalSize]; int position = 0; /* copy signature */ byte[][] signature = this.wotsPlusSignature.toByteArray(); for (int i = 0; i < signature.length; i++) { XMSSUtil.copyBytesAtOffset(out, signature[i], position); position += n; } /* copy authentication path */ for (int i = 0; i < authPath.size(); i++) { byte[] value = authPath.get(i).getValue(); XMSSUtil.copyBytesAtOffset(out, value, position); position += n; } return out; }
public int getHeight() { return keyParams.getParameters().getHeight(); }
if (!XMSSUtil.isIndexValid(params.getHeight(), index)) XMSSUtil.toBytesBigEndian(index, params.getDigestSize())); byte[] messageDigest = khf.HMsg(concatenated, message);
/** * XMSS constructor... * * @param params XMSSParameters. */ public XMSS(XMSSParameters params, SecureRandom prng) { super(); if (params == null) { throw new NullPointerException("params == null"); } this.params = params; wotsPlus = params.getWOTSPlus(); this.prng = prng; }
public KeyPair generateKeyPair() { if (!initialised) { param = new XMSSKeyGenerationParameters(new XMSSParameters(10, new SHA512Digest()), random); engine.init(param); initialised = true; } AsymmetricCipherKeyPair pair = engine.generateKeyPair(); XMSSPublicKeyParameters pub = (XMSSPublicKeyParameters)pair.getPublic(); XMSSPrivateKeyParameters priv = (XMSSPrivateKeyParameters)pair.getPrivate(); return new KeyPair(new BCXMSSPublicKey(treeDigest, pub), new BCXMSSPrivateKey(treeDigest, priv)); } }
int n = params.getDigestSize(); int len = params.getWOTSPlus().getParams().getLen(); int height = params.getHeight(); byte[] reducedSignature = builder.reducedSignature; if (reducedSignature != null) position += n; this.wotsPlusSignature = new WOTSPlusSignature(params.getWOTSPlus().getParams(), wotsPlusSignature); wotsPlusSignature = new WOTSPlusSignature(params.getWOTSPlus().getParams(), new byte[len][n]);
/** * Set up constructor. * * @param params tree parameters * @param publicSeed public seed for tree * @param secretKeySeed secret seed for tree * @param otsHashAddress hash address */ BDS(XMSSParameters params, byte[] publicSeed, byte[] secretKeySeed, OTSHashAddress otsHashAddress) { this(params.getWOTSPlus(), params.getHeight(), params.getK()); this.initialize(publicSeed, secretKeySeed, otsHashAddress); }