Exemplo n.º 1
0
 private static int RsaEncryptPkcs(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut) =>
 RsaEncryptPkcs(publicKey, ref MemoryMarshal.GetReference(pbData), cbData, out pEncryptedOut, out pErrorOut);
Exemplo n.º 2
0
 private static unsafe extern int AppleCryptoNative_SecKeyCreateWithData(
     byte *pKey,
     int cbKey,
     PAL_KeyAlgorithm keyAlgorithm,
     int isPublic,
     out SafeSecKeyRefHandle pDataKey,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 3
0
 private static extern int RsaDecryptOaep(
     SafeSecKeyRefHandle publicKey,
     ref byte pbData,
     int cbData,
     PAL_HashAlgorithm mgfAlgorithm,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 4
0
 internal static int GetErrorCode(SafeCFErrorHandle cfError)
 {
     unchecked
     {
         return((int)(CFErrorGetCode(cfError).ToInt64()));
     }
 }
Exemplo n.º 5
0
 private static int RsaDecryptPkcs(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut) =>
 RsaDecryptPkcs(publicKey, ref pbData.DangerousGetPinnableReference(), cbData, out pEncryptedOut, out pErrorOut);
Exemplo n.º 6
0
 private static extern int AppleCryptoNative_GenerateSignatureWithHashAlgorithm(
     SafeSecKeyRefHandle privateKey,
     ref byte pbDataHash,
     int cbDataHash,
     PAL_HashAlgorithm hashAlgorithm,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 7
0
 private static extern int AppleCryptoNative_VerifySignature(
     SafeSecKeyRefHandle publicKey,
     ref byte pbDataHash,
     int cbDataHash,
     ref byte pbSignature,
     int cbSignature,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 8
0
 private static partial int RsaDecryptOaep(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     PAL_HashAlgorithm mgfAlgorithm,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 9
0
 private static int AppleCryptoNative_GenerateSignature(
     SafeSecKeyRefHandle privateKey,
     ReadOnlySpan <byte> pbDataHash,
     int cbDataHash,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut) =>
 AppleCryptoNative_GenerateSignature(
     privateKey, ref MemoryMarshal.GetReference(pbDataHash), cbDataHash, out pSignatureOut, out pErrorOut);
Exemplo n.º 10
0
 private static int AppleCryptoNative_GenerateSignature(
     SafeSecKeyRefHandle privateKey,
     ReadOnlySpan <byte> pbDataHash,
     int cbDataHash,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut) =>
 AppleCryptoNative_GenerateSignature(
     privateKey, ref pbDataHash.DangerousGetPinnableReference(), cbDataHash, out pSignatureOut, out pErrorOut);
Exemplo n.º 11
0
 private static extern unsafe int AppleCryptoNative_VerifySignatureWithHashAlgorithm(
     SafeSecKeyRefHandle publicKey,
     byte *pbDataHash,
     int cbDataHash,
     byte *pbSignature,
     int cbSignature,
     PAL_HashAlgorithm hashAlgorithm,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 12
0
 private static int RsaDecryptOaep(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     PAL_HashAlgorithm mgfAlgorithm,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut) =>
 RsaDecryptOaep(publicKey, ref MemoryMarshal.GetReference(pbData), cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut);
Exemplo n.º 13
0
 private static int RsaDecryptOaep(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     PAL_HashAlgorithm mgfAlgorithm,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut) =>
 RsaDecryptOaep(publicKey, ref pbData.DangerousGetPinnableReference(), cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut);
Exemplo n.º 14
0
 private static unsafe extern int AppleCryptoNative_SecKeyCreateSignature(
     SafeSecKeyRefHandle privateKey,
     byte *pbDataHash,
     int cbDataHash,
     PAL_HashAlgorithm hashAlgorithm,
     PAL_SignatureAlgorithm signatureAlgorithm,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 15
0
 private static unsafe partial int AppleCryptoNative_SecKeyVerifySignature(
     SafeSecKeyRefHandle publicKey,
     byte *pbDataHash,
     int cbDataHash,
     byte *pbSignature,
     int cbSignature,
     PAL_HashAlgorithm hashAlgorithm,
     PAL_SignatureAlgorithm signatureAlgorithm,
     out SafeCFErrorHandle pErrorOut);
Exemplo n.º 16
0
        internal static Exception CreateExceptionForCFError(SafeCFErrorHandle cfError)
        {
            Debug.Assert(cfError != null);

            if (cfError.IsInvalid)
            {
                return(new CryptographicException());
            }

            return(new AppleCFErrorCryptographicException(cfError));
        }
Exemplo n.º 17
0
 private static unsafe int RsaDecryptPkcs(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut)
 {
     fixed(byte *pbDataPtr = &pbData.DangerousGetPinnableReference())
     {
         return(RsaDecryptPkcs(publicKey, pbDataPtr, cbData, out pEncryptedOut, out pErrorOut));
     }
 }
Exemplo n.º 18
0
 private static int AppleCryptoNative_VerifySignature(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbDataHash,
     ReadOnlySpan <byte> pbSignature,
     out SafeCFErrorHandle pErrorOut) =>
 AppleCryptoNative_VerifySignature(
     publicKey,
     ref MemoryMarshal.GetReference(pbDataHash),
     pbDataHash.Length,
     ref MemoryMarshal.GetReference(pbSignature),
     pbSignature.Length,
     out pErrorOut);
Exemplo n.º 19
0
 private static unsafe int RsaEncryptOaep(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbData,
     int cbData,
     PAL_HashAlgorithm mgfAlgorithm,
     out SafeCFDataHandle pEncryptedOut,
     out SafeCFErrorHandle pErrorOut)
 {
     fixed(byte *pbDataPtr = &pbData.DangerousGetPinnableReference())
     {
         return(RsaEncryptOaep(publicKey, pbDataPtr, cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut));
     }
 }
Exemplo n.º 20
0
 private static int AppleCryptoNative_GenerateSignatureWithHashAlgorithm(
     SafeSecKeyRefHandle privateKey,
     ReadOnlySpan <byte> pbDataHash,
     PAL_HashAlgorithm hashAlgorithm,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut) =>
 AppleCryptoNative_GenerateSignatureWithHashAlgorithm(
     privateKey,
     ref MemoryMarshal.GetReference(pbDataHash),
     pbDataHash.Length,
     hashAlgorithm,
     out pSignatureOut,
     out pErrorOut);
Exemplo n.º 21
0
 private static unsafe int AppleCryptoNative_GenerateSignature(
     SafeSecKeyRefHandle privateKey,
     ReadOnlySpan <byte> pbDataHash,
     int cbDataHash,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut)
 {
     fixed(byte *pbDataHashPtr = &pbDataHash.DangerousGetPinnableReference())
     {
         return(AppleCryptoNative_GenerateSignature(
                    privateKey, pbDataHashPtr, cbDataHash, out pSignatureOut, out pErrorOut));
     }
 }
Exemplo n.º 22
0
 private static unsafe int AppleCryptoNative_VerifySignature(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbDataHash,
     int cbDataHash,
     ReadOnlySpan <byte> pbSignature,
     int cbSignature,
     out SafeCFErrorHandle pErrorOut)
 {
     fixed(byte *pbDataHashPtr = &pbDataHash.DangerousGetPinnableReference())
     fixed(byte *pbSignaturePtr = &pbSignature.DangerousGetPinnableReference())
     {
         return(AppleCryptoNative_VerifySignature(publicKey, pbDataHashPtr, cbDataHash, pbSignaturePtr, cbSignature, out pErrorOut));
     }
 }
Exemplo n.º 23
0
 private static int AppleCryptoNative_VerifySignature(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbDataHash,
     int cbDataHash,
     ReadOnlySpan <byte> pbSignature,
     int cbSignature,
     out SafeCFErrorHandle pErrorOut) =>
 AppleCryptoNative_VerifySignature(
     publicKey,
     ref pbDataHash.DangerousGetPinnableReference(),
     cbDataHash,
     ref pbSignature.DangerousGetPinnableReference(),
     cbSignature,
     out pErrorOut);
Exemplo n.º 24
0
        internal static string?GetErrorDescription(SafeCFErrorHandle cfError)
        {
            Debug.Assert(cfError != null);

            if (cfError.IsInvalid)
            {
                return(null);
            }

            Debug.Assert(!cfError.IsClosed);

            using (SafeCFStringHandle cfString = CFErrorCopyDescription(cfError))
            {
                return(CFStringToString(cfString));
            }
        }
Exemplo n.º 25
0
 private static int AppleCryptoNative_VerifySignatureWithHashAlgorithm(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> pbDataHash,
     int cbDataHash,
     ReadOnlySpan <byte> pbSignature,
     int cbSignature,
     PAL_HashAlgorithm hashAlgorithm,
     out SafeCFErrorHandle pErrorOut) =>
 AppleCryptoNative_VerifySignatureWithHashAlgorithm(
     publicKey,
     ref MemoryMarshal.GetReference(pbDataHash),
     cbDataHash,
     ref MemoryMarshal.GetReference(pbSignature),
     cbSignature,
     hashAlgorithm,
     out pErrorOut);
Exemplo n.º 26
0
 private static unsafe int AppleCryptoNative_SecKeyCreateSignature(
     SafeSecKeyRefHandle privateKey,
     ReadOnlySpan <byte> dataHash,
     PAL_HashAlgorithm hashAlgorithm,
     PAL_SignatureAlgorithm signatureAlgorithm,
     out SafeCFDataHandle pSignatureOut,
     out SafeCFErrorHandle pErrorOut)
 {
     fixed(byte *pDataHash = dataHash)
     {
         return(AppleCryptoNative_SecKeyCreateSignature(
                    privateKey,
                    pDataHash,
                    dataHash.Length,
                    hashAlgorithm,
                    signatureAlgorithm,
                    out pSignatureOut,
                    out pErrorOut));
     }
 }
Exemplo n.º 27
0
        private static bool ProcessPrimitiveResponse(
            int returnValue,
            SafeCFDataHandle cfData,
            SafeCFErrorHandle cfError,
            Span <byte> destination,
            out int bytesWritten)
        {
            if (returnValue == kErrorSeeError)
            {
                throw CreateExceptionForCFError(cfError);
            }

            if (returnValue == kSuccess && !cfData.IsInvalid)
            {
                return(CoreFoundation.TryCFWriteData(cfData, destination, out bytesWritten));
            }

            Debug.Fail($"Unknown return value ({returnValue}) or no data object returned");
            throw new CryptographicException();
        }
Exemplo n.º 28
0
 private static unsafe int AppleCryptoNative_SecKeyVerifySignature(
     SafeSecKeyRefHandle publicKey,
     ReadOnlySpan <byte> dataHash,
     ReadOnlySpan <byte> signature,
     PAL_HashAlgorithm hashAlgorithm,
     PAL_SignatureAlgorithm signatureAlgorithm,
     out SafeCFErrorHandle pErrorOut)
 {
     fixed(byte *pDataHash = dataHash)
     fixed(byte *pSignature = signature)
     {
         return(AppleCryptoNative_SecKeyVerifySignature(
                    publicKey,
                    pDataHash,
                    dataHash.Length,
                    pSignature,
                    signature.Length,
                    hashAlgorithm,
                    signatureAlgorithm,
                    out pErrorOut));
     }
 }
Exemplo n.º 29
0
 internal AppleCFErrorCryptographicException(SafeCFErrorHandle cfError)
     : base(Interop.CoreFoundation.GetErrorDescription(cfError))
 {
     HResult = Interop.CoreFoundation.GetErrorCode(cfError);
 }
Exemplo n.º 30
0
 private static partial SafeCFStringHandle CFErrorCopyDescription(SafeCFErrorHandle cfError);