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