libcrypto_utils: switch to C++.
brillo is long gone, so no one should care about being C any more, and this will let future janitorial work take advantage of RAII. Test: treehugger Change-Id: I06acd01e8b30247bed6e971ab3e8660d3e599cce
This commit is contained in:
parent
cdfef7fe9e
commit
91784040db
2 changed files with 14 additions and 15 deletions
|
|
@ -23,7 +23,7 @@ cc_library {
|
||||||
},
|
},
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
srcs: [
|
srcs: [
|
||||||
"android_pubkey.c",
|
"android_pubkey.cpp",
|
||||||
],
|
],
|
||||||
cflags: [
|
cflags: [
|
||||||
"-Wall",
|
"-Wall",
|
||||||
|
|
|
||||||
|
|
@ -35,22 +35,22 @@
|
||||||
// little-endian 32 bit words. Note that Android only supports little-endian
|
// little-endian 32 bit words. Note that Android only supports little-endian
|
||||||
// processors, so we don't do any byte order conversions when parsing the binary
|
// processors, so we don't do any byte order conversions when parsing the binary
|
||||||
// struct.
|
// struct.
|
||||||
typedef struct RSAPublicKey {
|
struct RSAPublicKey {
|
||||||
// Modulus length. This must be ANDROID_PUBKEY_MODULUS_SIZE.
|
// Modulus length. This must be ANDROID_PUBKEY_MODULUS_SIZE.
|
||||||
uint32_t modulus_size_words;
|
uint32_t modulus_size_words;
|
||||||
|
|
||||||
// Precomputed montgomery parameter: -1 / n[0] mod 2^32
|
// Precomputed montgomery parameter: -1 / n[0] mod 2^32
|
||||||
uint32_t n0inv;
|
uint32_t n0inv;
|
||||||
|
|
||||||
// RSA modulus as a little-endian array.
|
// RSA modulus as a little-endian array.
|
||||||
uint8_t modulus[ANDROID_PUBKEY_MODULUS_SIZE];
|
uint8_t modulus[ANDROID_PUBKEY_MODULUS_SIZE];
|
||||||
|
|
||||||
// Montgomery parameter R^2 as a little-endian array.
|
// Montgomery parameter R^2 as a little-endian array.
|
||||||
uint8_t rr[ANDROID_PUBKEY_MODULUS_SIZE];
|
uint8_t rr[ANDROID_PUBKEY_MODULUS_SIZE];
|
||||||
|
|
||||||
// RSA modulus: 3 or 65537
|
// RSA modulus: 3 or 65537
|
||||||
uint32_t exponent;
|
uint32_t exponent;
|
||||||
} RSAPublicKey;
|
};
|
||||||
|
|
||||||
bool android_pubkey_decode(const uint8_t* key_buffer, size_t size, RSA** key) {
|
bool android_pubkey_decode(const uint8_t* key_buffer, size_t size, RSA** key) {
|
||||||
const RSAPublicKey* key_struct = (RSAPublicKey*)key_buffer;
|
const RSAPublicKey* key_struct = (RSAPublicKey*)key_buffer;
|
||||||
|
|
@ -116,8 +116,7 @@ bool android_pubkey_encode(const RSA* key, uint8_t* key_buffer, size_t size) {
|
||||||
BIGNUM* n0inv = BN_new();
|
BIGNUM* n0inv = BN_new();
|
||||||
BIGNUM* rr = BN_new();
|
BIGNUM* rr = BN_new();
|
||||||
|
|
||||||
if (sizeof(RSAPublicKey) > size ||
|
if (sizeof(RSAPublicKey) > size || RSA_size(key) != ANDROID_PUBKEY_MODULUS_SIZE) {
|
||||||
RSA_size(key) != ANDROID_PUBKEY_MODULUS_SIZE) {
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue