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