forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultECDiffieHellmanProvider.Unix.cs
57 lines (50 loc) · 1.72 KB
/
DefaultECDiffieHellmanProvider.Unix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.InteropServices;
namespace System.Security.Cryptography.EcDiffieHellman.Tests
{
public partial class ECDiffieHellmanProvider : IECDiffieHellmanProvider
{
public bool IsCurveValid(Oid oid)
{
if (PlatformDetection.IsApplePlatform)
{
return false;
}
if (!string.IsNullOrEmpty(oid.Value))
{
// Value is passed before FriendlyName
return IsValueOrFriendlyNameValid(oid.Value);
}
return IsValueOrFriendlyNameValid(oid.FriendlyName);
}
public bool ExplicitCurvesSupported
{
get
{
if (PlatformDetection.IsApplePlatform)
{
return false;
}
return true;
}
}
public bool CanDeriveNewPublicKey { get; } = !PlatformDetection.IsiOS && !PlatformDetection.IstvOS && !PlatformDetection.IsMacCatalyst;
public bool SupportsRawDerivation => true;
public bool SupportsSha3 => PlatformDetection.SupportsSha3;
private static bool IsValueOrFriendlyNameValid(string friendlyNameOrValue)
{
if (string.IsNullOrEmpty(friendlyNameOrValue))
{
return false;
}
IntPtr key = Interop.Crypto.EcKeyCreateByOid(friendlyNameOrValue);
if (key != IntPtr.Zero)
{
Interop.Crypto.EcKeyDestroy(key);
return true;
}
return false;
}
}
}