001package com.bitbucket.thinbus.srp6.js;
002
003import static com.nimbusds.srp6.BigIntegerUtils.toHex;
004
005import java.math.BigInteger;
006
007import com.nimbusds.srp6.ClientEvidenceRoutine;
008import com.nimbusds.srp6.SRP6ClientEvidenceContext;
009import com.nimbusds.srp6.SRP6CryptoParams;
010
011/**
012 * Custom routine interface for computing the client evidence message 'M1'.
013 * Compatible with browser implementations by using hashing of concatenated hex
014 * strings H( HEX(A) | HEX(B) | HEX(S) ).
015 * <p>
016 * Specification RFC 2945
017 * 
018 * @author Simon Massey
019 */
020public class HexHashedClientEvidenceRoutine implements ClientEvidenceRoutine {
021
022        /**
023         * Computes a client evidence message 'M1'.
024         * 
025         * @param cryptoParams
026         *            The crypto parameters for the SRP-6a protocol.
027         * @param ctx
028         *            Snapshot of the SRP-6a client session variables which may be
029         *            used in the computation of the client evidence message.
030         * 
031         * @return Client evidence message 'M1' as 'H( HEX(A) | HEX(B) | HEX(S) )'.
032         */
033        @Override
034        public BigInteger computeClientEvidence(SRP6CryptoParams cryptoParams, SRP6ClientEvidenceContext ctx) {
035                return HexHashedRoutines.hashValues(cryptoParams.getMessageDigestInstance(), toHex(ctx.A), toHex(ctx.B), toHex(ctx.S));
036        }
037}