forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dotnet/corefx#3812 from eerhardt/ShimBio2
Shim Interop.Bignum and Interop.BIO methods. Commit migrated from dotnet/corefx@aa215e4
- Loading branch information
Showing
26 changed files
with
277 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.BIO.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using Microsoft.Win32.SafeHandles; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Crypto | ||
{ | ||
[DllImport(Libraries.CryptoNative)] | ||
internal static extern SafeBioHandle CreateMemoryBio(); | ||
|
||
[DllImport(Libraries.CryptoNative)] | ||
internal static extern SafeBioHandle BioNewFile(string filename, string mode); | ||
|
||
[DllImport(Libraries.CryptoNative)] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
internal static extern bool BioDestroy(IntPtr a); | ||
|
||
[DllImport(Libraries.CryptoNative, CharSet = CharSet.Ansi)] | ||
internal static extern int BioGets(SafeBioHandle b, [Out] StringBuilder buf, int size); | ||
|
||
[DllImport(Libraries.CryptoNative)] | ||
internal static extern int BioRead(SafeBioHandle b, byte[] data, int len); | ||
|
||
[DllImport(Libraries.CryptoNative)] | ||
internal static extern int BioWrite(SafeBioHandle b, byte[] data, int len); | ||
|
||
[DllImport(Libraries.CryptoNative)] | ||
internal static extern int GetMemoryBioSize(SafeBioHandle bio); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
src/libraries/Common/src/Interop/Unix/libcrypto/Interop.BIO.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/libraries/Native/System.Security.Cryptography.Native/pal_bignum.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include "pal_bignum.h" | ||
|
||
extern "C" void BigNumDestroy(BIGNUM* a) | ||
{ | ||
if (a != nullptr) | ||
{ | ||
BN_clear_free(a); | ||
} | ||
} | ||
|
||
extern "C" BIGNUM* BigNumFromBinary(const unsigned char* s, int32_t len) | ||
{ | ||
if (!s || !len) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
return BN_bin2bn(s, len, nullptr); | ||
} | ||
|
||
extern "C" int32_t BigNumToBinary(const BIGNUM* a, unsigned char* to) | ||
{ | ||
if (!a || !to) | ||
{ | ||
return 0; | ||
} | ||
|
||
return BN_bn2bin(a, to); | ||
} | ||
|
||
extern "C" int32_t GetBigNumBytes(const BIGNUM* a) | ||
{ | ||
if (!a) | ||
{ | ||
return 0; | ||
} | ||
|
||
return BN_num_bytes(a); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/libraries/Native/System.Security.Cryptography.Native/pal_bignum.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include "pal_types.h" | ||
|
||
#include <openssl/bn.h> | ||
|
||
/* | ||
Cleans up and deletes an BIGNUM instance. | ||
Implemented by: | ||
1) Calling BN_clear_free | ||
No-op if a is null. | ||
The given BIGNUM pointer is invalid after this call. | ||
Always succeeds. | ||
*/ | ||
extern "C" void BigNumDestroy(BIGNUM* a); | ||
|
||
/* | ||
Shims the BN_bin2bn method. | ||
*/ | ||
extern "C" BIGNUM* BigNumFromBinary(const unsigned char* s, int32_t len); | ||
|
||
/* | ||
Shims the BN_bn2bin method. | ||
*/ | ||
extern "C" int32_t BigNumToBinary(const BIGNUM* a, unsigned char* to); | ||
|
||
/* | ||
Returns the number of bytes needed to export a BIGNUM. | ||
*/ | ||
extern "C" int32_t GetBigNumBytes(const BIGNUM* a); |
46 changes: 46 additions & 0 deletions
46
src/libraries/Native/System.Security.Cryptography.Native/pal_bio.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include "pal_bio.h" | ||
|
||
#include <assert.h> | ||
|
||
extern "C" BIO* CreateMemoryBio() | ||
{ | ||
return BIO_new(BIO_s_mem()); | ||
} | ||
|
||
extern "C" BIO* BioNewFile(const char* filename, const char* mode) | ||
{ | ||
return BIO_new_file(filename, mode); | ||
} | ||
|
||
extern "C" int32_t BioDestroy(BIO* a) | ||
{ | ||
return BIO_free(a); | ||
} | ||
|
||
extern "C" int32_t BioGets(BIO* b, char* buf, int32_t size) | ||
{ | ||
return BIO_gets(b, buf, size); | ||
} | ||
|
||
extern "C" int32_t BioRead(BIO* b, void* buf, int32_t len) | ||
{ | ||
return BIO_read(b, buf, len); | ||
} | ||
|
||
extern "C" int32_t BioWrite(BIO* b, const void* buf, int32_t len) | ||
{ | ||
return BIO_write(b, buf, len); | ||
} | ||
|
||
extern "C" int32_t GetMemoryBioSize(BIO* bio) | ||
{ | ||
long ret = BIO_get_mem_data(bio, nullptr); | ||
|
||
// BIO_get_mem_data returns the memory size, which will always be | ||
// an int32. | ||
assert(ret <= INT32_MAX); | ||
return static_cast<int32_t>(ret); | ||
} |
Oops, something went wrong.