Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,56 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Swift;
using System.Security.Cryptography.Apple;

#pragma warning disable CS3016 // Arrays as attribute arguments are not CLS Compliant

internal static partial class Interop
{
internal static partial class AppleCrypto
{
[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestFree")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
internal static partial void DigestFree(IntPtr handle);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestCreate")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
internal static partial SafeDigestCtxHandle DigestCreate(PAL_HashAlgorithm algorithm, out int cbDigest);

internal static int DigestUpdate(SafeDigestCtxHandle ctx, ReadOnlySpan<byte> data) =>
DigestUpdate(ctx, ref MemoryMarshal.GetReference(data), data.Length);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestUpdate")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
private static partial int DigestUpdate(SafeDigestCtxHandle ctx, ref byte pbData, int cbData);

internal static int DigestFinal(SafeDigestCtxHandle ctx, Span<byte> output) =>
DigestFinal(ctx, ref MemoryMarshal.GetReference(output), output.Length);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestFinal")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
private static partial int DigestFinal(SafeDigestCtxHandle ctx, ref byte pbOutput, int cbOutput);

internal static int DigestCurrent(SafeDigestCtxHandle ctx, Span<byte> output) =>
DigestCurrent(ctx, ref MemoryMarshal.GetReference(output), output.Length);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestCurrent")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
private static partial int DigestCurrent(SafeDigestCtxHandle ctx, ref byte pbOutput, int cbOutput);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestOneShot")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
internal static unsafe partial int DigestOneShot(PAL_HashAlgorithm algorithm, byte* pbData, int cbData, byte* pbOutput, int cbOutput, int* cbDigest);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestReset")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
internal static partial int DigestReset(SafeDigestCtxHandle ctx);

[LibraryImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestClone")]
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
internal static partial SafeDigestCtxHandle DigestClone(SafeDigestCtxHandle ctx);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set(NATIVE_LIBS_EXTRA)
append_extra_cryptography_apple_libs(NATIVE_LIBS_EXTRA)

set(NATIVECRYPTO_SOURCES
pal_digest.c
pal_ecc.c
pal_hmac.c
pal_keyagree.c
Expand Down
252 changes: 0 additions & 252 deletions src/native/libs/System.Security.Cryptography.Native.Apple/pal_digest.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,3 @@ enum
typedef uint32_t PAL_HashAlgorithm;

typedef struct digest_ctx_st DigestCtx;

/*
Free the resources held by a DigestCtx
*/
PALEXPORT void AppleCryptoNative_DigestFree(DigestCtx* pDigest);

/*
Create a digest handle for the specified algorithm.

Returns NULL when the algorithm is unknown, or pcbDigest is NULL; otherwise returns a pointer
to a digest context suitable for calling DigestUpdate and DigestFinal on and sets pcbDigest to
the size of the digest output.
*/
PALEXPORT DigestCtx* AppleCryptoNative_DigestCreate(PAL_HashAlgorithm algorithm, int32_t* pcbDigest);

/*
Apply cbBuf bytes of data from pBuf to the ongoing digest represented in ctx.

Returns 1 on success, 0 on failure, any other value on invalid inputs/state.
*/
PALEXPORT int32_t AppleCryptoNative_DigestUpdate(DigestCtx* ctx, uint8_t* pBuf, int32_t cbBuf);

/*
Complete the digest in ctx, copying the results to pOutput, and reset ctx for a new digest.

Returns 1 on success, 0 on failure, any other value on invalid inputs/state.
*/
PALEXPORT int32_t AppleCryptoNative_DigestFinal(DigestCtx* ctx, uint8_t* pOutput, int32_t cbOutput);

/*
Get the digest of the data already loaded into ctx, without resetting ctx.

Returns 1 on success, 0 on failure, any other value on invalid inputs/state.
*/
PALEXPORT int32_t AppleCryptoNative_DigestCurrent(const DigestCtx* ctx, uint8_t* pOutput, int32_t cbOutput);

/*
Combines DigestCreate, DigestUpdate, and DigestFinal in to a single operation.

Returns 1 on success, 0 on failure, any other value on invalid inputs/state.
*/
PALEXPORT int32_t AppleCryptoNative_DigestOneShot(PAL_HashAlgorithm algorithm, uint8_t* pBuf, int32_t cbBuf, uint8_t* pOutput, int32_t cbOutput, int32_t* pcbDigest);


/*
Re-initializes a digest context to an initial state.

Returns 1 on success, 0 on failure, any other value on invalid inputs/state.
*/
PALEXPORT int32_t AppleCryptoNative_DigestReset(DigestCtx* ctx);

/*
Clones the current digest context.

Returns a handle to the new digest context, or NULL if the clone failed.
*/
PALEXPORT DigestCtx* AppleCryptoNative_DigestClone(const DigestCtx* ctx);
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ EXTERN_C void* AppleCryptoNative_IsAuthenticationFailure;
EXTERN_C void* AppleCryptoNative_HKDFDeriveKey;
EXTERN_C void* AppleCryptoNative_HKDFExpand;
EXTERN_C void* AppleCryptoNative_HKDFExtract;

EXTERN_C void* AppleCryptoNative_DigestFree;
EXTERN_C void* AppleCryptoNative_DigestCreate;
EXTERN_C void* AppleCryptoNative_DigestUpdate;
EXTERN_C void* AppleCryptoNative_DigestFinal;
EXTERN_C void* AppleCryptoNative_DigestCurrent;
EXTERN_C void* AppleCryptoNative_DigestOneShot;
EXTERN_C void* AppleCryptoNative_DigestReset;
EXTERN_C void* AppleCryptoNative_DigestClone;
Loading
Loading