Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add ECDsa span-based methods #23252

Merged
merged 1 commit into from
Aug 15, 2017
Merged

Conversation

stephentoub
Copy link
Member

@@ -51,6 +51,14 @@ public override byte[] SignHash(byte[] hash)
}
}

public override unsafe bool TrySignHash(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What here (and at VerifyHash) requires the unsafe keyword?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null argument to TrySignHash is a void*.

@stephentoub
Copy link
Member Author

Thanks for reviewing, @bartonjs.

@stephentoub stephentoub merged commit 1d7b43d into dotnet:master Aug 15, 2017
@stephentoub stephentoub deleted the ecdsaspan branch August 15, 2017 17:07
@ektrah
Copy link
Member

ektrah commented Aug 15, 2017

@stephentoub - Quick question: The code currently pins spans for P/Invoke, e.g.:

private static unsafe int RsaEncryptPkcs(
    SafeSecKeyRefHandle publicKey,
    ReadOnlySpan<byte> pbData,
    int cbData,
    out SafeCFDataHandle pEncryptedOut,
    out SafeCFErrorHandle pErrorOut)
{
    fixed (byte* pbDataPtr = &pbData.DangerousGetPinnableReference())
    {
        return RsaEncryptPkcs(publicKey, pbDataPtr, cbData, out pEncryptedOut, out pErrorOut);
    }
}

Is that required or could the P/Invoke method defined to accept a ref byte? E.g.:

private static int RsaEncryptPkcs(
    SafeSecKeyRefHandle publicKey,
    ReadOnlySpan<byte> pbData,
    out SafeCFDataHandle pEncryptedOut,
    out SafeCFErrorHandle pErrorOut)
{
    return RsaEncryptPkcs(publicKey, ref pbData.DangerousGetPinnableReference(), pbData.Length, out pEncryptedOut, out pErrorOut);
}

[DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_RsaEncryptPkcs")]
private static extern int RsaEncryptPkcs(
    SafeSecKeyRefHandle publicKey,
    ref byte pbData,
    int cbData,
    out SafeCFDataHandle pEncryptedOut,
    out SafeCFErrorHandle pErrorOut);

I'm wondering because manual pinning is usually not required when passing, for example, a field by reference:

class A { public int B; }

[DllImport(...)]
static extern void Foo(ref int value);

static void Main()
{
    var a = new A();
    Foo(ref a.B);
}

@stephentoub
Copy link
Member Author

stephentoub commented Aug 15, 2017

Is that required or could the P/Invoke method defined to accept a ref byte?

That's a good question. I actually hadn't considered doing that, but I don't see why it wouldn't work. I'll try and submit a PR to clean it up assuming it works.

@karelz karelz modified the milestone: 2.1.0 Aug 20, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants