Exemple #1
0
        private static CngKey ImportKeyBlob(
            byte[] blob,
            string curveName,
            CngKeyBlobFormat format,
            ECCurve.ECCurveType curveType)
        {
            try
            {
                CngKey newKey = CngKey.Import(blob, curveName, format);
                newKey.ExportPolicy |= CngExportPolicies.AllowPlaintextExport;

                return(newKey);
            }
            catch (CryptographicException e)
            {
                if (curveType != ECCurve.ECCurveType.Named &&
                    e.HResult == (int)ErrorCode.NTE_NOT_SUPPORTED)
                {
                    throw new PlatformNotSupportedException(
                              SR.GetString(SR.Cryptography_CurveNotSupported, curveType),
                              e);
                }

                throw;
            }
        }
Exemple #2
0
 /// <summary>
 /// Helper method to map between BCrypt.ECC_CURVE_TYPE_ENUM and ECCurve.ECCurveType
 /// </summary>
 private static Interop.BCrypt.ECC_CURVE_TYPE_ENUM ConvertToCurveTypeEnum(ECCurve.ECCurveType value)
 {
     // Currently values 1-3 are interchangeable
     Debug.Assert(value == ECCurve.ECCurveType.Characteristic2 ||
                  value == ECCurve.ECCurveType.PrimeShortWeierstrass ||
                  value == ECCurve.ECCurveType.PrimeTwistedEdwards);
     return((Interop.BCrypt.ECC_CURVE_TYPE_ENUM)value);
 }
Exemple #3
0
 /// <summary>
 /// Helper method to map between BCrypt.ECC_CURVE_TYPE_ENUM and ECCurve.ECCurveType
 /// </summary>
 internal static ECCurve.ECCurveType ConvertToCurveTypeEnum(Interop.BCrypt.ECC_CURVE_TYPE_ENUM value)
 {
     // Currently values 1-3 are interchangeable
     ECCurve.ECCurveType curveType = (ECCurve.ECCurveType)value;
     Debug.Assert(curveType == ECCurve.ECCurveType.Characteristic2 ||
                  curveType == ECCurve.ECCurveType.PrimeShortWeierstrass ||
                  curveType == ECCurve.ECCurveType.PrimeTwistedEdwards);
     return(curveType);
 }
Exemple #4
0
 internal static partial SafeEcKeyHandle EcKeyCreateByExplicitParameters(
     ECCurve.ECCurveType curveType,
     byte[]?qx, int qxLength,
     byte[]?qy, int qyLength,
     byte[]?d, int dLength,
     byte[] p, int pLength,
     byte[] a, int aLength,
     byte[] b, int bLength,
     byte[] gx, int gxLength,
     byte[] gy, int gyLength,
     byte[] order, int nLength,
     byte[]?cofactor, int cofactorLength,
     byte[]?seed, int seedLength);
Exemple #5
0
 private static partial int CryptoNative_GetECCurveParameters(
     SafeEcKeyHandle key,
     [MarshalAs(UnmanagedType.Bool)] bool includePrivate,
     out ECCurve.ECCurveType curveType,
     out SafeBignumHandle qx, out int x_cb,
     out SafeBignumHandle qy, out int y_cb,
     out IntPtr d_bn_not_owned, out int d_cb,
     out SafeBignumHandle p, out int P_cb,
     out SafeBignumHandle a, out int A_cb,
     out SafeBignumHandle b, out int B_cb,
     out SafeBignumHandle gx, out int Gx_cb,
     out SafeBignumHandle gy, out int Gy_cb,
     out SafeBignumHandle order, out int order_cb,
     out SafeBignumHandle cofactor, out int cofactor_cb,
     out SafeBignumHandle seed, out int seed_cb);
 private static extern int AndroidCryptoNative_GetECCurveParameters(
     SafeEcKeyHandle key,
     bool includePrivate,
     out ECCurve.ECCurveType curveType,
     out SafeBignumHandle qx, out int x_cb,
     out SafeBignumHandle qy, out int y_cb,
     out IntPtr d_bn_not_owned, out int d_cb,
     out SafeBignumHandle p, out int P_cb,
     out SafeBignumHandle a, out int A_cb,
     out SafeBignumHandle b, out int B_cb,
     out SafeBignumHandle gx, out int Gx_cb,
     out SafeBignumHandle gy, out int Gy_cb,
     out SafeBignumHandle order, out int order_cb,
     out SafeBignumHandle cofactor, out int cofactor_cb,
     out SafeBignumHandle seed, out int seed_cb);
Exemple #7
0
        public bool IsCurveTypeEqual(ECCurve.ECCurveType actual)
        {
            if (CurveType == actual)
            {
                return(true);
            }

            // Montgomery and Weierstrass are interchangable depending on the platform
            if (CurveType == ECCurve.ECCurveType.PrimeMontgomery && actual == ECCurve.ECCurveType.PrimeShortWeierstrass ||
                CurveType == ECCurve.ECCurveType.PrimeShortWeierstrass && actual == ECCurve.ECCurveType.PrimeMontgomery)
            {
                return(true);
            }

            return(false);
        }