diff options
author | dangrasso <danielegrasso86@gmail.com> | 2013-09-12 22:43:32 +0400 |
---|---|---|
committer | dangrasso <danielegrasso86@gmail.com> | 2013-09-12 22:43:32 +0400 |
commit | 94447e133ce85abf752c18d5cac0dc34d5408d6e (patch) | |
tree | a6b0a7a42431dec7f68cbbaec254156d199afcb3 /core/src/main/java/org/bouncycastle | |
parent | 55366ae07342f7e7a8832cf17e1bb69862c0cc29 (diff) |
Update SRP6Util.java
adds calculateM1, calculateM2, calculateKey
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/agreement/srp/SRP6Util.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/agreement/srp/SRP6Util.java b/core/src/main/java/org/bouncycastle/crypto/agreement/srp/SRP6Util.java index ad5ceac8..bf1b1377 100644 --- a/core/src/main/java/org/bouncycastle/crypto/agreement/srp/SRP6Util.java +++ b/core/src/main/java/org/bouncycastle/crypto/agreement/srp/SRP6Util.java @@ -60,6 +60,65 @@ public class SRP6Util return val; } + + /** + * Computes the client evidence message (M1) according to the standard routine: + * M1 = H( A | B | S ) + * @param digest The Digest used as the hashing function H + * @param A The public client value + * @param B The public server value + * @param S The secret calculated by both sides + * @return M1 The calculated client evidence message + */ + public static BigInteger calculateM1(Digest digest, BigInteger A, BigInteger B, BigInteger S) { + byte[] _output = new byte[digest.getDigestSize()]; + byte[] _A = A.toByteArray(); + byte[] _B = B.toByteArray(); + byte[] _S = S.toByteArray(); + digest.update(_A, 0, _A.length); + digest.update(_B, 0, _B.length); + digest.update(_S, 0, _S.length); + digest.doFinal(_output, 0); + BigInteger M1 = new BigInteger(1, _output); + return M1; + } + + /** + * Computes the server evidence message (M2) according to the standard routine: + * M2 = H( A | M1 | S ) + * @param digest The Digest used as the hashing function H + * @param A The public client value + * @param M1 The client evidence message + * @param S The secret calculated by both sides + * @return M2 The calculated server evidence message + */ + public static BigInteger calculateM2(Digest digest, BigInteger A, BigInteger M1, BigInteger S){ + byte[] _output = new byte[digest.getDigestSize()]; + byte[] _A = A.toByteArray(); + byte[] _M1 = M1.toByteArray(); + byte[] _S = S.toByteArray(); + digest.update(_A, 0, _A.length); + digest.update(_M1,0,_M1.length); + digest.update(_S, 0, _S.length); + digest.doFinal(_output, 0); + BigInteger M2 = new BigInteger(1, _output); + return M2; + } + + /** + * Computes the final Key according to the standard routine: Key = H(S) + * @param digest The Digest used as the hashing function H + * @param S The secret calculated by both sides + * @return + */ + public static BigInteger calculateKey(Digest digest, BigInteger S) { + byte[] _output = new byte[digest.getDigestSize()]; + byte[] _S = S.toByteArray(); + digest.update(_S, 0, _S.length); + digest.doFinal(_output, 0); + BigInteger Key = new BigInteger(1, _output); + return Key; + } private static BigInteger hashPaddedPair(Digest digest, BigInteger N, BigInteger n1, BigInteger n2) { |