/** * Verify an XMSS signature. * * @param message Message. * @param signature XMSS signature. * @param publicKey XMSS public key. * @return true if signature is valid false else. * @throws ParseException */ public boolean verifySignature(byte[] message, byte[] signature, byte[] publicKey) throws ParseException { if (message == null) { throw new NullPointerException("message == null"); } if (signature == null) { throw new NullPointerException("signature == null"); } if (publicKey == null) { throw new NullPointerException("publicKey == null"); } XMSSSigner signer = new XMSSSigner(); signer.init(false, new XMSSPublicKeyParameters.Builder(getParams()).withPublicKey(publicKey).build()); return signer.verifySignature(message, signature); }
/** * Generate a WOTS+ signature on a message without the corresponding * authentication path * * @param messageDigest Message digest of length n. * @param otsHashAddress OTS hash address. * @return XMSS signature. */ protected 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 */ wotsPlus.importKeys(wotsPlus.getWOTSPlusSecretKey(privateKey.getSecretKeySeed(), otsHashAddress), getPublicSeed()); /* create WOTS+ signature */ return wotsPlus.sign(messageDigest, otsHashAddress); }
/** * Sign message. * * @param message Message to sign. * @return XMSS signature on digest of message. */ public byte[] sign(byte[] message) { if (message == null) { throw new NullPointerException("message == null"); } XMSSSigner signer = new XMSSSigner(); signer.init(true, privateKey); byte[] signature = signer.generateSignature(message); privateKey = (XMSSPrivateKeyParameters)signer.getUpdatedPrivateKey(); importState(privateKey, publicKey); return signature; }
protected void setPublicSeed(byte[] publicSeed) { privateKey = new XMSSPrivateKeyParameters.Builder(params) .withSecretKeySeed(privateKey.getSecretKeySeed()).withSecretKeyPRF(privateKey.getSecretKeyPRF()) .withPublicSeed(publicSeed).withRoot(getRoot()).withBDSState(privateKey.getBDSState()).build(); publicKey = new XMSSPublicKeyParameters.Builder(params).withRoot(getRoot()).withPublicSeed(publicSeed) .build(); wotsPlus.importKeys(new byte[params.getDigestSize()], publicSeed); }
.withPrivateKey(privateKey, this.getParams()).build(); XMSSPublicKeyParameters tmpPublicKey = new XMSSPublicKeyParameters.Builder(params).withPublicKey(publicKey) .build();
protected void setRoot(byte[] root) { privateKey = new XMSSPrivateKeyParameters.Builder(params) .withSecretKeySeed(privateKey.getSecretKeySeed()).withSecretKeyPRF(privateKey.getSecretKeyPRF()) .withPublicSeed(getPublicSeed()).withRoot(root).withBDSState(privateKey.getBDSState()).build(); publicKey = new XMSSPublicKeyParameters.Builder(params).withRoot(root).withPublicSeed(getPublicSeed()) .build(); }
/** * Generate a new XMSS private key / public key pair. */ public void generateKeys() { XMSSKeyPairGenerator kpGen = new XMSSKeyPairGenerator(); kpGen.init(new XMSSKeyGenerationParameters(getParams(), prng)); AsymmetricCipherKeyPair kp = kpGen.generateKeyPair(); privateKey = (XMSSPrivateKeyParameters)kp.getPrivate(); publicKey = (XMSSPublicKeyParameters)kp.getPublic(); wotsPlus.importKeys(new byte[params.getDigestSize()], this.privateKey.getPublicSeed()); }