示例#1
0
        public static bool IsCurveSupported(EccCurve curve)
        {
#if __MonoCS__
            return(false);
#else
            return(RawEccKey.IsCurveSupported(curve));
#endif
        }
示例#2
0
        internal static bool IsCurveSupported(EccCurve curve)
        {
            int curveIndex = (int)curve;

            if (curveIndex < EcdsaCurveIDs.Length &&
                EcdsaCurveIDs[curveIndex] != null)
            {
                return(true);
            }
            return(false);
        }
示例#3
0
        internal static uint MagicFromTpmAlgId(TpmAlgId algId, bool isEcdh, EccCurve curve, bool publicKey)
        {
            uint res = AlgInfo.FirstOrDefault(x => (x.Public == publicKey &&
                                                    x.KeyLength == GetKeyLength(curve) &&
                                                    x.Ecdh == isEcdh)).Magic;

            if (res == 0)
            {
                Globs.Throw("Unrecognized ECC parameter set");
            }
            return(res);
        }
示例#4
0
        public bool CurveSupportsScheme(EccCurve curveId, TpmAlgId scheme)
        {
            if (!EccCurves.ContainsKey(curveId))
            {
                return(false);
            }

            var curveParams = EccCurves[curveId];

            return(curveParams.signScheme == TpmAlgId.Null ||
                   curveParams.signScheme == scheme);
        }
示例#5
0
        internal static int GetKeyLength(EccCurve curve)
        {
            switch (curve)
            {
            case EccCurve.TpmEccNistP256:
                return(256);

            case EccCurve.TpmEccNistP384:
                return(384);

            case EccCurve.TpmEccNistP521:
                return(521);
            }
            Globs.Throw <ArgumentException>("GetKeyLength(): Invalid ECC curve");
            return(-1);
        }
示例#6
0
 ///<param name = "the_symmetric">for a restricted decryption key, shall be set to a supported symmetric algorithm, key size. and mode. if the key is not a restricted decryption key, this field shall be set to TPM_ALG_NULL.</param>
 ///<param name = "the_scheme">If the sign attribute of the key is SET, then this shall be a valid signing scheme. NOTE	If the sign parameter in curveID indicates a mandatory scheme, then this field shall have the same value. If the decrypt attribute of the key is SET, then this shall be a valid key exchange scheme or TPM_ALG_NULL. If the key is a Storage Key, then this field shall be TPM_ALG_NULL.(One of KeySchemeEcdh, KeySchemeEcmqv, SigSchemeRsassa, SigSchemeRsapss, SigSchemeEcdsa, SigSchemeEcdaa, SigSchemeSm2, SigSchemeEcschnorr, EncSchemeRsaes, EncSchemeOaep, SchemeHash, NullAsymScheme)</param>
 ///<param name = "the_curveID">ECC curve ID</param>
 ///<param name = "the_kdf">an optional key derivation scheme for generating a symmetric key from a Z value If the kdf parameter associated with curveID is not TPM_ALG_NULL then this is required to be NULL. NOTE	There are currently no commands where this parameter has effect and, in the reference code, this field needs to be set to TPM_ALG_NULL.(One of SchemeMgf1, SchemeKdf1Sp80056a, SchemeKdf2, SchemeKdf1Sp800108, NullKdfScheme)</param>
 public EccParms(
 SymDefObject the_symmetric,
 IAsymSchemeUnion the_scheme,
 EccCurve the_curveID,
 IKdfSchemeUnion the_kdf
 )
 {
     this.symmetric = the_symmetric;
     this.scheme = the_scheme;
     this.curveID = the_curveID;
     this.kdf = the_kdf;
 }
示例#7
0
 public EccParms()
 {
     symmetric = new SymDefObject();
     curveID = new EccCurve();
 }
示例#8
0
 public Tpm2EccParametersRequest()
 {
     curveID = new EccCurve();
 }
示例#9
0
 public bool IsImplemented(EccCurve curve)
 {
     return(EccCurves.ContainsKey(curve));
 }
示例#10
0
 public EccPoint EcEphemeral(
     EccCurve curveID,
     [SuppressMessage("Microsoft.Design", "CA1021")]
     out ushort counter
 )
 {
     Tpm2EcEphemeralRequest inS = new Tpm2EcEphemeralRequest();
     inS.curveID = curveID;
     TpmStructureBase outSBase;
     DispatchMethod(TpmCc.EcEphemeral, (TpmStructureBase) inS, typeof(Tpm2EcEphemeralResponse), out outSBase, 0, 0);
     Tpm2EcEphemeralResponse outS = (Tpm2EcEphemeralResponse) outSBase;
     counter = outS.counter;
     return outS.Q;
 }
示例#11
0
 public AlgorithmDetailEcc EccParameters(
     EccCurve curveID
 )
 {
     Tpm2EccParametersRequest inS = new Tpm2EccParametersRequest();
     inS.curveID = curveID;
     TpmStructureBase outSBase;
     DispatchMethod(TpmCc.EccParameters, (TpmStructureBase) inS, typeof(Tpm2EccParametersResponse), out outSBase, 0, 0);
     Tpm2EccParametersResponse outS = (Tpm2EccParametersResponse) outSBase;
     return outS.parameters;
 }
示例#12
0
 ///<param name = "the_curveID">The curve for the computed ephemeral point</param>
 public Tpm2EcEphemeralRequest(
 EccCurve the_curveID
 )
 {
     this.curveID = the_curveID;
 }
示例#13
0
 public Tpm2EcEphemeralRequest(Tpm2EcEphemeralRequest the_Tpm2EcEphemeralRequest)
 {
     if((Object) the_Tpm2EcEphemeralRequest == null ) throw new ArgumentException(Globs.GetResourceString("parmError"));
     curveID = the_Tpm2EcEphemeralRequest.curveID;
 }
示例#14
0
 public Tpm2EcEphemeralRequest()
 {
     curveID = new EccCurve();
 }
示例#15
0
 ///<param name = "the_curveID">parameter set selector</param>
 public Tpm2EccParametersRequest(
 EccCurve the_curveID
 )
 {
     this.curveID = the_curveID;
 }
示例#16
0
        internal static byte[] GetKeyBlob(byte[] x, byte[] y, TpmAlgId alg, bool isEcdh, EccCurve curve)
        {
            var m = new Marshaller();

            byte[] magic = BitConverter.GetBytes(MagicFromTpmAlgId(alg, isEcdh, curve, true));
            m.Put(magic, "");
            int keyBits      = GetKeyLength(curve);
            int keySizeBytes = (keyBits + 7) / 8;

            if (x.Length != keySizeBytes || y.Length != keySizeBytes)
            {
                Globs.Throw <ArgumentException>("GetKeyBlob: Malformed ECC key");
                return(new byte[0]);
            }

            var size = Globs.ReverseByteOrder(Globs.HostToNet(keySizeBytes));

            m.Put(size, "len");
            m.Put(x, "x");
            m.Put(y, "y");
            var res = m.GetBytes();

            return(res);
        }
示例#17
0
 ///<param name = "the_eccCurves">array of ECC curve identifiers</param>
 public EccCurveArray(
 EccCurve[] the_eccCurves
 )
 {
     this.eccCurves = the_eccCurves;
 }
示例#18
0
 public static bool IsCurveSupported(EccCurve curve)
 {
     return(RawEccKey.IsCurveSupported(curve));
 }
示例#19
0
 public AlgorithmDetailEcc()
 {
     curveID = new EccCurve();
 }
示例#20
0
 ///<param name = "the_curveID">identifier for the curve</param>
 ///<param name = "the_keySize">Size in bits of the key</param>
 ///<param name = "the_kdf">the default KDF and hash algorithm used in secret sharing operations(One of SchemeMgf1, SchemeKdf1Sp80056a, SchemeKdf2, SchemeKdf1Sp800108, NullKdfScheme)</param>
 ///<param name = "the_sign">If not TPM_ALG_NULL, this is the mandatory signature scheme that is required to be used with this curve.(One of KeySchemeEcdh, KeySchemeEcmqv, SigSchemeRsassa, SigSchemeRsapss, SigSchemeEcdsa, SigSchemeEcdaa, SigSchemeSm2, SigSchemeEcschnorr, EncSchemeRsaes, EncSchemeOaep, SchemeHash, NullAsymScheme)</param>
 ///<param name = "the_p">Fp (the modulus)</param>
 ///<param name = "the_a">coefficient of the linear term in the curve equation</param>
 ///<param name = "the_b">constant term for curve equation</param>
 ///<param name = "the_gX">x coordinate of base point G</param>
 ///<param name = "the_gY">y coordinate of base point G</param>
 ///<param name = "the_n">order of G</param>
 ///<param name = "the_h">cofactor (a size of zero indicates a cofactor of 1)</param>
 public AlgorithmDetailEcc(
 EccCurve the_curveID,
 ushort the_keySize,
 IKdfSchemeUnion the_kdf,
 IAsymSchemeUnion the_sign,
 byte[] the_p,
 byte[] the_a,
 byte[] the_b,
 byte[] the_gX,
 byte[] the_gY,
 byte[] the_n,
 byte[] the_h
 )
 {
     this.curveID = the_curveID;
     this.keySize = the_keySize;
     this.kdf = the_kdf;
     this.sign = the_sign;
     this.p = the_p;
     this.a = the_a;
     this.b = the_b;
     this.gX = the_gX;
     this.gY = the_gY;
     this.n = the_n;
     this.h = the_h;
 }
示例#21
0
 public AlgorithmDetailEcc()
 {
     curveID = new EccCurve();
     keySize = 0;
     p = null;
     a = null;
     b = null;
     gX = null;
     gY = null;
     n = null;
     h = null;
 }