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.SRP6CryptoParams;
009import com.nimbusds.srp6.SRP6ServerEvidenceContext;
010import com.nimbusds.srp6.ServerEvidenceRoutine;
011
012/**
013 * Custom routine interface for computing the server evidence message 'M1'.
014 * Compatible with browser implementations by using hashing of string
015 * concatenated hex strings 'H( HEX(A) | HEX(M1) | HEX(S)'.
016 * 
017 * <p>
018 * Specification RFC 2945
019 * 
020 * @author Simon Massey
021 */
022public class HexHashedServerEvidenceRoutine implements ServerEvidenceRoutine, Serializable {
023
024        /**
025         * Serializable class version number
026         */
027        private static final long serialVersionUID = 3243998651178428263L;
028
029        /**
030         * Computes a server evidence message 'M2'.
031         * 
032         * @param cryptoParams
033         *            The crypto parameters for the SRP-6a protocol.
034         * @param ctx
035         *            Snapshot of the SRP-6a server session variables which may be
036         *            used in the computation of the server evidence message.
037         * 
038         * @return Server evidence message 'M2' as 'H( HEX(A) | HEX(M1) | HEX(S)'
039         */
040        @Override
041        public BigInteger computeServerEvidence(SRP6CryptoParams cryptoParams, SRP6ServerEvidenceContext ctx) {
042                return HexHashedRoutines.hashValues(cryptoParams.getMessageDigestInstance(), toHex(ctx.A), toHex(ctx.M1), toHex(ctx.S));
043        }
044
045}