/**
         * Depending on the selected revocation algorithm, the proof data length will be different.
         * This method will give the proof length for any supported revocation algorithm.
         *
         * @param alg The revocation algorithm
         * @return The proof data length for the given revocation algorithm
         */
        public static int GetProofBytes(RevocationAlgorithm alg)
        {
            switch (alg)
            {
            case RevocationAlgorithm.ALG_NO_REVOCATION:
                return(0);

            default:
                throw new ArgumentException("Unsupported RevocationAlgorithm: " + alg.ToString());
            }
        }
示例#2
0
        /**
         * This method provides a non-revocation verifier depending on the Revocation algorithm
         *
         * @param algorithm Revocation mechanism to use
         * @return NonRevocationVerifier or null if not allowed
         */
        public static INonRevocationVerifier GetNonRevocationVerifier(RevocationAlgorithm algorithm)
        {
            switch (algorithm)
            {
            case RevocationAlgorithm.ALG_NO_REVOCATION:
                return(new NopNonRevocationVerifier());

            default:
                // Revocation algorithm not supported
                throw new Exception("Revocation algorithm " + algorithm.ToString() + " not supported");
            }
        }
        /**
         * Creates a Credential Revocation Information object
         *
         * @param key              Private key
         * @param unrevokedHandles Array of unrevoked revocation handles
         * @param epoch            The counter (representing a time window) in which this CRI is valid
         * @param alg              Revocation algorithm
         * @return CredentialRevocationInformation object
         */
        public static CredentialRevocationInformation CreateCRI(KeyPair key, BIG[] unrevokedHandles, int epoch, RevocationAlgorithm alg)
        {
            CredentialRevocationInformation cr = new CredentialRevocationInformation();

            cr.RevocationAlg = (int)alg;
            cr.Epoch         = epoch;

            // Create epoch key
            WeakBB.KeyPair keyPair = WeakBB.WeakBBKeyGen();
            if (alg == RevocationAlgorithm.ALG_NO_REVOCATION)
            {
                // Dummy PK in the proto
                cr.EpochPk = IdemixUtils.GenG2.ToProto();
            }
            else
            {
                // Real PK only if we are going to use it
                cr.EpochPk = keyPair.Pk.ToProto();
            }

            // Sign epoch + epoch key with the long term key
            byte[] signed;
            try
            {
                signed        = key.Sign(cr.ToByteArray(), "SHA256withECDSA");
                cr.EpochPkSig = ByteString.CopyFrom(signed);
            }
            catch (Exception e)
            {
                throw new CryptoException("Error processing the signature: ", e);
            }

            if (alg == RevocationAlgorithm.ALG_NO_REVOCATION)
            {
                // build and return the credential information object
                return(cr);
            }
            // If alg not supported, return null
            throw new ArgumentException("Algorithm " + alg.ToString() + " not supported");
        }