@Override protected void writePubKeyContentsIntoBuffer(PublicKey pk, Buffer<?> buf) { EdDSAPublicKey key = (EdDSAPublicKey) pk; buf.putBytes(key.getAbyte()); }
private static EdDSAEngine getEngine() { try { return new EdDSAEngine(MessageDigest.getInstance("SHA-512")); } catch (NoSuchAlgorithmException e) { throw new SSHRuntimeException(e); } }
@Override protected boolean engineVerify(byte[] sigBytes) throws SignatureException { try { return x_engineVerify(sigBytes); } finally { reset(); } }
kp = new KeyPair(publicKey, new EdDSAPrivateKey(new EdDSAPrivateKeySpec(privKey, EdDSANamedCurveTable.getByName("Ed25519")))); break; case RSA:
/** * @since 0.9.25 */ public EdDSAPrivateKey(PKCS8EncodedKeySpec spec) throws InvalidKeySpecException { this(new EdDSAPrivateKeySpec(decode(spec.getEncoded()), EdDSANamedCurveTable.ED_25519_CURVE_SPEC)); }
/** * To efficiently sign all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data, off, len) * sig = sign() *</pre> * * @param data byte array containing the message to be signed * @param off the start of the message inside data * @param len the length of the message * @return the signature * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public byte[] signOneShot(byte[] data, int off, int len) throws SignatureException { oneShotMode = true; update(data, off, len); return sign(); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data, off, len) * ok = verify(signature, sigoff, siglen) *</pre> * * @param data byte array containing the message that was signed * @param off the start of the message inside data * @param len the length of the message * @param signature byte array containing the signature * @param sigoff the start of the signature * @param siglen the length of the signature * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature, int sigoff, int siglen) throws SignatureException { oneShotMode = true; update(data, off, len); return verify(signature, sigoff, siglen); }
/** * Gets a value indicating whether or not the field element is non-zero. * * @return 1 if it is non-zero, 0 otherwise. */ public boolean isNonZero() { final byte[] s = toByteArray(); return Utils.equal(s, ZERO) == 0; }
@Override public String toString() { return "[Ed25519FieldElement val="+Utils.bytesToHex(toByteArray())+"]"; } }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * ok = verify(signature) *</pre> * * @param data the message that was signed * @param signature of the message * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, byte[] signature) throws SignatureException { return verifyOneShot(data, 0, data.length, signature, 0, signature.length); }
@Override protected byte[] engineSign() throws SignatureException { try { return x_engineSign(); } finally { reset(); // must leave the object ready to sign again with // the same key, as required by the API EdDSAPrivateKey privKey = (EdDSAPrivateKey) key; digestInitSign(privKey); } }
/** * @since 0.9.15 */ public static SigningPrivateKey fromJavaKey(EdDSAPrivateKey pk, SigType type) throws GeneralSecurityException { return new SigningPrivateKey(type, pk.getSeed()); }
/** * To efficiently sign all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * sig = sign() *</pre> * * @param data the message to be signed * @return the signature * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public byte[] signOneShot(byte[] data) throws SignatureException { return signOneShot(data, 0, data.length); }
/** * Gets the underlying finite field with q=2^255 - 19 elements. * * @return The finite field. */ public static Field getField() { return new Field( 256, // b Utils.hexToBytes("edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"), // q new Ed25519LittleEndianEncoding()); }
/** * Constant-time byte[] comparison. * @param b a byte[] * @param c a byte[] * @return 1 if b and c are equal, 0 otherwise. */ public static int equal(byte[] b, byte[] c) { int result = 0; for (int i = 0; i < 32; i++) { result |= b[i] ^ c[i]; } return equal(result, 0); }
public TestTuple(String line) { caseNum = ++numCases; String[] x = line.split(":"); seed = Utils.hexToBytes(x[0].substring(0, 64)); pk = Utils.hexToBytes(x[1]); message = Utils.hexToBytes(x[2]); sig = Utils.hexToBytes(x[3].substring(0, 128)); } }
/** * @since 0.9.15 */ public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type) throws GeneralSecurityException { return new SigningPublicKey(type, pk.getAbyte()); }
@Override public boolean equals(Object obj) { if (!(obj instanceof Ed25519FieldElement)) return false; Ed25519FieldElement fe = (Ed25519FieldElement) obj; return 1==Utils.equal(toByteArray(), fe.toByteArray()); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * ok = verify(signature, sigoff, siglen) *</pre> * * @param data the message that was signed * @param signature byte array containing the signature * @param sigoff the start of the signature * @param siglen the length of the signature * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, byte[] signature, int sigoff, int siglen) throws SignatureException { return verifyOneShot(data, 0, data.length, signature, sigoff, siglen); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data, off, len) * ok = verify(signature) *</pre> * * @param data byte array containing the message that was signed * @param off the start of the message inside data * @param len the length of the message * @param signature of the message * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature) throws SignatureException { return verifyOneShot(data, off, len, signature, 0, signature.length); }