mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9680b7251c | ||
|
|
3c632a678e | ||
|
|
7ba861aa8a | ||
|
|
afe4c9b5f6 | ||
|
|
d82f7d8ce8 | ||
|
|
6445f9fb06 | ||
|
|
f8b6e4e17e | ||
|
|
68d56d2b3c | ||
|
|
794901c991 | ||
|
|
82503a48ce |
No files matched your search
@@ -33,7 +33,7 @@ _[the Swift Crypto tag/commit hash]_
|
||||
|
||||
### Environment
|
||||
|
||||
Stand in the root of the repo and run `./scripts/environments.sh` and paste the output below
|
||||
Stand in the root of the repo and run `./scripts/environment.sh` and paste the output below
|
||||
|
||||
<details>
|
||||
<pre>PLEASE_REPLACE_THIS_STIRNG_WITH_OUTPUT_OF_script_environments_THAT_IS_IN_YOUR_PASTEBOARD</pre>
|
||||
|
||||
@@ -26,7 +26,7 @@ _[the Swift Crypto tag/commit hash]_
|
||||
|
||||
### Environment
|
||||
|
||||
Stand in the root of the repo and run `./scripts/environments.sh` and paste the output below
|
||||
Stand in the root of the repo and run `./scripts/environment.sh` and paste the output below
|
||||
|
||||
<details>
|
||||
<pre>PLEASE_REPLACE_THIS_STIRNG_WITH_OUTPUT_OF_script_environments_THAT_IS_IN_YOUR_PASTEBOARD</pre>
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 53a17f55247101105ae35767d5c5a6c311843a8e
|
||||
// BoringSSL Commit: 67818bea6690a230e2f42e8a588e0f54949bbbf1
|
||||
|
||||
import PackageDescription
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ If you have issues with CryptoKit, instead of Swift Crypto, please use [Feedback
|
||||
|
||||
#### `gyb`
|
||||
|
||||
Some of the files in this project are autogenerated (metaprogramming) using the Swift Utils tools called [gyb](https://github.com/apple/swift/blob/master/utils/gyb.py) (_"generate your boilerplate"_). `gyb` is included in [`./scripts/gyb`](scripts/gyb).
|
||||
Some of the files in this project are autogenerated (metaprogramming) using the Swift Utils tools called [gyb](https://github.com/apple/swift/blob/main/utils/gyb.py) (_"generate your boilerplate"_). `gyb` is included in [`./scripts/gyb`](scripts/gyb).
|
||||
|
||||
`gyb` will generate some `Foobar.swift` Swift file from some `Foobar.swift.gyb` _template_ file. **You should not edit `Foobar.swift` directly**, since all manual edits in that generated file will be overwritten the next time `gyb` is run.
|
||||
|
||||
@@ -108,5 +108,5 @@ SemVer and Swift Crypto's Public API guarantees should result in a working progr
|
||||
|
||||
### Developing Swift Crypto on macOS
|
||||
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force Swift Crypto to build its public API.
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force Swift Crypto to build its public API.
|
||||
|
||||
@@ -70,7 +70,7 @@ int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
|
||||
return M_ASN1_BIT_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
|
||||
int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp)
|
||||
{
|
||||
int ret, j, bits, len;
|
||||
unsigned char *p, *d;
|
||||
@@ -233,7 +233,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
|
||||
int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
|
||||
{
|
||||
int w, v;
|
||||
|
||||
@@ -250,7 +250,7 @@ int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
|
||||
* which is not specified in 'flags', 1 otherwise.
|
||||
* 'len' is the length of 'flags'.
|
||||
*/
|
||||
int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a,
|
||||
int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a,
|
||||
unsigned char *flags, int flags_len)
|
||||
{
|
||||
int i, ok;
|
||||
|
||||
@@ -108,7 +108,7 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
|
||||
return (1);
|
||||
}
|
||||
|
||||
long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
|
||||
long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
|
||||
{
|
||||
int neg = 0, i;
|
||||
|
||||
@@ -147,7 +147,7 @@ long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
|
||||
return r;
|
||||
}
|
||||
|
||||
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
|
||||
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
|
||||
{
|
||||
ASN1_ENUMERATED *ret;
|
||||
int len, j;
|
||||
@@ -183,7 +183,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
|
||||
BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
|
||||
{
|
||||
BIGNUM *ret;
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
|
||||
* followed by optional zeros isn't padded.
|
||||
*/
|
||||
|
||||
int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
|
||||
int i2c_ASN1_INTEGER(const ASN1_INTEGER *a, unsigned char **pp)
|
||||
{
|
||||
int pad = 0, ret, i, neg;
|
||||
unsigned char *p, *n, pb = 0;
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
|
||||
int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
|
||||
{
|
||||
unsigned char *p, *allocated = NULL;
|
||||
int objsize;
|
||||
@@ -98,12 +98,12 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
|
||||
return objsize;
|
||||
}
|
||||
|
||||
int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
|
||||
int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a)
|
||||
{
|
||||
return OBJ_obj2txt(buf, buf_len, a, 0);
|
||||
}
|
||||
|
||||
int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
|
||||
int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
|
||||
{
|
||||
char buf[80], *p = buf;
|
||||
int i;
|
||||
|
||||
@@ -100,7 +100,7 @@ ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
|
||||
return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec);
|
||||
}
|
||||
|
||||
int ASN1_TIME_check(ASN1_TIME *t)
|
||||
int ASN1_TIME_check(const ASN1_TIME *t)
|
||||
{
|
||||
if (t->type == V_ASN1_GENERALIZEDTIME)
|
||||
return ASN1_GENERALIZEDTIME_check(t);
|
||||
@@ -110,7 +110,7 @@ int ASN1_TIME_check(ASN1_TIME *t)
|
||||
}
|
||||
|
||||
/* Convert an ASN1_TIME structure to GeneralizedTime */
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
|
||||
ASN1_GENERALIZEDTIME **out)
|
||||
{
|
||||
ASN1_GENERALIZEDTIME *ret = NULL;
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
|
||||
int ASN1_TYPE_get(ASN1_TYPE *a)
|
||||
int ASN1_TYPE_get(const ASN1_TYPE *a)
|
||||
{
|
||||
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
|
||||
return (a->type);
|
||||
|
||||
@@ -424,13 +424,7 @@ int ASN1_STRING_length(const ASN1_STRING *x)
|
||||
return M_ASN1_STRING_length(x);
|
||||
}
|
||||
|
||||
void ASN1_STRING_length_set(ASN1_STRING *x, int len)
|
||||
{
|
||||
M_ASN1_STRING_length_set(x, len);
|
||||
return;
|
||||
}
|
||||
|
||||
int ASN1_STRING_type(ASN1_STRING *x)
|
||||
int ASN1_STRING_type(const ASN1_STRING *x)
|
||||
{
|
||||
return M_ASN1_STRING_type(x);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
|
||||
|
||||
/* Extract an ASN1 object from an ASN1_STRING */
|
||||
|
||||
void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
|
||||
void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
|
||||
{
|
||||
const unsigned char *p;
|
||||
void *ret;
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
/* Based on a_int.c: equivalent ENUMERATED functions */
|
||||
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
|
||||
int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
|
||||
int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
|
||||
@@ -35,6 +35,7 @@ Lone:
|
||||
|
||||
.align 5
|
||||
_ChaCha20_ctr32:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
cbz x2,Labort
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x5,:pg_hi21_nc:_OPENSSL_armcap_P
|
||||
@@ -48,6 +49,7 @@ _ChaCha20_ctr32:
|
||||
b.ne ChaCha20_neon
|
||||
|
||||
Lshort:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -260,6 +262,7 @@ Loop:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
Labort:
|
||||
ret
|
||||
|
||||
@@ -316,12 +319,14 @@ Loop_tail:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
|
||||
.align 5
|
||||
ChaCha20_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -702,6 +707,7 @@ Loop_neon:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
Ltail_neon:
|
||||
@@ -811,11 +817,13 @@ Ldone_neon:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
.align 5
|
||||
ChaCha20_512_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -1979,6 +1987,7 @@ Ldone_512_neon:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
.type ChaCha20_ctr32,%function
|
||||
.align 5
|
||||
ChaCha20_ctr32:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
cbz x2,.Labort
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x5,:pg_hi21_nc:OPENSSL_armcap_P
|
||||
@@ -49,6 +50,7 @@ ChaCha20_ctr32:
|
||||
b.ne ChaCha20_neon
|
||||
|
||||
.Lshort:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -261,6 +263,7 @@ ChaCha20_ctr32:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
.Labort:
|
||||
ret
|
||||
|
||||
@@ -317,12 +320,14 @@ ChaCha20_ctr32:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
|
||||
.type ChaCha20_neon,%function
|
||||
.align 5
|
||||
ChaCha20_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -703,6 +708,7 @@ ChaCha20_neon:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
.Ltail_neon:
|
||||
@@ -812,11 +818,13 @@ ChaCha20_neon:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_neon,.-ChaCha20_neon
|
||||
.type ChaCha20_512_neon,%function
|
||||
.align 5
|
||||
ChaCha20_512_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -1980,6 +1988,7 @@ ChaCha20_512_neon:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_512_neon,.-ChaCha20_512_neon
|
||||
#endif
|
||||
|
||||
@@ -133,6 +133,7 @@ void EVP_tls_cbc_copy_mac(uint8_t *out, size_t md_size, const uint8_t *in,
|
||||
assert(orig_len >= in_len);
|
||||
assert(in_len >= md_size);
|
||||
assert(md_size <= EVP_MAX_MD_SIZE);
|
||||
assert(md_size > 0);
|
||||
|
||||
// scan_start contains the number of bytes that we can ignore because
|
||||
// the MAC's position can only vary by 255 bytes.
|
||||
|
||||
@@ -72,12 +72,11 @@
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
#define OPENSSL_DSA_MAX_MODULUS_BITS 10000
|
||||
|
||||
// Primality test according to FIPS PUB 186[-1], Appendix 2.1: 50 rounds of
|
||||
// Miller-Rabin.
|
||||
#define DSS_prime_checks 50
|
||||
@@ -568,23 +567,7 @@ static int mod_mul_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
}
|
||||
|
||||
DSA_SIG *DSA_do_sign(const uint8_t *digest, size_t digest_len, const DSA *dsa) {
|
||||
if (!dsa->p || !dsa->q || !dsa->g) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_MISSING_PARAMETERS);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Reject invalid parameters. In particular, the algorithm will infinite loop
|
||||
// if |g| is zero.
|
||||
if (BN_is_zero(dsa->p) || BN_is_zero(dsa->q) || BN_is_zero(dsa->g)) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We only support DSA keys that are a multiple of 8 bits. (This is a weaker
|
||||
// check than the one in |DSA_do_check_signature|, which only allows 160-,
|
||||
// 224-, and 256-bit keys.
|
||||
if (BN_num_bits(dsa->q) % 8 != 0) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_Q_VALUE);
|
||||
if (!dsa_check_parameters(dsa)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -678,35 +661,17 @@ int DSA_do_verify(const uint8_t *digest, size_t digest_len, DSA_SIG *sig,
|
||||
|
||||
int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
|
||||
size_t digest_len, DSA_SIG *sig, const DSA *dsa) {
|
||||
BN_CTX *ctx;
|
||||
BIGNUM u1, u2, t1;
|
||||
int ret = 0;
|
||||
unsigned i;
|
||||
|
||||
*out_valid = 0;
|
||||
|
||||
if (!dsa->p || !dsa->q || !dsa->g) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_MISSING_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = BN_num_bits(dsa->q);
|
||||
// FIPS 186-3 allows only different sizes for q.
|
||||
if (i != 160 && i != 224 && i != 256) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_Q_VALUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_MODULUS_TOO_LARGE);
|
||||
if (!dsa_check_parameters(dsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
BIGNUM u1, u2, t1;
|
||||
BN_init(&u1);
|
||||
BN_init(&u2);
|
||||
BN_init(&t1);
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -729,11 +694,12 @@ int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
|
||||
}
|
||||
|
||||
// save M in u1
|
||||
if (digest_len > (i >> 3)) {
|
||||
unsigned q_bits = BN_num_bits(dsa->q);
|
||||
if (digest_len > (q_bits >> 3)) {
|
||||
// if the digest length is greater than the size of q use the
|
||||
// BN_num_bits(dsa->q) leftmost bits of the digest, see
|
||||
// fips 186-3, 4.2
|
||||
digest_len = (i >> 3);
|
||||
digest_len = (q_bits >> 3);
|
||||
}
|
||||
|
||||
if (BN_bin2bn(digest, digest_len, &u1) == NULL) {
|
||||
|
||||
@@ -61,9 +61,45 @@
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../bytestring/internal.h"
|
||||
|
||||
|
||||
#define OPENSSL_DSA_MAX_MODULUS_BITS 10000
|
||||
|
||||
// This function is in dsa_asn1.c rather than dsa.c because it is reachable from
|
||||
// |EVP_PKEY| parsers. This makes it easier for the static linker to drop most
|
||||
// of the DSA implementation.
|
||||
int dsa_check_parameters(const DSA *dsa) {
|
||||
if (!dsa->p || !dsa->q || !dsa->g) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_MISSING_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Reject invalid parameters. In particular, signing will infinite loop if |g|
|
||||
// is zero.
|
||||
if (BN_is_zero(dsa->p) || BN_is_zero(dsa->q) || BN_is_zero(dsa->g)) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIPS 186-4 allows only three different sizes for q.
|
||||
unsigned q_bits = BN_num_bits(dsa->q);
|
||||
if (q_bits != 160 && q_bits != 224 && q_bits != 256) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_Q_VALUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Bound |dsa->p| to avoid a DoS vector. Note this limit is much larger than
|
||||
// the one in FIPS 186-4, which only allows L = 1024, 2048, and 3072.
|
||||
if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_MODULUS_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_integer(CBS *cbs, BIGNUM **out) {
|
||||
assert(*out == NULL);
|
||||
*out = BN_new();
|
||||
@@ -124,10 +160,16 @@ DSA *DSA_parse_public_key(CBS *cbs) {
|
||||
!parse_integer(&child, &ret->g) ||
|
||||
CBS_len(&child) != 0) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR);
|
||||
DSA_free(ret);
|
||||
return NULL;
|
||||
goto err;
|
||||
}
|
||||
if (!dsa_check_parameters(ret)) {
|
||||
goto err;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
DSA_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DSA_marshal_public_key(CBB *cbb, const DSA *dsa) {
|
||||
@@ -156,10 +198,16 @@ DSA *DSA_parse_parameters(CBS *cbs) {
|
||||
!parse_integer(&child, &ret->g) ||
|
||||
CBS_len(&child) != 0) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR);
|
||||
DSA_free(ret);
|
||||
return NULL;
|
||||
goto err;
|
||||
}
|
||||
if (!dsa_check_parameters(ret)) {
|
||||
goto err;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
DSA_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DSA_marshal_parameters(CBB *cbb, const DSA *dsa) {
|
||||
@@ -203,6 +251,9 @@ DSA *DSA_parse_private_key(CBS *cbs) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (!dsa_check_parameters(ret)) {
|
||||
goto err;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_DSA_INTERNAL_H
|
||||
#define OPENSSL_HEADER_DSA_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_dsa.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// dsa_check_parameters checks that |dsa|'s group is within DoS bounds. It
|
||||
// returns one on success and zero on error.
|
||||
int dsa_check_parameters(const DSA *dsa);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_DSA_INTERNAL_H
|
||||
@@ -50,12 +50,10 @@
|
||||
|
||||
// expand_message_xmd implements the operation described in section 5.3.1 of
|
||||
// draft-irtf-cfrg-hash-to-curve-07. It returns one on success and zero on
|
||||
// allocation failure or if |out_len| was too large. If |is_draft06| is one, it
|
||||
// implements the operation from draft-irtf-cfrg-hash-to-curve-06 instead.
|
||||
// allocation failure or if |out_len| was too large.
|
||||
static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
|
||||
const uint8_t *msg, size_t msg_len,
|
||||
const uint8_t *dst, size_t dst_len,
|
||||
int is_draft06) {
|
||||
const uint8_t *dst, size_t dst_len) {
|
||||
int ret = 0;
|
||||
const size_t block_size = EVP_MD_block_size(md);
|
||||
const size_t md_size = EVP_MD_size(md);
|
||||
@@ -88,9 +86,8 @@ static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
|
||||
!EVP_DigestUpdate(&ctx, kZeros, block_size) ||
|
||||
!EVP_DigestUpdate(&ctx, msg, msg_len) ||
|
||||
!EVP_DigestUpdate(&ctx, l_i_b_str_zero, sizeof(l_i_b_str_zero)) ||
|
||||
(is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
|
||||
(!is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestUpdate(&ctx, &dst_len_u8, 1) ||
|
||||
!EVP_DigestFinal_ex(&ctx, b_0, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
@@ -114,9 +111,8 @@ static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
|
||||
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
|
||||
!EVP_DigestUpdate(&ctx, b_i, md_size) ||
|
||||
!EVP_DigestUpdate(&ctx, &i, 1) ||
|
||||
(is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
|
||||
(!is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestUpdate(&ctx, &dst_len_u8, 1) ||
|
||||
!EVP_DigestFinal_ex(&ctx, b_i, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
@@ -175,12 +171,11 @@ static void big_endian_to_words(BN_ULONG *out, size_t num_words,
|
||||
static int hash_to_field2(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_FELEM *out1, EC_FELEM *out2, const uint8_t *dst,
|
||||
size_t dst_len, unsigned k, const uint8_t *msg,
|
||||
size_t msg_len, int is_draft06) {
|
||||
size_t msg_len) {
|
||||
size_t L;
|
||||
uint8_t buf[4 * EC_MAX_BYTES];
|
||||
if (!num_bytes_to_derive(&L, &group->field, k) ||
|
||||
!expand_message_xmd(md, buf, 2 * L, msg, msg_len, dst, dst_len,
|
||||
is_draft06)) {
|
||||
!expand_message_xmd(md, buf, 2 * L, msg, msg_len, dst, dst_len)) {
|
||||
return 0;
|
||||
}
|
||||
BN_ULONG words[2 * EC_MAX_WORDS];
|
||||
@@ -196,12 +191,11 @@ static int hash_to_field2(const EC_GROUP *group, const EVP_MD *md,
|
||||
// group order rather than a field element. |k| is the security factor.
|
||||
static int hash_to_scalar(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
unsigned k, const uint8_t *msg, size_t msg_len,
|
||||
int is_draft06) {
|
||||
unsigned k, const uint8_t *msg, size_t msg_len) {
|
||||
size_t L;
|
||||
uint8_t buf[EC_MAX_BYTES * 2];
|
||||
if (!num_bytes_to_derive(&L, &group->order, k) ||
|
||||
!expand_message_xmd(md, buf, L, msg, msg_len, dst, dst_len, is_draft06)) {
|
||||
!expand_message_xmd(md, buf, L, msg, msg_len, dst, dst_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -310,10 +304,9 @@ static int map_to_curve_simple_swu(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
static int hash_to_curve(const EC_GROUP *group, const EVP_MD *md,
|
||||
const EC_FELEM *Z, const EC_FELEM *c2, unsigned k,
|
||||
EC_RAW_POINT *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len, int is_draft06) {
|
||||
const uint8_t *msg, size_t msg_len) {
|
||||
EC_FELEM u0, u1;
|
||||
if (!hash_to_field2(group, md, &u0, &u1, dst, dst_len, k, msg, msg_len,
|
||||
is_draft06)) {
|
||||
if (!hash_to_field2(group, md, &u0, &u1, dst, dst_len, k, msg, msg_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -376,7 +369,7 @@ int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
ec_felem_neg(group, &Z, &Z);
|
||||
|
||||
return hash_to_curve(group, EVP_sha512(), &Z, &c2, /*k=*/192, out, dst,
|
||||
dst_len, msg, msg_len, /*is_draft06=*/0);
|
||||
dst_len, msg, msg_len);
|
||||
}
|
||||
|
||||
int ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
||||
@@ -388,38 +381,5 @@ int ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
||||
}
|
||||
|
||||
return hash_to_scalar(group, EVP_sha512(), out, dst, dst_len, /*k=*/192, msg,
|
||||
msg_len, /*is_draft06=*/0);
|
||||
}
|
||||
|
||||
int ec_hash_to_curve_p521_xmd_sha512_sswu_draft06(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len) {
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-06.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp521r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Z = -4, c2 = 8.
|
||||
EC_FELEM Z, c2;
|
||||
if (!felem_from_u8(group, &Z, 4) ||
|
||||
!felem_from_u8(group, &c2, 8)) {
|
||||
return 0;
|
||||
}
|
||||
ec_felem_neg(group, &Z, &Z);
|
||||
|
||||
return hash_to_curve(group, EVP_sha512(), &Z, &c2, /*k=*/256, out, dst,
|
||||
dst_len, msg, msg_len, /*is_draft06=*/1);
|
||||
}
|
||||
|
||||
int ec_hash_to_scalar_p521_xmd_sha512_draft06(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len) {
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp521r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hash_to_scalar(group, EVP_sha512(), out, dst, dst_len, /*k=*/256, msg,
|
||||
msg_len, /*is_draft06=*/1);
|
||||
msg_len);
|
||||
}
|
||||
@@ -48,28 +48,6 @@ OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_curve_p521_xmd_sha512_sswu_draft06 hashes |msg| to a point on
|
||||
// |group| and writes the result to |out|, implementing the
|
||||
// P521_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-06. It
|
||||
// returns one on success and zero on error.
|
||||
//
|
||||
// This function implements an older version of the draft and should not be used
|
||||
// in new code.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p521_xmd_sha512_sswu_draft06(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_scalar_p521_xmd_sha512_draft06 hashes |msg| to a scalar on |group|
|
||||
// and writes the result to |out|, using the hash_to_field operation from the
|
||||
// P521_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-06, but
|
||||
// generating a value modulo the group order rather than a field element.
|
||||
//
|
||||
// This function implements an older version of the draft and should not be used
|
||||
// in new code.
|
||||
OPENSSL_EXPORT int ec_hash_to_scalar_p521_xmd_sha512_draft06(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -76,6 +76,10 @@
|
||||
// TODO(davidben): Fix Node to not touch the error queue itself and remove this.
|
||||
OPENSSL_DECLARE_ERROR_REASON(EVP, NOT_XOF_OR_INVALID_LENGTH)
|
||||
|
||||
// The HPKE module uses the EVP error namespace, but it lives in another
|
||||
// directory.
|
||||
OPENSSL_DECLARE_ERROR_REASON(EVP, EMPTY_PSK)
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new(void) {
|
||||
EVP_PKEY *ret;
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#include <CCryptoBoringSSL_rsa.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
@@ -386,3 +387,161 @@ err:
|
||||
EVP_PKEY_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EVP_PKEY *d2i_PUBKEY(EVP_PKEY **out, const uint8_t **inp, long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
EVP_PKEY *ret = EVP_parse_public_key(&cbs);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (out != NULL) {
|
||||
EVP_PKEY_free(*out);
|
||||
*out = ret;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int i2d_PUBKEY(const EVP_PKEY *pkey, uint8_t **outp) {
|
||||
if (pkey == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, 128) ||
|
||||
!EVP_marshal_public_key(&cbb, pkey)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
RSA *d2i_RSA_PUBKEY(RSA **out, const uint8_t **inp, long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
EVP_PKEY *pkey = EVP_parse_public_key(&cbs);
|
||||
if (pkey == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
RSA *rsa = EVP_PKEY_get1_RSA(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
if (rsa == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (out != NULL) {
|
||||
RSA_free(*out);
|
||||
*out = rsa;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
int i2d_RSA_PUBKEY(const RSA *rsa, uint8_t **outp) {
|
||||
if (rsa == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = -1;
|
||||
EVP_PKEY *pkey = EVP_PKEY_new();
|
||||
if (pkey == NULL ||
|
||||
!EVP_PKEY_set1_RSA(pkey, (RSA *)rsa)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = i2d_PUBKEY(pkey, outp);
|
||||
|
||||
err:
|
||||
EVP_PKEY_free(pkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
DSA *d2i_DSA_PUBKEY(DSA **out, const uint8_t **inp, long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
EVP_PKEY *pkey = EVP_parse_public_key(&cbs);
|
||||
if (pkey == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
DSA *dsa = EVP_PKEY_get1_DSA(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
if (dsa == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (out != NULL) {
|
||||
DSA_free(*out);
|
||||
*out = dsa;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return dsa;
|
||||
}
|
||||
|
||||
int i2d_DSA_PUBKEY(const DSA *dsa, uint8_t **outp) {
|
||||
if (dsa == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = -1;
|
||||
EVP_PKEY *pkey = EVP_PKEY_new();
|
||||
if (pkey == NULL ||
|
||||
!EVP_PKEY_set1_DSA(pkey, (DSA *)dsa)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = i2d_PUBKEY(pkey, outp);
|
||||
|
||||
err:
|
||||
EVP_PKEY_free(pkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EC_KEY *d2i_EC_PUBKEY(EC_KEY **out, const uint8_t **inp, long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
EVP_PKEY *pkey = EVP_parse_public_key(&cbs);
|
||||
if (pkey == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
EC_KEY *ec_key = EVP_PKEY_get1_EC_KEY(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
if (ec_key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (out != NULL) {
|
||||
EC_KEY_free(*out);
|
||||
*out = ec_key;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return ec_key;
|
||||
}
|
||||
|
||||
int i2d_EC_PUBKEY(const EC_KEY *ec_key, uint8_t **outp) {
|
||||
if (ec_key == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = -1;
|
||||
EVP_PKEY *pkey = EVP_PKEY_new();
|
||||
if (pkey == NULL ||
|
||||
!EVP_PKEY_set1_EC_KEY(pkey, (EC_KEY *)ec_key)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = i2d_PUBKEY(pkey, outp);
|
||||
|
||||
err:
|
||||
EVP_PKEY_free(pkey);
|
||||
return ret;
|
||||
}
|
||||
@@ -141,9 +141,13 @@ static int dsa_priv_decode(EVP_PKEY *out, CBS *params, CBS *key) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Decode the key.
|
||||
// Decode the key. To avoid DoS attacks when importing private keys, we bound
|
||||
// |dsa->priv_key| against |dsa->q|, which itself bound by
|
||||
// |DSA_parse_parameters|. (We cannot call |BN_num_bits| on |dsa->priv_key|.
|
||||
// That would leak a secret bit width.)
|
||||
if (!BN_parse_asn1_unsigned(key, dsa->priv_key) ||
|
||||
CBS_len(key) != 0) {
|
||||
CBS_len(key) != 0 ||
|
||||
BN_cmp(dsa->priv_key, dsa->q) >= 0) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ Lrcon:
|
||||
.align 5
|
||||
_aes_hw_set_encrypt_key:
|
||||
Lenc_key:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
mov x3,#-1
|
||||
@@ -202,6 +204,7 @@ Lenc_key_abort:
|
||||
|
||||
.align 5
|
||||
_aes_hw_set_decrypt_key:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
bl Lenc_key
|
||||
@@ -235,6 +238,7 @@ Loop_imc:
|
||||
eor x0,x0,x0 // return value
|
||||
Ldec_key_abort:
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
.globl _aes_hw_encrypt
|
||||
@@ -242,6 +246,7 @@ Ldec_key_abort:
|
||||
|
||||
.align 5
|
||||
_aes_hw_encrypt:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ldr w3,[x2,#240]
|
||||
ld1 {v0.4s},[x2],#16
|
||||
ld1 {v2.16b},[x0]
|
||||
@@ -272,6 +277,7 @@ Loop_enc:
|
||||
|
||||
.align 5
|
||||
_aes_hw_decrypt:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ldr w3,[x2,#240]
|
||||
ld1 {v0.4s},[x2],#16
|
||||
ld1 {v2.16b},[x0]
|
||||
@@ -302,6 +308,8 @@ Loop_dec:
|
||||
|
||||
.align 5
|
||||
_aes_hw_cbc_encrypt:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
subs x2,x2,#16
|
||||
@@ -593,6 +601,8 @@ Lcbc_abort:
|
||||
|
||||
.align 5
|
||||
_aes_hw_ctr32_encrypt_blocks:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
ldr w5,[x3,#240]
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
.align 5
|
||||
aes_hw_set_encrypt_key:
|
||||
.Lenc_key:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
mov x3,#-1
|
||||
@@ -203,6 +205,7 @@ aes_hw_set_encrypt_key:
|
||||
.type aes_hw_set_decrypt_key,%function
|
||||
.align 5
|
||||
aes_hw_set_decrypt_key:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
bl .Lenc_key
|
||||
@@ -236,6 +239,7 @@ aes_hw_set_decrypt_key:
|
||||
eor x0,x0,x0 // return value
|
||||
.Ldec_key_abort:
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size aes_hw_set_decrypt_key,.-aes_hw_set_decrypt_key
|
||||
.globl aes_hw_encrypt
|
||||
@@ -243,6 +247,7 @@ aes_hw_set_decrypt_key:
|
||||
.type aes_hw_encrypt,%function
|
||||
.align 5
|
||||
aes_hw_encrypt:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ldr w3,[x2,#240]
|
||||
ld1 {v0.4s},[x2],#16
|
||||
ld1 {v2.16b},[x0]
|
||||
@@ -273,6 +278,7 @@ aes_hw_encrypt:
|
||||
.type aes_hw_decrypt,%function
|
||||
.align 5
|
||||
aes_hw_decrypt:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ldr w3,[x2,#240]
|
||||
ld1 {v0.4s},[x2],#16
|
||||
ld1 {v2.16b},[x0]
|
||||
@@ -303,6 +309,8 @@ aes_hw_decrypt:
|
||||
.type aes_hw_cbc_encrypt,%function
|
||||
.align 5
|
||||
aes_hw_cbc_encrypt:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
subs x2,x2,#16
|
||||
@@ -594,6 +602,8 @@ aes_hw_cbc_encrypt:
|
||||
.type aes_hw_ctr32_encrypt_blocks,%function
|
||||
.align 5
|
||||
aes_hw_ctr32_encrypt_blocks:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
ldr w5,[x3,#240]
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
.text
|
||||
|
||||
.globl _bn_mul_mont
|
||||
@@ -21,6 +23,7 @@
|
||||
|
||||
.align 5
|
||||
_bn_mul_mont:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
tst x5,#7
|
||||
b.eq __bn_sqr8x_mont
|
||||
tst x5,#3
|
||||
@@ -218,11 +221,14 @@ Lcond_copy:
|
||||
mov x0,#1
|
||||
ldp x23,x24,[x29,#48]
|
||||
ldr x29,[sp],#64
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
.align 5
|
||||
__bn_sqr8x_mont:
|
||||
// Not adding AARCH64_SIGN_LINK_REGISTER here because __bn_sqr8x_mont is jumped to
|
||||
// only from bn_mul_mont which has already signed the return address.
|
||||
cmp x1,x2
|
||||
b.ne __bn_mul4x_mont
|
||||
Lsqr8x_mont:
|
||||
@@ -976,11 +982,16 @@ Lsqr8x_done:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldr x29,[sp],#128
|
||||
// x30 is popped earlier
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
.align 5
|
||||
__bn_mul4x_mont:
|
||||
// Not adding AARCH64_SIGN_LINK_REGISTER here because __bn_mul4x_mont is jumped to
|
||||
// only from bn_mul_mont or __bn_mul8x_mont which have already signed the
|
||||
// return address.
|
||||
stp x29,x30,[sp,#-128]!
|
||||
add x29,sp,#0
|
||||
stp x19,x20,[sp,#16]
|
||||
@@ -1414,6 +1425,8 @@ Lmul4x_done:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldr x29,[sp],#128
|
||||
// x30 is popped earlier
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
.byte 77,111,110,116,103,111,109,101,114,121,32,77,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
.text
|
||||
|
||||
.globl bn_mul_mont
|
||||
@@ -22,6 +24,7 @@
|
||||
.type bn_mul_mont,%function
|
||||
.align 5
|
||||
bn_mul_mont:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
tst x5,#7
|
||||
b.eq __bn_sqr8x_mont
|
||||
tst x5,#3
|
||||
@@ -219,11 +222,14 @@ bn_mul_mont:
|
||||
mov x0,#1
|
||||
ldp x23,x24,[x29,#48]
|
||||
ldr x29,[sp],#64
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size bn_mul_mont,.-bn_mul_mont
|
||||
.type __bn_sqr8x_mont,%function
|
||||
.align 5
|
||||
__bn_sqr8x_mont:
|
||||
// Not adding AARCH64_SIGN_LINK_REGISTER here because __bn_sqr8x_mont is jumped to
|
||||
// only from bn_mul_mont which has already signed the return address.
|
||||
cmp x1,x2
|
||||
b.ne __bn_mul4x_mont
|
||||
.Lsqr8x_mont:
|
||||
@@ -977,11 +983,16 @@ __bn_sqr8x_mont:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldr x29,[sp],#128
|
||||
// x30 is popped earlier
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size __bn_sqr8x_mont,.-__bn_sqr8x_mont
|
||||
.type __bn_mul4x_mont,%function
|
||||
.align 5
|
||||
__bn_mul4x_mont:
|
||||
// Not adding AARCH64_SIGN_LINK_REGISTER here because __bn_mul4x_mont is jumped to
|
||||
// only from bn_mul_mont or __bn_mul8x_mont which have already signed the
|
||||
// return address.
|
||||
stp x29,x30,[sp,#-128]!
|
||||
add x29,sp,#0
|
||||
stp x19,x20,[sp,#16]
|
||||
@@ -1415,6 +1426,8 @@ __bn_mul4x_mont:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldr x29,[sp],#128
|
||||
// x30 is popped earlier
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size __bn_mul4x_mont,.-__bn_mul4x_mont
|
||||
.byte 77,111,110,116,103,111,109,101,114,121,32,77,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
|
||||
@@ -404,9 +404,19 @@ uint64_t bn_mont_n0(const BIGNUM *n);
|
||||
int bn_mod_exp_base_2_consttime(BIGNUM *r, unsigned p, const BIGNUM *n,
|
||||
BN_CTX *ctx);
|
||||
|
||||
#if defined(OPENSSL_X86_64) && defined(_MSC_VER)
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(OPENSSL_X86_64)
|
||||
#define BN_UMULT_LOHI(low, high, a, b) ((low) = _umul128((a), (b), &(high)))
|
||||
#elif defined(OPENSSL_AARCH64)
|
||||
#define BN_UMULT_LOHI(low, high, a, b) \
|
||||
do { \
|
||||
const BN_ULONG _a = (a); \
|
||||
const BN_ULONG _b = (b); \
|
||||
(low) = _a * _b; \
|
||||
(high) = __umulh(_a, _b); \
|
||||
} while (0)
|
||||
#endif
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if !defined(BN_ULLONG) && !defined(BN_UMULT_LOHI)
|
||||
#error "Either BN_ULLONG or BN_UMULT_LOHI must be defined on every platform."
|
||||
|
||||
@@ -122,6 +122,8 @@ int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, uint8_t *out, size_t len) {
|
||||
|
||||
uint32_t EVP_MD_meth_get_flags(const EVP_MD *md) { return EVP_MD_flags(md); }
|
||||
|
||||
void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) {}
|
||||
|
||||
int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) {
|
||||
// |in->digest| may be NULL if this is a signing |EVP_MD_CTX| for, e.g.,
|
||||
// Ed25519 which does not hash with |EVP_MD_CTX|.
|
||||
|
||||
@@ -703,7 +703,8 @@ void ec_GFp_mont_felem_to_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
int ec_GFp_mont_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out,
|
||||
const uint8_t *in, size_t len);
|
||||
|
||||
void ec_GFp_nistp_recode_scalar_bits(uint8_t *sign, uint8_t *digit, uint8_t in);
|
||||
void ec_GFp_nistp_recode_scalar_bits(crypto_word_t *sign, crypto_word_t *digit,
|
||||
crypto_word_t in);
|
||||
|
||||
const EC_METHOD *EC_GFp_nistp224_method(void);
|
||||
const EC_METHOD *EC_GFp_nistp256_method(void);
|
||||
|
||||
@@ -866,7 +866,7 @@ static void p224_select_point(const uint64_t idx, size_t size,
|
||||
}
|
||||
|
||||
// p224_get_bit returns the |i|th bit in |in|
|
||||
static char p224_get_bit(const p224_felem_bytearray in, size_t i) {
|
||||
static crypto_word_t p224_get_bit(const p224_felem_bytearray in, size_t i) {
|
||||
if (i >= 224) {
|
||||
return 0;
|
||||
}
|
||||
@@ -977,13 +977,13 @@ static void ec_GFp_nistp224_point_mul(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
|
||||
// Add every 5 doublings.
|
||||
if (i % 5 == 0) {
|
||||
uint64_t bits = p224_get_bit(scalar->bytes, i + 4) << 5;
|
||||
crypto_word_t bits = p224_get_bit(scalar->bytes, i + 4) << 5;
|
||||
bits |= p224_get_bit(scalar->bytes, i + 3) << 4;
|
||||
bits |= p224_get_bit(scalar->bytes, i + 2) << 3;
|
||||
bits |= p224_get_bit(scalar->bytes, i + 1) << 2;
|
||||
bits |= p224_get_bit(scalar->bytes, i) << 1;
|
||||
bits |= p224_get_bit(scalar->bytes, i - 1);
|
||||
uint8_t sign, digit;
|
||||
crypto_word_t sign, digit;
|
||||
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, bits);
|
||||
|
||||
// Select the point to add or subtract.
|
||||
@@ -1022,7 +1022,7 @@ static void ec_GFp_nistp224_point_mul_base(const EC_GROUP *group,
|
||||
}
|
||||
|
||||
// First, look 28 bits upwards.
|
||||
uint64_t bits = p224_get_bit(scalar->bytes, i + 196) << 3;
|
||||
crypto_word_t bits = p224_get_bit(scalar->bytes, i + 196) << 3;
|
||||
bits |= p224_get_bit(scalar->bytes, i + 140) << 2;
|
||||
bits |= p224_get_bit(scalar->bytes, i + 84) << 1;
|
||||
bits |= p224_get_bit(scalar->bytes, i + 28);
|
||||
@@ -1080,14 +1080,15 @@ static void ec_GFp_nistp224_point_mul_public(const EC_GROUP *group,
|
||||
// Add multiples of the generator.
|
||||
if (i <= 27) {
|
||||
// First, look 28 bits upwards.
|
||||
uint64_t bits = p224_get_bit(g_scalar->bytes, i + 196) << 3;
|
||||
crypto_word_t bits = p224_get_bit(g_scalar->bytes, i + 196) << 3;
|
||||
bits |= p224_get_bit(g_scalar->bytes, i + 140) << 2;
|
||||
bits |= p224_get_bit(g_scalar->bytes, i + 84) << 1;
|
||||
bits |= p224_get_bit(g_scalar->bytes, i + 28);
|
||||
|
||||
size_t index = (size_t)bits;
|
||||
p224_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 1 /* mixed */,
|
||||
g_p224_pre_comp[1][bits][0], g_p224_pre_comp[1][bits][1],
|
||||
g_p224_pre_comp[1][bits][2]);
|
||||
g_p224_pre_comp[1][index][0], g_p224_pre_comp[1][index][1],
|
||||
g_p224_pre_comp[1][index][2]);
|
||||
assert(!skip);
|
||||
|
||||
// Second, look at the current position.
|
||||
@@ -1095,20 +1096,21 @@ static void ec_GFp_nistp224_point_mul_public(const EC_GROUP *group,
|
||||
bits |= p224_get_bit(g_scalar->bytes, i + 112) << 2;
|
||||
bits |= p224_get_bit(g_scalar->bytes, i + 56) << 1;
|
||||
bits |= p224_get_bit(g_scalar->bytes, i);
|
||||
index = (size_t)bits;
|
||||
p224_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 1 /* mixed */,
|
||||
g_p224_pre_comp[0][bits][0], g_p224_pre_comp[0][bits][1],
|
||||
g_p224_pre_comp[0][bits][2]);
|
||||
g_p224_pre_comp[0][index][0], g_p224_pre_comp[0][index][1],
|
||||
g_p224_pre_comp[0][index][2]);
|
||||
}
|
||||
|
||||
// Incorporate |p_scalar| every 5 doublings.
|
||||
if (i % 5 == 0) {
|
||||
uint64_t bits = p224_get_bit(p_scalar->bytes, i + 4) << 5;
|
||||
crypto_word_t bits = p224_get_bit(p_scalar->bytes, i + 4) << 5;
|
||||
bits |= p224_get_bit(p_scalar->bytes, i + 3) << 4;
|
||||
bits |= p224_get_bit(p_scalar->bytes, i + 2) << 3;
|
||||
bits |= p224_get_bit(p_scalar->bytes, i + 1) << 2;
|
||||
bits |= p224_get_bit(p_scalar->bytes, i) << 1;
|
||||
bits |= p224_get_bit(p_scalar->bytes, i - 1);
|
||||
uint8_t sign, digit;
|
||||
crypto_word_t sign, digit;
|
||||
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, bits);
|
||||
|
||||
// Select the point to add or subtract.
|
||||
|
||||
@@ -52,8 +52,8 @@ static const BN_ULONG ONE[P256_LIMBS] = {
|
||||
|
||||
// Recode window to a signed digit, see |ec_GFp_nistp_recode_scalar_bits| in
|
||||
// util.c for details
|
||||
static unsigned booth_recode_w5(unsigned in) {
|
||||
unsigned s, d;
|
||||
static crypto_word_t booth_recode_w5(crypto_word_t in) {
|
||||
crypto_word_t s, d;
|
||||
|
||||
s = ~((in >> 5) - 1);
|
||||
d = (1 << 6) - in - 1;
|
||||
@@ -63,8 +63,8 @@ static unsigned booth_recode_w5(unsigned in) {
|
||||
return (d << 1) + (s & 1);
|
||||
}
|
||||
|
||||
static unsigned booth_recode_w7(unsigned in) {
|
||||
unsigned s, d;
|
||||
static crypto_word_t booth_recode_w7(crypto_word_t in) {
|
||||
crypto_word_t s, d;
|
||||
|
||||
s = ~((in >> 7) - 1);
|
||||
d = (1 << 8) - in - 1;
|
||||
@@ -196,8 +196,8 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
|
||||
assert(p_scalar != NULL);
|
||||
assert(group->field.width == P256_LIMBS);
|
||||
|
||||
static const unsigned kWindowSize = 5;
|
||||
static const unsigned kMask = (1 << (5 /* kWindowSize */ + 1)) - 1;
|
||||
static const size_t kWindowSize = 5;
|
||||
static const crypto_word_t kMask = (1 << (5 /* kWindowSize */ + 1)) - 1;
|
||||
|
||||
// A |P256_POINT| is (3 * 32) = 96 bytes, and the 64-byte alignment should
|
||||
// add no more than 63 bytes of overhead. Thus, |table| should require
|
||||
@@ -234,17 +234,17 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
|
||||
|
||||
BN_ULONG tmp[P256_LIMBS];
|
||||
alignas(32) P256_POINT h;
|
||||
unsigned index = 255;
|
||||
unsigned wvalue = p_str[(index - 1) / 8];
|
||||
size_t index = 255;
|
||||
crypto_word_t wvalue = p_str[(index - 1) / 8];
|
||||
wvalue = (wvalue >> ((index - 1) % 8)) & kMask;
|
||||
|
||||
ecp_nistz256_select_w5(r, table, booth_recode_w5(wvalue) >> 1);
|
||||
|
||||
while (index >= 5) {
|
||||
if (index != 255) {
|
||||
unsigned off = (index - 1) / 8;
|
||||
size_t off = (index - 1) / 8;
|
||||
|
||||
wvalue = p_str[off] | p_str[off + 1] << 8;
|
||||
wvalue = (crypto_word_t)p_str[off] | (crypto_word_t)p_str[off + 1] << 8;
|
||||
wvalue = (wvalue >> ((index - 1) % 8)) & kMask;
|
||||
|
||||
wvalue = booth_recode_w5(wvalue);
|
||||
@@ -285,21 +285,22 @@ typedef union {
|
||||
P256_POINT_AFFINE a;
|
||||
} p256_point_union_t;
|
||||
|
||||
static unsigned calc_first_wvalue(unsigned *index, const uint8_t p_str[33]) {
|
||||
static const unsigned kWindowSize = 7;
|
||||
static const unsigned kMask = (1 << (7 /* kWindowSize */ + 1)) - 1;
|
||||
static crypto_word_t calc_first_wvalue(size_t *index, const uint8_t p_str[33]) {
|
||||
static const size_t kWindowSize = 7;
|
||||
static const crypto_word_t kMask = (1 << (7 /* kWindowSize */ + 1)) - 1;
|
||||
*index = kWindowSize;
|
||||
|
||||
unsigned wvalue = (p_str[0] << 1) & kMask;
|
||||
crypto_word_t wvalue = (p_str[0] << 1) & kMask;
|
||||
return booth_recode_w7(wvalue);
|
||||
}
|
||||
|
||||
static unsigned calc_wvalue(unsigned *index, const uint8_t p_str[33]) {
|
||||
static const unsigned kWindowSize = 7;
|
||||
static const unsigned kMask = (1 << (7 /* kWindowSize */ + 1)) - 1;
|
||||
static crypto_word_t calc_wvalue(size_t *index, const uint8_t p_str[33]) {
|
||||
static const size_t kWindowSize = 7;
|
||||
static const crypto_word_t kMask = (1 << (7 /* kWindowSize */ + 1)) - 1;
|
||||
|
||||
const unsigned off = (*index - 1) / 8;
|
||||
unsigned wvalue = p_str[off] | p_str[off + 1] << 8;
|
||||
const size_t off = (*index - 1) / 8;
|
||||
crypto_word_t wvalue =
|
||||
(crypto_word_t)p_str[off] | (crypto_word_t)p_str[off + 1] << 8;
|
||||
wvalue = (wvalue >> ((*index - 1) % 8)) & kMask;
|
||||
*index += kWindowSize;
|
||||
|
||||
@@ -327,8 +328,8 @@ static void ecp_nistz256_point_mul_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
p_str[32] = 0;
|
||||
|
||||
// First window
|
||||
unsigned index = 0;
|
||||
unsigned wvalue = calc_first_wvalue(&index, p_str);
|
||||
size_t index = 0;
|
||||
crypto_word_t wvalue = calc_first_wvalue(&index, p_str);
|
||||
|
||||
ecp_nistz256_select_w7(&p.a, ecp_nistz256_precomputed[0], wvalue >> 1);
|
||||
ecp_nistz256_neg(p.p.Z, p.p.Y);
|
||||
@@ -372,8 +373,8 @@ static void ecp_nistz256_points_mul_public(const EC_GROUP *group,
|
||||
p_str[32] = 0;
|
||||
|
||||
// First window
|
||||
unsigned index = 0;
|
||||
unsigned wvalue = calc_first_wvalue(&index, p_str);
|
||||
size_t index = 0;
|
||||
size_t wvalue = calc_first_wvalue(&index, p_str);
|
||||
|
||||
// Convert |p| from affine to Jacobian coordinates. We set Z to zero if |p|
|
||||
// is infinity and |ONE| otherwise. |p| was computed from the table, so it
|
||||
|
||||
@@ -67,7 +67,7 @@ static fiat_p256_limb_t fiat_p256_nz(
|
||||
|
||||
static void fiat_p256_copy(fiat_p256_limb_t out[FIAT_P256_NLIMBS],
|
||||
const fiat_p256_limb_t in1[FIAT_P256_NLIMBS]) {
|
||||
for (int i = 0; i < FIAT_P256_NLIMBS; i++) {
|
||||
for (size_t i = 0; i < FIAT_P256_NLIMBS; i++) {
|
||||
out[i] = in1[i];
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ static void fiat_p256_select_point(const fiat_p256_limb_t idx, size_t size,
|
||||
}
|
||||
|
||||
// fiat_p256_get_bit returns the |i|th bit in |in|
|
||||
static char fiat_p256_get_bit(const uint8_t *in, int i) {
|
||||
static crypto_word_t fiat_p256_get_bit(const uint8_t *in, int i) {
|
||||
if (i < 0 || i >= 256) {
|
||||
return 0;
|
||||
}
|
||||
@@ -498,20 +498,20 @@ static void ec_GFp_nistp256_point_mul(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
|
||||
// do other additions every 5 doublings
|
||||
if (i % 5 == 0) {
|
||||
uint64_t bits = fiat_p256_get_bit(scalar->bytes, i + 4) << 5;
|
||||
crypto_word_t bits = fiat_p256_get_bit(scalar->bytes, i + 4) << 5;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 3) << 4;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 2) << 3;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 1) << 2;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i) << 1;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i - 1);
|
||||
uint8_t sign, digit;
|
||||
crypto_word_t sign, digit;
|
||||
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, bits);
|
||||
|
||||
// select the point to add or subtract, in constant time.
|
||||
fiat_p256_select_point(digit, 17, (const fiat_p256_felem(*)[3])p_pre_comp,
|
||||
tmp);
|
||||
fiat_p256_select_point((fiat_p256_limb_t)digit, 17,
|
||||
(const fiat_p256_felem(*)[3])p_pre_comp, tmp);
|
||||
fiat_p256_opp(ftmp, tmp[1]); // (X, -Y, Z) is the negative point.
|
||||
fiat_p256_cmovznz(tmp[1], sign, tmp[1], ftmp);
|
||||
fiat_p256_cmovznz(tmp[1], (fiat_p256_limb_t)sign, tmp[1], ftmp);
|
||||
|
||||
if (!skip) {
|
||||
fiat_p256_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2],
|
||||
@@ -543,12 +543,13 @@ static void ec_GFp_nistp256_point_mul_base(const EC_GROUP *group,
|
||||
}
|
||||
|
||||
// First, look 32 bits upwards.
|
||||
uint64_t bits = fiat_p256_get_bit(scalar->bytes, i + 224) << 3;
|
||||
crypto_word_t bits = fiat_p256_get_bit(scalar->bytes, i + 224) << 3;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 160) << 2;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 96) << 1;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 32);
|
||||
// Select the point to add, in constant time.
|
||||
fiat_p256_select_point_affine(bits, 15, fiat_p256_g_pre_comp[1], tmp);
|
||||
fiat_p256_select_point_affine((fiat_p256_limb_t)bits, 15,
|
||||
fiat_p256_g_pre_comp[1], tmp);
|
||||
|
||||
if (!skip) {
|
||||
fiat_p256_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2],
|
||||
@@ -566,7 +567,8 @@ static void ec_GFp_nistp256_point_mul_base(const EC_GROUP *group,
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 64) << 1;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i);
|
||||
// Select the point to add, in constant time.
|
||||
fiat_p256_select_point_affine(bits, 15, fiat_p256_g_pre_comp[0], tmp);
|
||||
fiat_p256_select_point_affine((fiat_p256_limb_t)bits, 15,
|
||||
fiat_p256_g_pre_comp[0], tmp);
|
||||
fiat_p256_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 1 /* mixed */,
|
||||
tmp[0], tmp[1], tmp[2]);
|
||||
}
|
||||
@@ -613,14 +615,15 @@ static void ec_GFp_nistp256_point_mul_public(const EC_GROUP *group,
|
||||
// constant-time lookup.
|
||||
if (i <= 31) {
|
||||
// First, look 32 bits upwards.
|
||||
uint64_t bits = fiat_p256_get_bit(g_scalar->bytes, i + 224) << 3;
|
||||
crypto_word_t bits = fiat_p256_get_bit(g_scalar->bytes, i + 224) << 3;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 160) << 2;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 96) << 1;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 32);
|
||||
if (bits != 0) {
|
||||
size_t index = (size_t)(bits - 1);
|
||||
fiat_p256_point_add(ret[0], ret[1], ret[2], ret[0], ret[1], ret[2],
|
||||
1 /* mixed */, fiat_p256_g_pre_comp[1][bits - 1][0],
|
||||
fiat_p256_g_pre_comp[1][bits - 1][1],
|
||||
1 /* mixed */, fiat_p256_g_pre_comp[1][index][0],
|
||||
fiat_p256_g_pre_comp[1][index][1],
|
||||
fiat_p256_one);
|
||||
skip = 0;
|
||||
}
|
||||
@@ -631,9 +634,10 @@ static void ec_GFp_nistp256_point_mul_public(const EC_GROUP *group,
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 64) << 1;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i);
|
||||
if (bits != 0) {
|
||||
size_t index = (size_t)(bits - 1);
|
||||
fiat_p256_point_add(ret[0], ret[1], ret[2], ret[0], ret[1], ret[2],
|
||||
1 /* mixed */, fiat_p256_g_pre_comp[0][bits - 1][0],
|
||||
fiat_p256_g_pre_comp[0][bits - 1][1],
|
||||
1 /* mixed */, fiat_p256_g_pre_comp[0][index][0],
|
||||
fiat_p256_g_pre_comp[0][index][1],
|
||||
fiat_p256_one);
|
||||
skip = 0;
|
||||
}
|
||||
@@ -642,7 +646,7 @@ static void ec_GFp_nistp256_point_mul_public(const EC_GROUP *group,
|
||||
int digit = p_wNAF[i];
|
||||
if (digit != 0) {
|
||||
assert(digit & 1);
|
||||
int idx = digit < 0 ? (-digit) >> 1 : digit >> 1;
|
||||
size_t idx = (size_t)(digit < 0 ? (-digit) >> 1 : digit >> 1);
|
||||
fiat_p256_felem *y = &p_pre_comp[idx][1], tmp;
|
||||
if (digit < 0) {
|
||||
fiat_p256_opp(tmp, p_pre_comp[idx][1]);
|
||||
|
||||
@@ -108,7 +108,7 @@ static void ec_GFp_mont_batch_get_window(const EC_GROUP *group,
|
||||
if (i > 0) {
|
||||
window |= bn_is_bit_set_words(scalar->words, width, i - 1);
|
||||
}
|
||||
uint8_t sign, digit;
|
||||
crypto_word_t sign, digit;
|
||||
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, window);
|
||||
|
||||
// Select the entry in constant-time.
|
||||
@@ -121,7 +121,7 @@ static void ec_GFp_mont_batch_get_window(const EC_GROUP *group,
|
||||
// Negate if necessary.
|
||||
EC_FELEM neg_Y;
|
||||
ec_felem_neg(group, &neg_Y, &out->Y);
|
||||
BN_ULONG sign_mask = sign;
|
||||
crypto_word_t sign_mask = sign;
|
||||
sign_mask = 0u - sign_mask;
|
||||
ec_felem_select(group, &out->Y, sign_mask, &neg_Y, &out->Y);
|
||||
}
|
||||
|
||||
@@ -240,9 +240,9 @@
|
||||
// P-384: ...01110011; w = 2, 5, 6, 7 are okay
|
||||
// P-256: ...01010001; w = 5, 7 are okay
|
||||
// P-224: ...00111101; w = 3, 4, 5, 6 are okay
|
||||
void ec_GFp_nistp_recode_scalar_bits(uint8_t *sign, uint8_t *digit,
|
||||
uint8_t in) {
|
||||
uint8_t s, d;
|
||||
void ec_GFp_nistp_recode_scalar_bits(crypto_word_t *sign, crypto_word_t *digit,
|
||||
crypto_word_t in) {
|
||||
crypto_word_t s, d;
|
||||
|
||||
s = ~((in >> 5) - 1); /* sets all bits to MSB(in), 'in' seen as
|
||||
* 6-bit value */
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
.text
|
||||
|
||||
.globl _gcm_init_neon
|
||||
@@ -21,6 +23,7 @@
|
||||
|
||||
.align 4
|
||||
_gcm_init_neon:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
// This function is adapted from gcm_init_v8. xC2 is t3.
|
||||
ld1 {v17.2d}, [x1] // load H
|
||||
movi v19.16b, #0xe1
|
||||
@@ -46,6 +49,7 @@ _gcm_init_neon:
|
||||
|
||||
.align 4
|
||||
_gcm_gmult_neon:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v3.16b}, [x0] // load Xi
|
||||
ld1 {v5.1d}, [x1], #8 // load twisted H
|
||||
ld1 {v6.1d}, [x1]
|
||||
@@ -65,6 +69,7 @@ _gcm_gmult_neon:
|
||||
|
||||
.align 4
|
||||
_gcm_ghash_neon:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v0.16b}, [x0] // load Xi
|
||||
ld1 {v5.1d}, [x1], #8 // load twisted H
|
||||
ld1 {v6.1d}, [x1]
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
.text
|
||||
|
||||
.globl gcm_init_neon
|
||||
@@ -22,6 +24,7 @@
|
||||
.type gcm_init_neon,%function
|
||||
.align 4
|
||||
gcm_init_neon:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
// This function is adapted from gcm_init_v8. xC2 is t3.
|
||||
ld1 {v17.2d}, [x1] // load H
|
||||
movi v19.16b, #0xe1
|
||||
@@ -47,6 +50,7 @@ gcm_init_neon:
|
||||
.type gcm_gmult_neon,%function
|
||||
.align 4
|
||||
gcm_gmult_neon:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v3.16b}, [x0] // load Xi
|
||||
ld1 {v5.1d}, [x1], #8 // load twisted H
|
||||
ld1 {v6.1d}, [x1]
|
||||
@@ -66,6 +70,7 @@ gcm_gmult_neon:
|
||||
.type gcm_ghash_neon,%function
|
||||
.align 4
|
||||
gcm_ghash_neon:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v0.16b}, [x0] // load Xi
|
||||
ld1 {v5.1d}, [x1], #8 // load twisted H
|
||||
ld1 {v6.1d}, [x1]
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
.align 4
|
||||
_gcm_init_v8:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v17.2d},[x1] //load input H
|
||||
movi v19.16b,#0xe1
|
||||
shl v19.2d,v19.2d,#57 //0xc2.0
|
||||
@@ -74,6 +75,7 @@ _gcm_init_v8:
|
||||
|
||||
.align 4
|
||||
_gcm_gmult_v8:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v17.2d},[x0] //load Xi
|
||||
movi v19.16b,#0xe1
|
||||
ld1 {v20.2d,v21.2d},[x1] //load twisted H, ...
|
||||
@@ -116,6 +118,7 @@ _gcm_gmult_v8:
|
||||
|
||||
.align 4
|
||||
_gcm_ghash_v8:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v0.2d},[x0] //load [rotated] Xi
|
||||
//"[rotated]" means that
|
||||
//loaded value would have
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
.type gcm_init_v8,%function
|
||||
.align 4
|
||||
gcm_init_v8:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v17.2d},[x1] //load input H
|
||||
movi v19.16b,#0xe1
|
||||
shl v19.2d,v19.2d,#57 //0xc2.0
|
||||
@@ -75,6 +76,7 @@ gcm_init_v8:
|
||||
.type gcm_gmult_v8,%function
|
||||
.align 4
|
||||
gcm_gmult_v8:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v17.2d},[x0] //load Xi
|
||||
movi v19.16b,#0xe1
|
||||
ld1 {v20.2d,v21.2d},[x1] //load twisted H, ...
|
||||
@@ -117,6 +119,7 @@ gcm_gmult_v8:
|
||||
.type gcm_ghash_v8,%function
|
||||
.align 4
|
||||
gcm_ghash_v8:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ld1 {v0.2d},[x0] //load [rotated] Xi
|
||||
//"[rotated]" means that
|
||||
//loaded value would have
|
||||
|
||||
@@ -108,6 +108,10 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(uint8_t *out, size_t *out_len,
|
||||
int RSA_padding_add_none(uint8_t *to, size_t to_len, const uint8_t *from,
|
||||
size_t from_len);
|
||||
|
||||
// rsa_check_public_key checks that |rsa|'s public modulus and exponent are
|
||||
// within DoS bounds.
|
||||
int rsa_check_public_key(const RSA *rsa);
|
||||
|
||||
// RSA_private_transform calls either the method-specific |private_transform|
|
||||
// function (if given) or the generic one. See the comment for
|
||||
// |private_transform| in |rsa_meth_st|.
|
||||
|
||||
@@ -661,6 +661,9 @@ static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv,
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Note |bn_mul_consttime| and |bn_div_consttime| do not scale linearly, but
|
||||
// checking |ainv| is in range bounds the running time, assuming |m|'s bounds
|
||||
// were checked by the caller.
|
||||
BN_CTX_start(ctx);
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
int ret = tmp != NULL &&
|
||||
@@ -674,22 +677,35 @@ static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv,
|
||||
}
|
||||
|
||||
int RSA_check_key(const RSA *key) {
|
||||
// TODO(davidben): RSA key initialization is spread across
|
||||
// |rsa_check_public_key|, |RSA_check_key|, |freeze_private_key|, and
|
||||
// |BN_MONT_CTX_set_locked| as a result of API issues. See
|
||||
// https://crbug.com/boringssl/316. As a result, we inconsistently check RSA
|
||||
// invariants. We should fix this and integrate that logic.
|
||||
|
||||
if (RSA_is_opaque(key)) {
|
||||
// Opaque keys can't be checked.
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!rsa_check_public_key(key)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((key->p != NULL) != (key->q != NULL)) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_ONLY_ONE_OF_P_Q_GIVEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!key->n || !key->e) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_VALUE_MISSING);
|
||||
// |key->d| must be bounded by |key->n|. This ensures bounds on |RSA_bits|
|
||||
// translate to bounds on the running time of private key operations.
|
||||
if (key->d != NULL &&
|
||||
(BN_is_negative(key->d) || BN_cmp(key->d, key->n) >= 0)) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_D_OUT_OF_RANGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!key->d || !key->p) {
|
||||
if (key->d == NULL || key->p == NULL) {
|
||||
// For a public key, or without p and q, there's nothing that can be
|
||||
// checked.
|
||||
return 1;
|
||||
@@ -709,24 +725,28 @@ int RSA_check_key(const RSA *key) {
|
||||
BN_init(&qm1);
|
||||
BN_init(&dmp1);
|
||||
BN_init(&dmq1);
|
||||
|
||||
// Check that p * q == n. Before we multiply, we check that p and q are in
|
||||
// bounds, to avoid a DoS vector in |bn_mul_consttime| below. Note that
|
||||
// n was bound by |rsa_check_public_key|.
|
||||
if (BN_is_negative(key->p) || BN_cmp(key->p, key->n) >= 0 ||
|
||||
BN_is_negative(key->q) || BN_cmp(key->q, key->n) >= 0) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_N_NOT_EQUAL_P_Q);
|
||||
goto out;
|
||||
}
|
||||
if (!bn_mul_consttime(&tmp, key->p, key->q, ctx)) {
|
||||
OPENSSL_PUT_ERROR(RSA, ERR_LIB_BN);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (BN_cmp(&tmp, key->n) != 0) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_N_NOT_EQUAL_P_Q);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (BN_is_negative(key->d) || BN_cmp(key->d, key->n) >= 0) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_D_OUT_OF_RANGE);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// d must be an inverse of e mod the Carmichael totient, lcm(p-1, q-1), but it
|
||||
// may be unreduced because other implementations use the Euler totient. We
|
||||
// simply check that d * e is one mod p-1 and mod q-1.
|
||||
// simply check that d * e is one mod p-1 and mod q-1. Note d and e were bound
|
||||
// by earlier checks in this function.
|
||||
if (!bn_usub_consttime(&pm1, key->p, BN_value_one()) ||
|
||||
!bn_usub_consttime(&qm1, key->q, BN_value_one()) ||
|
||||
!bn_mul_consttime(&de, key->d, key->e, ctx) ||
|
||||
|
||||
@@ -73,7 +73,12 @@
|
||||
#include "../rand/fork_detect.h"
|
||||
|
||||
|
||||
static int check_modulus_and_exponent_sizes(const RSA *rsa) {
|
||||
int rsa_check_public_key(const RSA *rsa) {
|
||||
if (rsa->n == NULL || rsa->e == NULL) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_VALUE_MISSING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned rsa_bits = BN_num_bits(rsa->n);
|
||||
|
||||
if (rsa_bits > 16 * 1024) {
|
||||
@@ -253,8 +258,7 @@ size_t rsa_default_size(const RSA *rsa) {
|
||||
|
||||
int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
if (rsa->n == NULL || rsa->e == NULL) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_VALUE_MISSING);
|
||||
if (!rsa_check_public_key(rsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -269,10 +273,6 @@ int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!check_modulus_and_exponent_sizes(rsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
@@ -592,8 +592,7 @@ static int mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
|
||||
|
||||
int RSA_verify_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
if (rsa->n == NULL || rsa->e == NULL) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_VALUE_MISSING);
|
||||
if (!rsa_check_public_key(rsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -610,10 +609,6 @@ int RSA_verify_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!check_modulus_and_exponent_sizes(rsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
@@ -1121,8 +1116,8 @@ static int rsa_generate_key_impl(RSA *rsa, int bits, const BIGNUM *e_value,
|
||||
|
||||
// Reject excessively large public exponents. Windows CryptoAPI and Go don't
|
||||
// support values larger than 32 bits, so match their limits for generating
|
||||
// keys. (|check_modulus_and_exponent_sizes| uses a slightly more conservative
|
||||
// value, but we don't need to support generating such keys.)
|
||||
// keys. (|rsa_check_public_key| uses a slightly more conservative value, but
|
||||
// we don't need to support generating such keys.)
|
||||
// https://github.com/golang/go/issues/3161
|
||||
// https://msdn.microsoft.com/en-us/library/aa387685(VS.85).aspx
|
||||
if (BN_num_bits(e_value) > 32) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_ecdsa.h>
|
||||
#include <CCryptoBoringSSL_ec_key.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
@@ -430,11 +431,44 @@ int boringssl_fips_self_test(
|
||||
0xba, 0x4d, 0xd9, 0x86, 0x77, 0xda, 0x7d, 0x8f, 0xef, 0xc4, 0x1a,
|
||||
0xf0, 0xcc, 0x81, 0xe5, 0xea, 0x3f, 0xc2, 0x41, 0x7f, 0xd8,
|
||||
};
|
||||
// kP256Point is SHA256("Primitive Z Computation KAT")×G within P-256.
|
||||
const uint8_t kP256Point[65] = {
|
||||
0x04, 0x4e, 0xc1, 0x94, 0x8c, 0x5c, 0xf4, 0x37, 0x35, 0x0d, 0xa3,
|
||||
0xf9, 0x55, 0xf9, 0x8b, 0x26, 0x23, 0x5c, 0x43, 0xe0, 0x83, 0x51,
|
||||
0x2b, 0x0d, 0x4b, 0x56, 0x24, 0xc3, 0xe4, 0xa5, 0xa8, 0xe2, 0xe9,
|
||||
0x95, 0xf2, 0xc4, 0xb9, 0xb7, 0x48, 0x7d, 0x2a, 0xae, 0xc5, 0xc0,
|
||||
0x0a, 0xcc, 0x1b, 0xd0, 0xec, 0xb8, 0xdc, 0xbe, 0x0c, 0xbe, 0x52,
|
||||
0x79, 0x93, 0x7c, 0x0b, 0x92, 0x2b, 0x7f, 0x17, 0xa5, 0x80,
|
||||
};
|
||||
// kP256Scalar is SHA256("Primitive Z Computation KAT scalar").
|
||||
const uint8_t kP256Scalar[32] = {
|
||||
0xe7, 0x60, 0x44, 0x91, 0x26, 0x9a, 0xfb, 0x5b, 0x10, 0x2d, 0x6e,
|
||||
0xa5, 0x2c, 0xb5, 0x9f, 0xeb, 0x70, 0xae, 0xde, 0x6c, 0xe3, 0xbf,
|
||||
0xb3, 0xe0, 0x10, 0x54, 0x85, 0xab, 0xd8, 0x61, 0xd7, 0x7b,
|
||||
};
|
||||
// kP256PointResult is |kP256Scalar|×|kP256Point|.
|
||||
const uint8_t kP256PointResult[65] = {
|
||||
0x04, 0xf1, 0x63, 0x00, 0x88, 0xc5, 0xd5, 0xe9, 0x05, 0x52, 0xac,
|
||||
0xb6, 0xec, 0x68, 0x76, 0xb8, 0x73, 0x7f, 0x0f, 0x72, 0x34, 0xe6,
|
||||
0xbb, 0x30, 0x32, 0x22, 0x37, 0xb6, 0x2a, 0x80, 0xe8, 0x9e, 0x6e,
|
||||
0x6f, 0x36, 0x02, 0xe7, 0x21, 0xd2, 0x31, 0xdb, 0x94, 0x63, 0xb7,
|
||||
0xd8, 0x19, 0x0e, 0xc2, 0xc0, 0xa7, 0x2f, 0x15, 0x49, 0x1a, 0xa2,
|
||||
0x7c, 0x41, 0x8f, 0xaf, 0x9c, 0x40, 0xaf, 0x2e, 0x4a,
|
||||
#if !defined(BORINGSSL_FIPS_BREAK_Z_COMPUTATION)
|
||||
0x0c,
|
||||
#else
|
||||
0x00,
|
||||
#endif
|
||||
};
|
||||
|
||||
EVP_AEAD_CTX aead_ctx;
|
||||
EVP_AEAD_CTX_zero(&aead_ctx);
|
||||
RSA *rsa_key = NULL;
|
||||
EC_KEY *ec_key = NULL;
|
||||
EC_GROUP *ec_group = NULL;
|
||||
EC_POINT *ec_point_in = NULL;
|
||||
EC_POINT *ec_point_out = NULL;
|
||||
BIGNUM *ec_scalar = NULL;
|
||||
ECDSA_SIG *sig = NULL;
|
||||
int ret = 0;
|
||||
|
||||
@@ -602,6 +636,30 @@ int boringssl_fips_self_test(
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Primitive Z Computation KAT (IG 9.6).
|
||||
ec_group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
|
||||
if (ec_group == NULL) {
|
||||
fprintf(stderr, "Failed to create P-256 group.\n");
|
||||
goto err;
|
||||
}
|
||||
ec_point_in = EC_POINT_new(ec_group);
|
||||
ec_point_out = EC_POINT_new(ec_group);
|
||||
ec_scalar = BN_new();
|
||||
uint8_t z_comp_result[65];
|
||||
if (ec_point_in == NULL || ec_point_out == NULL || ec_scalar == NULL ||
|
||||
!EC_POINT_oct2point(ec_group, ec_point_in, kP256Point, sizeof(kP256Point),
|
||||
NULL) ||
|
||||
!BN_bin2bn(kP256Scalar, sizeof(kP256Scalar), ec_scalar) ||
|
||||
!EC_POINT_mul(ec_group, ec_point_out, NULL, ec_point_in, ec_scalar,
|
||||
NULL) ||
|
||||
!EC_POINT_point2oct(ec_group, ec_point_out, POINT_CONVERSION_UNCOMPRESSED,
|
||||
z_comp_result, sizeof(z_comp_result), NULL) ||
|
||||
!check_test(kP256PointResult, z_comp_result, sizeof(z_comp_result),
|
||||
"Z Computation Result")) {
|
||||
fprintf(stderr, "Z Computation KAT failed.\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
// DBRG KAT
|
||||
CTR_DRBG_STATE drbg;
|
||||
if (!CTR_DRBG_init(&drbg, kDRBGEntropy, kDRBGPersonalization,
|
||||
@@ -642,6 +700,10 @@ err:
|
||||
EVP_AEAD_CTX_cleanup(&aead_ctx);
|
||||
RSA_free(rsa_key);
|
||||
EC_KEY_free(ec_key);
|
||||
EC_POINT_free(ec_point_in);
|
||||
EC_POINT_free(ec_point_out);
|
||||
EC_GROUP_free(ec_group);
|
||||
BN_free(ec_scalar);
|
||||
ECDSA_SIG_free(sig);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
.align 6
|
||||
_sha1_block_data_order:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x16,:pg_hi21_nc:_OPENSSL_armcap_P
|
||||
#else
|
||||
@@ -1091,6 +1093,8 @@ Loop:
|
||||
|
||||
.align 6
|
||||
sha1_block_armv8:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
Lv8_entry:
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
.type sha1_block_data_order,%function
|
||||
.align 6
|
||||
sha1_block_data_order:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x16,:pg_hi21_nc:OPENSSL_armcap_P
|
||||
#else
|
||||
@@ -1092,6 +1094,8 @@ sha1_block_data_order:
|
||||
.type sha1_block_armv8,%function
|
||||
.align 6
|
||||
sha1_block_armv8:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
.Lv8_entry:
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -29,6 +29,8 @@ sha1_block_data_order:
|
||||
movl 8(%r10),%r10d
|
||||
testl $512,%r8d
|
||||
jz .Lialu
|
||||
testl $536870912,%r10d
|
||||
jnz _shaext_shortcut
|
||||
andl $296,%r10d
|
||||
cmpl $296,%r10d
|
||||
je _avx2_shortcut
|
||||
@@ -1271,6 +1273,175 @@ sha1_block_data_order:
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size sha1_block_data_order,.-sha1_block_data_order
|
||||
.type sha1_block_data_order_shaext,@function
|
||||
.align 32
|
||||
sha1_block_data_order_shaext:
|
||||
_shaext_shortcut:
|
||||
.cfi_startproc
|
||||
movdqu (%rdi),%xmm0
|
||||
movd 16(%rdi),%xmm1
|
||||
movdqa K_XX_XX+160(%rip),%xmm3
|
||||
|
||||
movdqu (%rsi),%xmm4
|
||||
pshufd $27,%xmm0,%xmm0
|
||||
movdqu 16(%rsi),%xmm5
|
||||
pshufd $27,%xmm1,%xmm1
|
||||
movdqu 32(%rsi),%xmm6
|
||||
.byte 102,15,56,0,227
|
||||
movdqu 48(%rsi),%xmm7
|
||||
.byte 102,15,56,0,235
|
||||
.byte 102,15,56,0,243
|
||||
movdqa %xmm1,%xmm9
|
||||
.byte 102,15,56,0,251
|
||||
jmp .Loop_shaext
|
||||
|
||||
.align 16
|
||||
.Loop_shaext:
|
||||
decq %rdx
|
||||
leaq 64(%rsi),%r8
|
||||
paddd %xmm4,%xmm1
|
||||
cmovneq %r8,%rsi
|
||||
movdqa %xmm0,%xmm8
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,0
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,0
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,0
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,0
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,0
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,1
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,1
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,1
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,1
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,1
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,2
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,2
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,2
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,2
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,2
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,3
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
movdqu (%rsi),%xmm4
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,3
|
||||
.byte 15,56,200,213
|
||||
movdqu 16(%rsi),%xmm5
|
||||
.byte 102,15,56,0,227
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,3
|
||||
.byte 15,56,200,206
|
||||
movdqu 32(%rsi),%xmm6
|
||||
.byte 102,15,56,0,235
|
||||
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,3
|
||||
.byte 15,56,200,215
|
||||
movdqu 48(%rsi),%xmm7
|
||||
.byte 102,15,56,0,243
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,3
|
||||
.byte 65,15,56,200,201
|
||||
.byte 102,15,56,0,251
|
||||
|
||||
paddd %xmm8,%xmm0
|
||||
movdqa %xmm1,%xmm9
|
||||
|
||||
jnz .Loop_shaext
|
||||
|
||||
pshufd $27,%xmm0,%xmm0
|
||||
pshufd $27,%xmm1,%xmm1
|
||||
movdqu %xmm0,(%rdi)
|
||||
movd %xmm1,16(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size sha1_block_data_order_shaext,.-sha1_block_data_order_shaext
|
||||
.type sha1_block_data_order_ssse3,@function
|
||||
.align 16
|
||||
sha1_block_data_order_ssse3:
|
||||
|
||||
@@ -28,6 +28,8 @@ _sha1_block_data_order:
|
||||
movl 8(%r10),%r10d
|
||||
testl $512,%r8d
|
||||
jz L$ialu
|
||||
testl $536870912,%r10d
|
||||
jnz _shaext_shortcut
|
||||
andl $296,%r10d
|
||||
cmpl $296,%r10d
|
||||
je _avx2_shortcut
|
||||
@@ -1271,6 +1273,175 @@ L$epilogue:
|
||||
|
||||
|
||||
|
||||
.p2align 5
|
||||
sha1_block_data_order_shaext:
|
||||
_shaext_shortcut:
|
||||
|
||||
movdqu (%rdi),%xmm0
|
||||
movd 16(%rdi),%xmm1
|
||||
movdqa K_XX_XX+160(%rip),%xmm3
|
||||
|
||||
movdqu (%rsi),%xmm4
|
||||
pshufd $27,%xmm0,%xmm0
|
||||
movdqu 16(%rsi),%xmm5
|
||||
pshufd $27,%xmm1,%xmm1
|
||||
movdqu 32(%rsi),%xmm6
|
||||
.byte 102,15,56,0,227
|
||||
movdqu 48(%rsi),%xmm7
|
||||
.byte 102,15,56,0,235
|
||||
.byte 102,15,56,0,243
|
||||
movdqa %xmm1,%xmm9
|
||||
.byte 102,15,56,0,251
|
||||
jmp L$oop_shaext
|
||||
|
||||
.p2align 4
|
||||
L$oop_shaext:
|
||||
decq %rdx
|
||||
leaq 64(%rsi),%r8
|
||||
paddd %xmm4,%xmm1
|
||||
cmovneq %r8,%rsi
|
||||
movdqa %xmm0,%xmm8
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,0
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,0
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,0
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,0
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,0
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,1
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,1
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,1
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,1
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,1
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,2
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,2
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
.byte 15,56,201,229
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,2
|
||||
.byte 15,56,200,213
|
||||
pxor %xmm6,%xmm4
|
||||
.byte 15,56,201,238
|
||||
.byte 15,56,202,231
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,2
|
||||
.byte 15,56,200,206
|
||||
pxor %xmm7,%xmm5
|
||||
.byte 15,56,202,236
|
||||
.byte 15,56,201,247
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,2
|
||||
.byte 15,56,200,215
|
||||
pxor %xmm4,%xmm6
|
||||
.byte 15,56,201,252
|
||||
.byte 15,56,202,245
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,3
|
||||
.byte 15,56,200,204
|
||||
pxor %xmm5,%xmm7
|
||||
.byte 15,56,202,254
|
||||
movdqu (%rsi),%xmm4
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,3
|
||||
.byte 15,56,200,213
|
||||
movdqu 16(%rsi),%xmm5
|
||||
.byte 102,15,56,0,227
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,3
|
||||
.byte 15,56,200,206
|
||||
movdqu 32(%rsi),%xmm6
|
||||
.byte 102,15,56,0,235
|
||||
|
||||
movdqa %xmm0,%xmm2
|
||||
.byte 15,58,204,193,3
|
||||
.byte 15,56,200,215
|
||||
movdqu 48(%rsi),%xmm7
|
||||
.byte 102,15,56,0,243
|
||||
|
||||
movdqa %xmm0,%xmm1
|
||||
.byte 15,58,204,194,3
|
||||
.byte 65,15,56,200,201
|
||||
.byte 102,15,56,0,251
|
||||
|
||||
paddd %xmm8,%xmm0
|
||||
movdqa %xmm1,%xmm9
|
||||
|
||||
jnz L$oop_shaext
|
||||
|
||||
pshufd $27,%xmm0,%xmm0
|
||||
pshufd $27,%xmm1,%xmm1
|
||||
movdqu %xmm0,(%rdi)
|
||||
movd %xmm1,16(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
sha1_block_data_order_ssse3:
|
||||
_ssse3_shortcut:
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
|
||||
.align 6
|
||||
_sha256_block_data_order:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
#ifndef __KERNEL__
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x16,:pg_hi21_nc:_OPENSSL_armcap_P
|
||||
@@ -75,6 +76,7 @@ _sha256_block_data_order:
|
||||
tst w16,#ARMV8_SHA256
|
||||
b.ne Lv8_entry
|
||||
#endif
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-128]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -1035,6 +1037,7 @@ Loop_16_xx:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#128
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
@@ -1069,6 +1072,7 @@ LK256:
|
||||
.align 6
|
||||
sha256_block_armv8:
|
||||
Lv8_entry:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
.type sha256_block_data_order,%function
|
||||
.align 6
|
||||
sha256_block_data_order:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
#ifndef __KERNEL__
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x16,:pg_hi21_nc:OPENSSL_armcap_P
|
||||
@@ -76,6 +77,7 @@ sha256_block_data_order:
|
||||
tst w16,#ARMV8_SHA256
|
||||
b.ne .Lv8_entry
|
||||
#endif
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-128]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -1036,6 +1038,7 @@ sha256_block_data_order:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#128
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size sha256_block_data_order,.-sha256_block_data_order
|
||||
|
||||
@@ -1070,6 +1073,7 @@ sha256_block_data_order:
|
||||
.align 6
|
||||
sha256_block_armv8:
|
||||
.Lv8_entry:
|
||||
// Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later.
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
|
||||
.align 6
|
||||
_sha512_block_data_order:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-128]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -1025,6 +1026,7 @@ Loop_16_xx:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#128
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
.type sha512_block_data_order,%function
|
||||
.align 6
|
||||
sha512_block_data_order:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-128]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -1026,6 +1027,7 @@ sha512_block_data_order:
|
||||
ldp x25,x26,[x29,#64]
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#128
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size sha512_block_data_order,.-sha512_block_data_order
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
.section __TEXT,__const
|
||||
|
||||
|
||||
@@ -216,6 +218,7 @@ Lenc_entry:
|
||||
|
||||
.align 4
|
||||
_vpaes_encrypt:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -225,6 +228,7 @@ _vpaes_encrypt:
|
||||
st1 {v0.16b}, [x1]
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
@@ -453,6 +457,7 @@ Ldec_entry:
|
||||
|
||||
.align 4
|
||||
_vpaes_decrypt:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -462,6 +467,7 @@ _vpaes_decrypt:
|
||||
st1 {v0.16b}, [x1]
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
@@ -631,6 +637,7 @@ _vpaes_key_preheat:
|
||||
|
||||
.align 4
|
||||
_vpaes_schedule_core:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29, x30, [sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -800,6 +807,7 @@ Lschedule_mangle_last_dec:
|
||||
eor v6.16b, v6.16b, v6.16b // vpxor %xmm6, %xmm6, %xmm6
|
||||
eor v7.16b, v7.16b, v7.16b // vpxor %xmm7, %xmm7, %xmm7
|
||||
ldp x29, x30, [sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
@@ -1013,6 +1021,7 @@ Lschedule_mangle_both:
|
||||
|
||||
.align 4
|
||||
_vpaes_set_encrypt_key:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1028,6 +1037,7 @@ _vpaes_set_encrypt_key:
|
||||
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
@@ -1036,6 +1046,7 @@ _vpaes_set_encrypt_key:
|
||||
|
||||
.align 4
|
||||
_vpaes_set_decrypt_key:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1055,6 +1066,7 @@ _vpaes_set_decrypt_key:
|
||||
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
.globl _vpaes_cbc_encrypt
|
||||
@@ -1062,6 +1074,7 @@ _vpaes_set_decrypt_key:
|
||||
|
||||
.align 4
|
||||
_vpaes_cbc_encrypt:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
cbz x2, Lcbc_abort
|
||||
cmp w5, #0 // check direction
|
||||
b.eq vpaes_cbc_decrypt
|
||||
@@ -1088,6 +1101,7 @@ Lcbc_enc_loop:
|
||||
st1 {v0.16b}, [x4] // write ivec
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
Lcbc_abort:
|
||||
ret
|
||||
|
||||
@@ -1095,6 +1109,8 @@ Lcbc_abort:
|
||||
|
||||
.align 4
|
||||
vpaes_cbc_decrypt:
|
||||
// Not adding AARCH64_SIGN_LINK_REGISTER here because vpaes_cbc_decrypt is jumped to
|
||||
// only from vpaes_cbc_encrypt which has already signed the return address.
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1136,6 +1152,7 @@ Lcbc_dec_done:
|
||||
ldp d10,d11,[sp],#16
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
.globl _vpaes_ctr32_encrypt_blocks
|
||||
@@ -1143,6 +1160,7 @@ Lcbc_dec_done:
|
||||
|
||||
.align 4
|
||||
_vpaes_ctr32_encrypt_blocks:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1210,6 +1228,7 @@ Lctr32_done:
|
||||
ldp d10,d11,[sp],#16
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
.section .rodata
|
||||
|
||||
.type _vpaes_consts,%object
|
||||
@@ -217,6 +219,7 @@ _vpaes_encrypt_core:
|
||||
.type vpaes_encrypt,%function
|
||||
.align 4
|
||||
vpaes_encrypt:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -226,6 +229,7 @@ vpaes_encrypt:
|
||||
st1 {v0.16b}, [x1]
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_encrypt,.-vpaes_encrypt
|
||||
|
||||
@@ -454,6 +458,7 @@ _vpaes_decrypt_core:
|
||||
.type vpaes_decrypt,%function
|
||||
.align 4
|
||||
vpaes_decrypt:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -463,6 +468,7 @@ vpaes_decrypt:
|
||||
st1 {v0.16b}, [x1]
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_decrypt,.-vpaes_decrypt
|
||||
|
||||
@@ -632,6 +638,7 @@ _vpaes_key_preheat:
|
||||
.type _vpaes_schedule_core,%function
|
||||
.align 4
|
||||
_vpaes_schedule_core:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29, x30, [sp,#-16]!
|
||||
add x29,sp,#0
|
||||
|
||||
@@ -801,6 +808,7 @@ _vpaes_schedule_core:
|
||||
eor v6.16b, v6.16b, v6.16b // vpxor %xmm6, %xmm6, %xmm6
|
||||
eor v7.16b, v7.16b, v7.16b // vpxor %xmm7, %xmm7, %xmm7
|
||||
ldp x29, x30, [sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size _vpaes_schedule_core,.-_vpaes_schedule_core
|
||||
|
||||
@@ -1014,6 +1022,7 @@ _vpaes_schedule_mangle:
|
||||
.type vpaes_set_encrypt_key,%function
|
||||
.align 4
|
||||
vpaes_set_encrypt_key:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1029,6 +1038,7 @@ vpaes_set_encrypt_key:
|
||||
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_set_encrypt_key,.-vpaes_set_encrypt_key
|
||||
|
||||
@@ -1037,6 +1047,7 @@ vpaes_set_encrypt_key:
|
||||
.type vpaes_set_decrypt_key,%function
|
||||
.align 4
|
||||
vpaes_set_decrypt_key:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1056,6 +1067,7 @@ vpaes_set_decrypt_key:
|
||||
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_set_decrypt_key,.-vpaes_set_decrypt_key
|
||||
.globl vpaes_cbc_encrypt
|
||||
@@ -1063,6 +1075,7 @@ vpaes_set_decrypt_key:
|
||||
.type vpaes_cbc_encrypt,%function
|
||||
.align 4
|
||||
vpaes_cbc_encrypt:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
cbz x2, .Lcbc_abort
|
||||
cmp w5, #0 // check direction
|
||||
b.eq vpaes_cbc_decrypt
|
||||
@@ -1089,6 +1102,7 @@ vpaes_cbc_encrypt:
|
||||
st1 {v0.16b}, [x4] // write ivec
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
.Lcbc_abort:
|
||||
ret
|
||||
.size vpaes_cbc_encrypt,.-vpaes_cbc_encrypt
|
||||
@@ -1096,6 +1110,8 @@ vpaes_cbc_encrypt:
|
||||
.type vpaes_cbc_decrypt,%function
|
||||
.align 4
|
||||
vpaes_cbc_decrypt:
|
||||
// Not adding AARCH64_SIGN_LINK_REGISTER here because vpaes_cbc_decrypt is jumped to
|
||||
// only from vpaes_cbc_encrypt which has already signed the return address.
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1137,6 +1153,7 @@ vpaes_cbc_decrypt:
|
||||
ldp d10,d11,[sp],#16
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_cbc_decrypt,.-vpaes_cbc_decrypt
|
||||
.globl vpaes_ctr32_encrypt_blocks
|
||||
@@ -1144,6 +1161,7 @@ vpaes_cbc_decrypt:
|
||||
.type vpaes_ctr32_encrypt_blocks,%function
|
||||
.align 4
|
||||
vpaes_ctr32_encrypt_blocks:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-16]!
|
||||
add x29,sp,#0
|
||||
stp d8,d9,[sp,#-16]! // ABI spec says so
|
||||
@@ -1211,6 +1229,7 @@ vpaes_ctr32_encrypt_blocks:
|
||||
ldp d10,d11,[sp],#16
|
||||
ldp d8,d9,[sp],#16
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_ctr32_encrypt_blocks,.-vpaes_ctr32_encrypt_blocks
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,543 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_evp.h>
|
||||
#include <CCryptoBoringSSL_hkdf.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// This file implements draft-irtf-cfrg-hpke-05.
|
||||
|
||||
#define KEM_CONTEXT_LEN (2 * X25519_PUBLIC_VALUE_LEN)
|
||||
|
||||
// HPKE KEM scheme IDs.
|
||||
#define HPKE_DHKEM_X25519_HKDF_SHA256 0x0020
|
||||
|
||||
// This is strlen("HPKE") + 3 * sizeof(uint16_t).
|
||||
#define HPKE_SUITE_ID_LEN 10
|
||||
|
||||
#define HPKE_MODE_BASE 0
|
||||
#define HPKE_MODE_PSK 1
|
||||
|
||||
static const char kHpkeRfcId[] = "HPKE-05 ";
|
||||
|
||||
static int add_label_string(CBB *cbb, const char *label) {
|
||||
return CBB_add_bytes(cbb, (const uint8_t *)label, strlen(label));
|
||||
}
|
||||
|
||||
// The suite_id for the KEM is defined as concat("KEM", I2OSP(kem_id, 2)). Note
|
||||
// that the suite_id used outside of the KEM also includes the kdf_id and
|
||||
// aead_id.
|
||||
static const uint8_t kX25519SuiteID[] = {
|
||||
'K', 'E', 'M', HPKE_DHKEM_X25519_HKDF_SHA256 >> 8,
|
||||
HPKE_DHKEM_X25519_HKDF_SHA256 & 0x00ff};
|
||||
|
||||
// The suite_id for non-KEM pieces of HPKE is defined as concat("HPKE",
|
||||
// I2OSP(kem_id, 2), I2OSP(kdf_id, 2), I2OSP(aead_id, 2)).
|
||||
static int hpke_build_suite_id(uint8_t out[HPKE_SUITE_ID_LEN], uint16_t kdf_id,
|
||||
uint16_t aead_id) {
|
||||
CBB cbb;
|
||||
int ret = CBB_init_fixed(&cbb, out, HPKE_SUITE_ID_LEN) &&
|
||||
add_label_string(&cbb, "HPKE") &&
|
||||
CBB_add_u16(&cbb, HPKE_DHKEM_X25519_HKDF_SHA256) &&
|
||||
CBB_add_u16(&cbb, kdf_id) &&
|
||||
CBB_add_u16(&cbb, aead_id);
|
||||
CBB_cleanup(&cbb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int hpke_labeled_extract(const EVP_MD *hkdf_md, uint8_t *out_key,
|
||||
size_t *out_len, const uint8_t *salt,
|
||||
size_t salt_len, const uint8_t *suite_id,
|
||||
size_t suite_id_len, const char *label,
|
||||
const uint8_t *ikm, size_t ikm_len) {
|
||||
// labeledIKM = concat("RFCXXXX ", suite_id, label, IKM)
|
||||
CBB labeled_ikm;
|
||||
int ok = CBB_init(&labeled_ikm, 0) &&
|
||||
add_label_string(&labeled_ikm, kHpkeRfcId) &&
|
||||
CBB_add_bytes(&labeled_ikm, suite_id, suite_id_len) &&
|
||||
add_label_string(&labeled_ikm, label) &&
|
||||
CBB_add_bytes(&labeled_ikm, ikm, ikm_len) &&
|
||||
HKDF_extract(out_key, out_len, hkdf_md, CBB_data(&labeled_ikm),
|
||||
CBB_len(&labeled_ikm), salt, salt_len);
|
||||
CBB_cleanup(&labeled_ikm);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int hpke_labeled_expand(const EVP_MD *hkdf_md, uint8_t *out_key,
|
||||
size_t out_len, const uint8_t *prk,
|
||||
size_t prk_len, const uint8_t *suite_id,
|
||||
size_t suite_id_len, const char *label,
|
||||
const uint8_t *info, size_t info_len) {
|
||||
// labeledInfo = concat(I2OSP(L, 2), "RFCXXXX ", suite_id, label, info)
|
||||
CBB labeled_info;
|
||||
int ok = CBB_init(&labeled_info, 0) &&
|
||||
CBB_add_u16(&labeled_info, out_len) &&
|
||||
add_label_string(&labeled_info, kHpkeRfcId) &&
|
||||
CBB_add_bytes(&labeled_info, suite_id, suite_id_len) &&
|
||||
add_label_string(&labeled_info, label) &&
|
||||
CBB_add_bytes(&labeled_info, info, info_len) &&
|
||||
HKDF_expand(out_key, out_len, hkdf_md, prk, prk_len,
|
||||
CBB_data(&labeled_info), CBB_len(&labeled_info));
|
||||
CBB_cleanup(&labeled_info);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int hpke_extract_and_expand(const EVP_MD *hkdf_md, uint8_t *out_key,
|
||||
size_t out_len,
|
||||
const uint8_t dh[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t kem_context[KEM_CONTEXT_LEN]) {
|
||||
uint8_t prk[EVP_MAX_MD_SIZE];
|
||||
size_t prk_len;
|
||||
static const char kEaePrkLabel[] = "eae_prk";
|
||||
if (!hpke_labeled_extract(hkdf_md, prk, &prk_len, NULL, 0, kX25519SuiteID,
|
||||
sizeof(kX25519SuiteID), kEaePrkLabel, dh,
|
||||
X25519_PUBLIC_VALUE_LEN)) {
|
||||
return 0;
|
||||
}
|
||||
static const char kPRKExpandLabel[] = "shared_secret";
|
||||
if (!hpke_labeled_expand(hkdf_md, out_key, out_len, prk, prk_len,
|
||||
kX25519SuiteID, sizeof(kX25519SuiteID),
|
||||
kPRKExpandLabel, kem_context, KEM_CONTEXT_LEN)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD *hpke_get_aead(uint16_t aead_id) {
|
||||
switch (aead_id) {
|
||||
case EVP_HPKE_AEAD_AES_GCM_128:
|
||||
return EVP_aead_aes_128_gcm();
|
||||
case EVP_HPKE_AEAD_AES_GCM_256:
|
||||
return EVP_aead_aes_256_gcm();
|
||||
case EVP_HPKE_AEAD_CHACHA20POLY1305:
|
||||
return EVP_aead_chacha20_poly1305();
|
||||
}
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_INTERNAL_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const EVP_MD *hpke_get_kdf(uint16_t kdf_id) {
|
||||
switch (kdf_id) {
|
||||
case EVP_HPKE_HKDF_SHA256:
|
||||
return EVP_sha256();
|
||||
case EVP_HPKE_HKDF_SHA384:
|
||||
return EVP_sha384();
|
||||
case EVP_HPKE_HKDF_SHA512:
|
||||
return EVP_sha512();
|
||||
}
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_INTERNAL_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int hpke_key_schedule(EVP_HPKE_CTX *hpke, uint8_t mode,
|
||||
const uint8_t *shared_secret,
|
||||
size_t shared_secret_len, const uint8_t *info,
|
||||
size_t info_len, const uint8_t *psk,
|
||||
size_t psk_len, const uint8_t *psk_id,
|
||||
size_t psk_id_len) {
|
||||
// Verify the PSK inputs.
|
||||
switch (mode) {
|
||||
case HPKE_MODE_BASE:
|
||||
// This is an internal error, unreachable from the caller.
|
||||
assert(psk_len == 0 && psk_id_len == 0);
|
||||
break;
|
||||
case HPKE_MODE_PSK:
|
||||
if (psk_len == 0 || psk_id_len == 0) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EMPTY_PSK);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Attempt to get an EVP_AEAD*.
|
||||
const EVP_AEAD *aead = hpke_get_aead(hpke->aead_id);
|
||||
if (aead == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t suite_id[HPKE_SUITE_ID_LEN];
|
||||
if (!hpke_build_suite_id(suite_id, hpke->kdf_id, hpke->aead_id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// psk_id_hash = LabeledExtract("", "psk_id_hash", psk_id)
|
||||
static const char kPskIdHashLabel[] = "psk_id_hash";
|
||||
uint8_t psk_id_hash[EVP_MAX_MD_SIZE];
|
||||
size_t psk_id_hash_len;
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, psk_id_hash, &psk_id_hash_len, NULL,
|
||||
0, suite_id, sizeof(suite_id), kPskIdHashLabel,
|
||||
psk_id, psk_id_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// info_hash = LabeledExtract("", "info_hash", info)
|
||||
static const char kInfoHashLabel[] = "info_hash";
|
||||
uint8_t info_hash[EVP_MAX_MD_SIZE];
|
||||
size_t info_hash_len;
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, info_hash, &info_hash_len, NULL, 0,
|
||||
suite_id, sizeof(suite_id), kInfoHashLabel, info,
|
||||
info_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// key_schedule_context = concat(mode, psk_id_hash, info_hash)
|
||||
uint8_t context[sizeof(uint8_t) + 2 * EVP_MAX_MD_SIZE];
|
||||
size_t context_len;
|
||||
CBB context_cbb;
|
||||
if (!CBB_init_fixed(&context_cbb, context, sizeof(context)) ||
|
||||
!CBB_add_u8(&context_cbb, mode) ||
|
||||
!CBB_add_bytes(&context_cbb, psk_id_hash, psk_id_hash_len) ||
|
||||
!CBB_add_bytes(&context_cbb, info_hash, info_hash_len) ||
|
||||
!CBB_finish(&context_cbb, NULL, &context_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// psk_hash = LabeledExtract("", "psk_hash", psk)
|
||||
static const char kPskHashLabel[] = "psk_hash";
|
||||
uint8_t psk_hash[EVP_MAX_MD_SIZE];
|
||||
size_t psk_hash_len;
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, psk_hash, &psk_hash_len, NULL, 0,
|
||||
suite_id, sizeof(suite_id), kPskHashLabel, psk,
|
||||
psk_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// secret = LabeledExtract(psk_hash, "secret", shared_secret)
|
||||
static const char kSecretExtractLabel[] = "secret";
|
||||
uint8_t secret[EVP_MAX_MD_SIZE];
|
||||
size_t secret_len;
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, secret, &secret_len, psk_hash,
|
||||
psk_hash_len, suite_id, sizeof(suite_id),
|
||||
kSecretExtractLabel, shared_secret,
|
||||
shared_secret_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// key = LabeledExpand(secret, "key", key_schedule_context, Nk)
|
||||
static const char kKeyExpandLabel[] = "key";
|
||||
uint8_t key[EVP_AEAD_MAX_KEY_LENGTH];
|
||||
const size_t kKeyLen = EVP_AEAD_key_length(aead);
|
||||
if (!hpke_labeled_expand(hpke->hkdf_md, key, kKeyLen, secret, secret_len,
|
||||
suite_id, sizeof(suite_id), kKeyExpandLabel, context,
|
||||
context_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Initialize the HPKE context's AEAD context, storing a copy of |key|.
|
||||
if (!EVP_AEAD_CTX_init(&hpke->aead_ctx, aead, key, kKeyLen, 0, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// nonce = LabeledExpand(secret, "nonce", key_schedule_context, Nn)
|
||||
static const char kNonceExpandLabel[] = "nonce";
|
||||
if (!hpke_labeled_expand(hpke->hkdf_md, hpke->nonce,
|
||||
EVP_AEAD_nonce_length(aead), secret, secret_len,
|
||||
suite_id, sizeof(suite_id), kNonceExpandLabel,
|
||||
context, context_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// exporter_secret = LabeledExpand(secret, "exp", key_schedule_context, Nh)
|
||||
static const char kExporterSecretExpandLabel[] = "exp";
|
||||
if (!hpke_labeled_expand(hpke->hkdf_md, hpke->exporter_secret,
|
||||
EVP_MD_size(hpke->hkdf_md), secret, secret_len,
|
||||
suite_id, sizeof(suite_id),
|
||||
kExporterSecretExpandLabel, context, context_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The number of bytes written to |out_shared_secret| is the size of the KEM's
|
||||
// KDF (currently we only support SHA256).
|
||||
static int hpke_encap(EVP_HPKE_CTX *hpke,
|
||||
uint8_t out_shared_secret[SHA256_DIGEST_LENGTH],
|
||||
const uint8_t public_key_r[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN],
|
||||
const uint8_t ephemeral_public[X25519_PUBLIC_VALUE_LEN]) {
|
||||
uint8_t dh[X25519_PUBLIC_VALUE_LEN];
|
||||
if (!X25519(dh, ephemeral_private, public_key_r)) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_PEER_KEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t kem_context[KEM_CONTEXT_LEN];
|
||||
OPENSSL_memcpy(kem_context, ephemeral_public, X25519_PUBLIC_VALUE_LEN);
|
||||
OPENSSL_memcpy(kem_context + X25519_PUBLIC_VALUE_LEN, public_key_r,
|
||||
X25519_PUBLIC_VALUE_LEN);
|
||||
if (!hpke_extract_and_expand(EVP_sha256(), out_shared_secret,
|
||||
SHA256_DIGEST_LENGTH, dh, kem_context)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int hpke_decap(const EVP_HPKE_CTX *hpke,
|
||||
uint8_t out_shared_secret[SHA256_DIGEST_LENGTH],
|
||||
const uint8_t enc[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t public_key_r[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t secret_key_r[X25519_PRIVATE_KEY_LEN]) {
|
||||
uint8_t dh[X25519_PUBLIC_VALUE_LEN];
|
||||
if (!X25519(dh, secret_key_r, enc)) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_PEER_KEY);
|
||||
return 0;
|
||||
}
|
||||
uint8_t kem_context[KEM_CONTEXT_LEN];
|
||||
OPENSSL_memcpy(kem_context, enc, X25519_PUBLIC_VALUE_LEN);
|
||||
OPENSSL_memcpy(kem_context + X25519_PUBLIC_VALUE_LEN, public_key_r,
|
||||
X25519_PUBLIC_VALUE_LEN);
|
||||
if (!hpke_extract_and_expand(EVP_sha256(), out_shared_secret,
|
||||
SHA256_DIGEST_LENGTH, dh, kem_context)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void EVP_HPKE_CTX_init(EVP_HPKE_CTX *ctx) {
|
||||
OPENSSL_memset(ctx, 0, sizeof(EVP_HPKE_CTX));
|
||||
EVP_AEAD_CTX_zero(&ctx->aead_ctx);
|
||||
}
|
||||
|
||||
void EVP_HPKE_CTX_cleanup(EVP_HPKE_CTX *ctx) {
|
||||
EVP_AEAD_CTX_cleanup(&ctx->aead_ctx);
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_setup_base_s_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint8_t out_enc[X25519_PUBLIC_VALUE_LEN],
|
||||
uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len) {
|
||||
// The GenerateKeyPair() step technically belongs in the KEM's Encap()
|
||||
// function, but we've moved it up a layer to make it easier for tests to
|
||||
// inject an ephemeral keypair.
|
||||
uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN];
|
||||
X25519_keypair(out_enc, ephemeral_private);
|
||||
return EVP_HPKE_CTX_setup_base_s_x25519_for_test(
|
||||
hpke, kdf_id, aead_id, peer_public_value, info, info_len,
|
||||
ephemeral_private, out_enc);
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_setup_base_s_x25519_for_test(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len,
|
||||
const uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN],
|
||||
const uint8_t ephemeral_public[X25519_PUBLIC_VALUE_LEN]) {
|
||||
hpke->is_sender = 1;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t shared_secret[SHA256_DIGEST_LENGTH];
|
||||
if (!hpke_encap(hpke, shared_secret, peer_public_value, ephemeral_private,
|
||||
ephemeral_public) ||
|
||||
!hpke_key_schedule(hpke, HPKE_MODE_BASE, shared_secret,
|
||||
sizeof(shared_secret), info, info_len, NULL, 0, NULL,
|
||||
0)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_setup_base_r_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t enc[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t public_key[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t private_key[X25519_PRIVATE_KEY_LEN], const uint8_t *info,
|
||||
size_t info_len) {
|
||||
hpke->is_sender = 0;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t shared_secret[SHA256_DIGEST_LENGTH];
|
||||
if (!hpke_decap(hpke, shared_secret, enc, public_key, private_key) ||
|
||||
!hpke_key_schedule(hpke, HPKE_MODE_BASE, shared_secret,
|
||||
sizeof(shared_secret), info, info_len, NULL, 0, NULL,
|
||||
0)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_setup_psk_s_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint8_t out_enc[X25519_PUBLIC_VALUE_LEN],
|
||||
uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len,
|
||||
const uint8_t *psk_id, size_t psk_id_len) {
|
||||
// The GenerateKeyPair() step technically belongs in the KEM's Encap()
|
||||
// function, but we've moved it up a layer to make it easier for tests to
|
||||
// inject an ephemeral keypair.
|
||||
uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN];
|
||||
X25519_keypair(out_enc, ephemeral_private);
|
||||
return EVP_HPKE_CTX_setup_psk_s_x25519_for_test(
|
||||
hpke, kdf_id, aead_id, peer_public_value, info, info_len, psk, psk_len,
|
||||
psk_id, psk_id_len, ephemeral_private, out_enc);
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_setup_psk_s_x25519_for_test(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len,
|
||||
const uint8_t *psk_id, size_t psk_id_len,
|
||||
const uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN],
|
||||
const uint8_t ephemeral_public[X25519_PUBLIC_VALUE_LEN]) {
|
||||
hpke->is_sender = 1;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t shared_secret[SHA256_DIGEST_LENGTH];
|
||||
if (!hpke_encap(hpke, shared_secret, peer_public_value, ephemeral_private,
|
||||
ephemeral_public) ||
|
||||
!hpke_key_schedule(hpke, HPKE_MODE_PSK, shared_secret,
|
||||
sizeof(shared_secret), info, info_len, psk, psk_len,
|
||||
psk_id, psk_id_len)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_setup_psk_r_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t enc[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t public_key[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t private_key[X25519_PRIVATE_KEY_LEN], const uint8_t *info,
|
||||
size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id,
|
||||
size_t psk_id_len) {
|
||||
hpke->is_sender = 0;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t shared_secret[SHA256_DIGEST_LENGTH];
|
||||
if (!hpke_decap(hpke, shared_secret, enc, public_key, private_key) ||
|
||||
!hpke_key_schedule(hpke, HPKE_MODE_PSK, shared_secret,
|
||||
sizeof(shared_secret), info, info_len, psk, psk_len,
|
||||
psk_id, psk_id_len)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void hpke_nonce(const EVP_HPKE_CTX *hpke, uint8_t *out_nonce,
|
||||
size_t nonce_len) {
|
||||
assert(nonce_len >= 8);
|
||||
|
||||
// Write padded big-endian bytes of |hpke->seq| to |out_nonce|.
|
||||
OPENSSL_memset(out_nonce, 0, nonce_len);
|
||||
uint64_t seq_copy = hpke->seq;
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
out_nonce[nonce_len - i - 1] = seq_copy & 0xff;
|
||||
seq_copy >>= 8;
|
||||
}
|
||||
|
||||
// XOR the encoded sequence with the |hpke->nonce|.
|
||||
for (size_t i = 0; i < nonce_len; i++) {
|
||||
out_nonce[i] ^= hpke->nonce[i];
|
||||
}
|
||||
}
|
||||
|
||||
size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *hpke) {
|
||||
assert(hpke->is_sender);
|
||||
return EVP_AEAD_max_overhead(hpke->aead_ctx.aead);
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_open(EVP_HPKE_CTX *hpke, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len, const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
if (hpke->is_sender) {
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
if (hpke->seq == UINT64_MAX) {
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t nonce[EVP_AEAD_MAX_NONCE_LENGTH];
|
||||
const size_t nonce_len = EVP_AEAD_nonce_length(hpke->aead_ctx.aead);
|
||||
hpke_nonce(hpke, nonce, nonce_len);
|
||||
|
||||
if (!EVP_AEAD_CTX_open(&hpke->aead_ctx, out, out_len, max_out_len, nonce,
|
||||
nonce_len, in, in_len, ad, ad_len)) {
|
||||
return 0;
|
||||
}
|
||||
hpke->seq++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_seal(EVP_HPKE_CTX *hpke, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len, const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
if (!hpke->is_sender) {
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
if (hpke->seq == UINT64_MAX) {
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t nonce[EVP_AEAD_MAX_NONCE_LENGTH];
|
||||
const size_t nonce_len = EVP_AEAD_nonce_length(hpke->aead_ctx.aead);
|
||||
hpke_nonce(hpke, nonce, nonce_len);
|
||||
|
||||
if (!EVP_AEAD_CTX_seal(&hpke->aead_ctx, out, out_len, max_out_len, nonce,
|
||||
nonce_len, in, in_len, ad, ad_len)) {
|
||||
return 0;
|
||||
}
|
||||
hpke->seq++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_HPKE_CTX_export(const EVP_HPKE_CTX *hpke, uint8_t *out,
|
||||
size_t secret_len, const uint8_t *context,
|
||||
size_t context_len) {
|
||||
uint8_t suite_id[HPKE_SUITE_ID_LEN];
|
||||
if (!hpke_build_suite_id(suite_id, hpke->kdf_id, hpke->aead_id)) {
|
||||
return 0;
|
||||
}
|
||||
static const char kExportExpandLabel[] = "sec";
|
||||
if (!hpke_labeled_expand(hpke->hkdf_md, out, secret_len,
|
||||
hpke->exporter_secret, EVP_MD_size(hpke->hkdf_md),
|
||||
suite_id, sizeof(suite_id), kExportExpandLabel,
|
||||
context, context_len)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_HPKE_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_HPKE_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_curve25519.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Hybrid Public Key Encryption.
|
||||
//
|
||||
// Hybrid Public Key Encryption (HPKE) enables a sender to encrypt messages to a
|
||||
// receiver with a public key. Optionally, the sender may authenticate its
|
||||
// possession of a pre-shared key to the recipient.
|
||||
//
|
||||
// See https://tools.ietf.org/html/draft-irtf-cfrg-hpke-05.
|
||||
|
||||
// EVP_HPKE_AEAD_* are AEAD identifiers.
|
||||
#define EVP_HPKE_AEAD_AES_GCM_128 0x0001
|
||||
#define EVP_HPKE_AEAD_AES_GCM_256 0x0002
|
||||
#define EVP_HPKE_AEAD_CHACHA20POLY1305 0x0003
|
||||
|
||||
// EVP_HPKE_HKDF_* are HKDF identifiers.
|
||||
#define EVP_HPKE_HKDF_SHA256 0x0001
|
||||
#define EVP_HPKE_HKDF_SHA384 0x0002
|
||||
#define EVP_HPKE_HKDF_SHA512 0x0003
|
||||
|
||||
// EVP_HPKE_MAX_OVERHEAD contains the largest value that
|
||||
// |EVP_HPKE_CTX_max_overhead| would ever return for any context.
|
||||
#define EVP_HPKE_MAX_OVERHEAD EVP_AEAD_MAX_OVERHEAD
|
||||
|
||||
|
||||
// Encryption contexts.
|
||||
|
||||
// An |EVP_HPKE_CTX| is an HPKE encryption context.
|
||||
typedef struct evp_hpke_ctx_st {
|
||||
const EVP_MD *hkdf_md;
|
||||
EVP_AEAD_CTX aead_ctx;
|
||||
uint16_t kdf_id;
|
||||
uint16_t aead_id;
|
||||
uint8_t nonce[EVP_AEAD_MAX_NONCE_LENGTH];
|
||||
uint8_t exporter_secret[EVP_MAX_MD_SIZE];
|
||||
uint64_t seq;
|
||||
int is_sender;
|
||||
} EVP_HPKE_CTX;
|
||||
|
||||
// EVP_HPKE_CTX_init initializes an already-allocated |EVP_HPKE_CTX|. The caller
|
||||
// should then use one of the |EVP_HPKE_CTX_setup_*| functions.
|
||||
//
|
||||
// It is safe, but not necessary to call |EVP_HPKE_CTX_cleanup| in this state.
|
||||
OPENSSL_EXPORT void EVP_HPKE_CTX_init(EVP_HPKE_CTX *ctx);
|
||||
|
||||
// EVP_HPKE_CTX_cleanup releases memory referenced by |ctx|. |ctx| must have
|
||||
// been initialized with |EVP_HPKE_CTX_init|.
|
||||
OPENSSL_EXPORT void EVP_HPKE_CTX_cleanup(EVP_HPKE_CTX *ctx);
|
||||
|
||||
|
||||
// Setting up HPKE contexts.
|
||||
//
|
||||
// In each of the following functions, |hpke| must have been initialized with
|
||||
// |EVP_HPKE_CTX_init|. |kdf_id| selects the KDF for non-KEM HPKE operations and
|
||||
// must be one of the |EVP_HPKE_HKDF_*| constants. |aead_id| selects the AEAD
|
||||
// for the "open" and "seal" operations and must be one of the |EVP_HPKE_AEAD_*"
|
||||
// constants."
|
||||
|
||||
// EVP_HPKE_CTX_setup_base_s_x25519 sets up |hpke| as a sender context that can
|
||||
// encrypt for the private key corresponding to |peer_public_value| (the
|
||||
// recipient's public key). It returns one on success, and zero otherwise. Note
|
||||
// that this function will fail if |peer_public_value| is invalid.
|
||||
//
|
||||
// This function writes the encapsulated shared secret to |out_enc|.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_setup_base_s_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint8_t out_enc[X25519_PUBLIC_VALUE_LEN],
|
||||
uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len);
|
||||
|
||||
// EVP_HPKE_CTX_setup_base_s_x25519_for_test behaves like
|
||||
// |EVP_HPKE_CTX_setup_base_s_x25519|, but takes a pre-generated ephemeral
|
||||
// sender key.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_setup_base_s_x25519_for_test(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len,
|
||||
const uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN],
|
||||
const uint8_t ephemeral_public[X25519_PUBLIC_VALUE_LEN]);
|
||||
|
||||
// EVP_HPKE_CTX_setup_base_r_x25519 sets up |hpke| as a recipient context that
|
||||
// can decrypt messages. |private_key| is the recipient's private key, and |enc|
|
||||
// is the encapsulated shared secret from the sender. Note that this function
|
||||
// will fail if |enc| is invalid.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_setup_base_r_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t enc[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t public_key[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t private_key[X25519_PRIVATE_KEY_LEN], const uint8_t *info,
|
||||
size_t info_len);
|
||||
|
||||
// EVP_HPKE_CTX_setup_psk_s_x25519 sets up |hpke| as a sender context that can
|
||||
// encrypt for the private key corresponding to |peer_public_value| (the
|
||||
// recipient's public key) and authenticate its possession of a PSK. It returns
|
||||
// one on success, and zero otherwise. Note that this function will fail if
|
||||
// |peer_public_value| is invalid.
|
||||
//
|
||||
// The PSK and its ID must be provided in |psk| and |psk_id|, respectively. Both
|
||||
// must be nonempty (|psk_len| and |psk_id_len| must be non-zero), or this
|
||||
// function will fail.
|
||||
//
|
||||
// This function writes the encapsulated shared secret to |out_enc|.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_setup_psk_s_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint8_t out_enc[X25519_PUBLIC_VALUE_LEN],
|
||||
uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len,
|
||||
const uint8_t *psk_id, size_t psk_id_len);
|
||||
|
||||
// EVP_HPKE_CTX_setup_psk_s_x25519_for_test behaves like
|
||||
// |EVP_HPKE_CTX_setup_psk_s_x25519|, but takes a pre-generated ephemeral sender
|
||||
// key.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_setup_psk_s_x25519_for_test(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t peer_public_value[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len,
|
||||
const uint8_t *psk_id, size_t psk_id_len,
|
||||
const uint8_t ephemeral_private[X25519_PRIVATE_KEY_LEN],
|
||||
const uint8_t ephemeral_public[X25519_PUBLIC_VALUE_LEN]);
|
||||
|
||||
// EVP_HPKE_CTX_setup_psk_r_x25519 sets up |hpke| as a recipient context that
|
||||
// can decrypt messages. Future open (decrypt) operations will fail if the
|
||||
// sender does not possess the PSK indicated by |psk| and |psk_id|.
|
||||
// |private_key| is the recipient's private key, and |enc| is the encapsulated
|
||||
// shared secret from the sender. If |enc| is invalid, this function will fail.
|
||||
//
|
||||
// The PSK and its ID must be provided in |psk| and |psk_id|, respectively. Both
|
||||
// must be nonempty (|psk_len| and |psk_id_len| must be non-zero), or this
|
||||
// function will fail.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_setup_psk_r_x25519(
|
||||
EVP_HPKE_CTX *hpke, uint16_t kdf_id, uint16_t aead_id,
|
||||
const uint8_t enc[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t public_key[X25519_PUBLIC_VALUE_LEN],
|
||||
const uint8_t private_key[X25519_PRIVATE_KEY_LEN], const uint8_t *info,
|
||||
size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id,
|
||||
size_t psk_id_len);
|
||||
|
||||
|
||||
// Using an HPKE context.
|
||||
|
||||
// EVP_HPKE_CTX_open uses the HPKE context |hpke| to authenticate |in_len| bytes
|
||||
// from |in| and |ad_len| bytes from |ad| and to decrypt at most |in_len| bytes
|
||||
// into |out|. It returns one on success, and zero otherwise.
|
||||
//
|
||||
// This operation will fail if the |hpke| context is not set up as a receiver.
|
||||
//
|
||||
// Note that HPKE encryption is stateful and ordered. The sender's first call to
|
||||
// |EVP_HPKE_CTX_seal| must correspond to the recipient's first call to
|
||||
// |EVP_HPKE_CTX_open|, etc.
|
||||
//
|
||||
// At most |in_len| bytes are written to |out|. In order to ensure success,
|
||||
// |max_out_len| should be at least |in_len|. On successful return, |*out_len|
|
||||
// is set to the actual number of bytes written.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_open(EVP_HPKE_CTX *hpke, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len);
|
||||
|
||||
// EVP_HPKE_CTX_seal uses the HPKE context |hpke| to encrypt and authenticate
|
||||
// |in_len| bytes of ciphertext |in| and authenticate |ad_len| bytes from |ad|,
|
||||
// writing the result to |out|. It returns one on success and zero otherwise.
|
||||
//
|
||||
// This operation will fail if the |hpke| context is not set up as a sender.
|
||||
//
|
||||
// Note that HPKE encryption is stateful and ordered. The sender's first call to
|
||||
// |EVP_HPKE_CTX_seal| must correspond to the recipient's first call to
|
||||
// |EVP_HPKE_CTX_open|, etc.
|
||||
//
|
||||
// At most, |max_out_len| encrypted bytes are written to |out|. On successful
|
||||
// return, |*out_len| is set to the actual number of bytes written.
|
||||
//
|
||||
// To ensure success, |max_out_len| should be |in_len| plus the result of
|
||||
// |EVP_HPKE_CTX_max_overhead| or |EVP_HPKE_MAX_OVERHEAD|.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_seal(EVP_HPKE_CTX *hpke, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len);
|
||||
|
||||
// EVP_HPKE_CTX_export uses the HPKE context |hpke| to export a secret of
|
||||
// |secret_len| bytes into |out|. This function uses |context_len| bytes from
|
||||
// |context| as a context string for the secret. This is necessary to separate
|
||||
// different uses of exported secrets and bind relevant caller-specific context
|
||||
// into the output. It returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int EVP_HPKE_CTX_export(const EVP_HPKE_CTX *hpke, uint8_t *out,
|
||||
size_t secret_len,
|
||||
const uint8_t *context,
|
||||
size_t context_len);
|
||||
|
||||
// EVP_HPKE_CTX_max_overhead returns the maximum number of additional bytes
|
||||
// added by sealing data with |EVP_HPKE_CTX_seal|. The |hpke| context must be
|
||||
// set up as a sender.
|
||||
OPENSSL_EXPORT size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *hpke);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#if !defined(BORINGSSL_NO_CXX)
|
||||
extern "C++" {
|
||||
|
||||
BSSL_NAMESPACE_BEGIN
|
||||
|
||||
using ScopedEVP_HPKE_CTX =
|
||||
internal::StackAllocated<EVP_HPKE_CTX, void, EVP_HPKE_CTX_init,
|
||||
EVP_HPKE_CTX_cleanup>;
|
||||
|
||||
BSSL_NAMESPACE_END
|
||||
|
||||
} // extern C++
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_HPKE_INTERNAL_H
|
||||
@@ -72,6 +72,8 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
|
||||
|
||||
#define OPENSSL_MALLOC_PREFIX 8
|
||||
OPENSSL_STATIC_ASSERT(OPENSSL_MALLOC_PREFIX >= sizeof(size_t),
|
||||
"size_t too large");
|
||||
|
||||
#if defined(OPENSSL_ASAN)
|
||||
void __asan_poison_memory_region(const volatile void *addr, size_t size);
|
||||
@@ -101,13 +103,21 @@ static void __asan_unpoison_memory_region(const void *addr, size_t size) {}
|
||||
// linked. This isn't an ideal result, but its helps in some cases.
|
||||
WEAK_SYMBOL_FUNC(void, sdallocx, (void *ptr, size_t size, int flags));
|
||||
|
||||
// The following two functions are for memory tracking. They are no-ops by
|
||||
// default but can be overridden at link time if the application needs to
|
||||
// observe heap operations.
|
||||
WEAK_SYMBOL_FUNC(void, OPENSSL_track_memory_alloc, (void *ptr, size_t size));
|
||||
WEAK_SYMBOL_FUNC(void, OPENSSL_track_memory_free, (void *ptr, size_t size));
|
||||
// The following three functions can be defined to override default heap
|
||||
// allocation and freeing. If defined, it is the responsibility of
|
||||
// |OPENSSL_memory_free| to zero out the memory before returning it to the
|
||||
// system. |OPENSSL_memory_free| will not be passed NULL pointers.
|
||||
WEAK_SYMBOL_FUNC(void*, OPENSSL_memory_alloc, (size_t size));
|
||||
WEAK_SYMBOL_FUNC(void, OPENSSL_memory_free, (void *ptr));
|
||||
WEAK_SYMBOL_FUNC(size_t, OPENSSL_memory_get_size, (void *ptr));
|
||||
|
||||
void *OPENSSL_malloc(size_t size) {
|
||||
if (OPENSSL_memory_alloc != NULL) {
|
||||
assert(OPENSSL_memory_free != NULL);
|
||||
assert(OPENSSL_memory_get_size != NULL);
|
||||
return OPENSSL_memory_alloc(size);
|
||||
}
|
||||
|
||||
if (size + OPENSSL_MALLOC_PREFIX < size) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -120,9 +130,6 @@ void *OPENSSL_malloc(size_t size) {
|
||||
*(size_t *)ptr = size;
|
||||
|
||||
__asan_poison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
if (OPENSSL_track_memory_alloc) {
|
||||
OPENSSL_track_memory_alloc(ptr, size + OPENSSL_MALLOC_PREFIX);
|
||||
}
|
||||
return ((uint8_t *)ptr) + OPENSSL_MALLOC_PREFIX;
|
||||
}
|
||||
|
||||
@@ -131,13 +138,15 @@ void OPENSSL_free(void *orig_ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (OPENSSL_memory_free != NULL) {
|
||||
OPENSSL_memory_free(orig_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
void *ptr = ((uint8_t *)orig_ptr) - OPENSSL_MALLOC_PREFIX;
|
||||
__asan_unpoison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
|
||||
size_t size = *(size_t *)ptr;
|
||||
if (OPENSSL_track_memory_free) {
|
||||
OPENSSL_track_memory_free(ptr, size + OPENSSL_MALLOC_PREFIX);
|
||||
}
|
||||
OPENSSL_cleanse(ptr, size + OPENSSL_MALLOC_PREFIX);
|
||||
if (sdallocx) {
|
||||
sdallocx(ptr, size + OPENSSL_MALLOC_PREFIX, 0 /* flags */);
|
||||
@@ -151,10 +160,15 @@ void *OPENSSL_realloc(void *orig_ptr, size_t new_size) {
|
||||
return OPENSSL_malloc(new_size);
|
||||
}
|
||||
|
||||
void *ptr = ((uint8_t *)orig_ptr) - OPENSSL_MALLOC_PREFIX;
|
||||
__asan_unpoison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
size_t old_size = *(size_t *)ptr;
|
||||
__asan_poison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
size_t old_size;
|
||||
if (OPENSSL_memory_get_size != NULL) {
|
||||
old_size = OPENSSL_memory_get_size(orig_ptr);
|
||||
} else {
|
||||
void *ptr = ((uint8_t *)orig_ptr) - OPENSSL_MALLOC_PREFIX;
|
||||
__asan_unpoison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
old_size = *(size_t *)ptr;
|
||||
__asan_poison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
}
|
||||
|
||||
void *ret = OPENSSL_malloc(new_size);
|
||||
if (ret == NULL) {
|
||||
|
||||
@@ -63,6 +63,13 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct pkcs8_priv_key_info_st {
|
||||
ASN1_INTEGER *version;
|
||||
X509_ALGOR *pkeyalg;
|
||||
ASN1_OCTET_STRING *pkey;
|
||||
STACK_OF(X509_ATTRIBUTE) *attributes;
|
||||
};
|
||||
|
||||
// pkcs8_pbe_decrypt decrypts |in| using the PBE scheme described by
|
||||
// |algorithm|, which should be a serialized AlgorithmIdentifier structure. On
|
||||
// success, it sets |*out| to a newly-allocated buffer containing the decrypted
|
||||
|
||||
@@ -96,10 +96,8 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
// Since the structure must still be valid use ASN1_OP_FREE_PRE
|
||||
if (operation == ASN1_OP_FREE_PRE) {
|
||||
PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
|
||||
if (key->pkey && key->pkey->type == V_ASN1_OCTET_STRING &&
|
||||
key->pkey->value.octet_string) {
|
||||
OPENSSL_cleanse(key->pkey->value.octet_string->data,
|
||||
key->pkey->value.octet_string->length);
|
||||
if (key->pkey) {
|
||||
OPENSSL_cleanse(key->pkey->data, key->pkey->length);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@@ -108,12 +106,45 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = {
|
||||
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR),
|
||||
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY),
|
||||
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_OCTET_STRING),
|
||||
ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0)
|
||||
} ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
|
||||
|
||||
int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version,
|
||||
int ptype, void *pval, uint8_t *penc, int penclen) {
|
||||
if (version >= 0 &&
|
||||
!ASN1_INTEGER_set(priv->version, version)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (penc != NULL) {
|
||||
ASN1_STRING_set0(priv->pkey, penc, penclen);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, const uint8_t **pk, int *ppklen,
|
||||
X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8) {
|
||||
if (ppkalg) {
|
||||
*ppkalg = p8->pkeyalg->algorithm;
|
||||
}
|
||||
if (pk) {
|
||||
*pk = ASN1_STRING_data(p8->pkey);
|
||||
*ppklen = ASN1_STRING_length(p8->pkey);
|
||||
}
|
||||
if (pa) {
|
||||
*pa = p8->pkeyalg;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) {
|
||||
uint8_t *der = NULL;
|
||||
int der_len = i2d_PKCS8_PRIV_KEY_INFO(p8, &der);
|
||||
|
||||
@@ -77,27 +77,6 @@ OPENSSL_EXPORT void PMBTOKEN_PRETOKEN_free(PMBTOKEN_PRETOKEN *token);
|
||||
|
||||
DEFINE_STACK_OF(PMBTOKEN_PRETOKEN)
|
||||
|
||||
// The following functions implement the corresponding |TRUST_TOKENS_METHOD|
|
||||
// functions for |TRUST_TOKENS_experiment_v0|'s PMBTokens construction which
|
||||
// uses P-521.
|
||||
int pmbtoken_exp0_generate_key(CBB *out_private, CBB *out_public);
|
||||
int pmbtoken_exp0_client_key_from_bytes(PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
int pmbtoken_exp0_issuer_key_from_bytes(PMBTOKEN_ISSUER_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) * pmbtoken_exp0_blind(CBB *cbb, size_t count);
|
||||
int pmbtoken_exp0_sign(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata);
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
pmbtoken_exp0_unblind(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens,
|
||||
CBS *cbs, size_t count, uint32_t key_id);
|
||||
int pmbtoken_exp0_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len);
|
||||
|
||||
// The following functions implement the corresponding |TRUST_TOKENS_METHOD|
|
||||
// functions for |TRUST_TOKENS_experiment_v1|'s PMBTokens construction which
|
||||
// uses P-384.
|
||||
@@ -131,6 +110,39 @@ int pmbtoken_exp1_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
// function is used to confirm H was computed as expected.
|
||||
OPENSSL_EXPORT int pmbtoken_exp1_get_h_for_testing(uint8_t out[97]);
|
||||
|
||||
// The following functions implement the corresponding |TRUST_TOKENS_METHOD|
|
||||
// functions for |TRUST_TOKENS_experiment_v2|'s PMBTokens construction which
|
||||
// uses P-384.
|
||||
//
|
||||
// We use P-384 instead of our usual choice of P-256. See Appendix I which
|
||||
// describes two attacks which may affect smaller curves. In particular, p-1 for
|
||||
// P-256 is smooth, giving a low complexity for the p-1 attack. P-384's p-1 has
|
||||
// a 281-bit prime factor,
|
||||
// 3055465788140352002733946906144561090641249606160407884365391979704929268480326390471.
|
||||
// This lower-bounds the p-1 attack at O(2^140). The p+1 attack is lower-bounded
|
||||
// by O(p^(1/3)) or O(2^128), so we do not need to check the smoothness of p+1.
|
||||
int pmbtoken_exp2_generate_key(CBB *out_private, CBB *out_public);
|
||||
int pmbtoken_exp2_client_key_from_bytes(PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
int pmbtoken_exp2_issuer_key_from_bytes(PMBTOKEN_ISSUER_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) * pmbtoken_exp2_blind(CBB *cbb, size_t count);
|
||||
int pmbtoken_exp2_sign(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata);
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
pmbtoken_exp2_unblind(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens,
|
||||
CBS *cbs, size_t count, uint32_t key_id);
|
||||
int pmbtoken_exp2_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len);
|
||||
|
||||
// pmbtoken_exp2_get_h_for_testing returns H in uncompressed coordinates. This
|
||||
// function is used to confirm H was computed as expected.
|
||||
OPENSSL_EXPORT int pmbtoken_exp2_get_h_for_testing(uint8_t out[97]);
|
||||
|
||||
|
||||
// Trust Tokens internals.
|
||||
|
||||
@@ -194,13 +206,14 @@ struct trust_token_method_st {
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len);
|
||||
|
||||
// use_token_hash determines whether to include the token hash in the SRR and
|
||||
// private metadata encryption.
|
||||
int use_token_hash : 1;
|
||||
// whether the construction supports private metadata.
|
||||
int has_private_metadata;
|
||||
|
||||
// batched_proof determines whether PMBToken uses a batched DLEQOR proof when
|
||||
// signing tokens.
|
||||
int batched_proof : 1;
|
||||
// max keys that can be configured.
|
||||
size_t max_keys;
|
||||
|
||||
// whether the SRR is part of the protocol.
|
||||
int has_srr;
|
||||
};
|
||||
|
||||
// Structure representing a single Trust Token public key with the specified ID.
|
||||
@@ -224,7 +237,7 @@ struct trust_token_client_st {
|
||||
|
||||
// keys is the set of public keys that are supported by the client for
|
||||
// issuance/redemptions.
|
||||
struct trust_token_client_key_st keys[3];
|
||||
struct trust_token_client_key_st keys[6];
|
||||
|
||||
// num_keys is the number of keys currently configured.
|
||||
size_t num_keys;
|
||||
@@ -246,7 +259,7 @@ struct trust_token_issuer_st {
|
||||
// keys is the set of private keys that are supported by the issuer for
|
||||
// issuance/redemptions. The public metadata is an index into this list of
|
||||
// keys.
|
||||
struct trust_token_issuer_key_st keys[3];
|
||||
struct trust_token_issuer_key_st keys[6];
|
||||
|
||||
// num_keys is the number of keys currently configured.
|
||||
size_t num_keys;
|
||||
|
||||
@@ -52,9 +52,7 @@ typedef struct {
|
||||
// hash_c implements the H_c operation in PMBTokens. It returns one on success
|
||||
// and zero on error.
|
||||
hash_c_func_t hash_c;
|
||||
// batched_proof determines whether PMBToken uses a batched DLEQOR proof when
|
||||
// signing tokens.
|
||||
int batched_proof : 1;
|
||||
int prefix_point : 1;
|
||||
} PMBTOKEN_METHOD;
|
||||
|
||||
static const uint8_t kDefaultAdditionalData[32] = {0};
|
||||
@@ -62,7 +60,7 @@ static const uint8_t kDefaultAdditionalData[32] = {0};
|
||||
static int pmbtoken_init_method(PMBTOKEN_METHOD *method, int curve_nid,
|
||||
const uint8_t *h_bytes, size_t h_len,
|
||||
hash_t_func_t hash_t, hash_s_func_t hash_s,
|
||||
hash_c_func_t hash_c, int batched_proof) {
|
||||
hash_c_func_t hash_c, int prefix_point) {
|
||||
method->group = EC_GROUP_new_by_curve_name(curve_nid);
|
||||
if (method->group == NULL) {
|
||||
return 0;
|
||||
@@ -71,7 +69,7 @@ static int pmbtoken_init_method(PMBTOKEN_METHOD *method, int curve_nid,
|
||||
method->hash_t = hash_t;
|
||||
method->hash_s = hash_s;
|
||||
method->hash_c = hash_c;
|
||||
method->batched_proof = batched_proof;
|
||||
method->prefix_point = prefix_point;
|
||||
|
||||
EC_AFFINE h;
|
||||
if (!ec_point_from_uncompressed(method->group, &h, h_bytes, h_len)) {
|
||||
@@ -117,11 +115,40 @@ static int point_to_cbb(CBB *out, const EC_GROUP *group,
|
||||
len) == len;
|
||||
}
|
||||
|
||||
static int cbb_add_prefixed_point(CBB *out, const EC_GROUP *group,
|
||||
const EC_AFFINE *point, int prefix_point) {
|
||||
if (prefix_point) {
|
||||
CBB child;
|
||||
if (!CBB_add_u16_length_prefixed(out, &child) ||
|
||||
!point_to_cbb(&child, group, point) ||
|
||||
!CBB_flush(out)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!point_to_cbb(out, group, point) ||
|
||||
!CBB_flush(out)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cbs_get_prefixed_point(CBS *cbs, const EC_GROUP *group,
|
||||
EC_AFFINE *out) {
|
||||
EC_AFFINE *out, int prefix_point) {
|
||||
CBS child;
|
||||
if (!CBS_get_u16_length_prefixed(cbs, &child) ||
|
||||
!ec_point_from_uncompressed(group, out, CBS_data(&child),
|
||||
if (prefix_point) {
|
||||
if (!CBS_get_u16_length_prefixed(cbs, &child)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
size_t plen = 1 + 2 * BN_num_bytes(&group->field);
|
||||
if (!CBS_get_bytes(cbs, &child, plen)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ec_point_from_uncompressed(group, out, CBS_data(&child),
|
||||
CBS_len(&child))) {
|
||||
return 0;
|
||||
}
|
||||
@@ -170,16 +197,12 @@ static int pmbtoken_generate_key(const PMBTOKEN_METHOD *method,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(https://crbug.com/boringssl/331): When updating the key format, remove
|
||||
// the redundant length prefixes.
|
||||
CBB child;
|
||||
if (!CBB_add_u16_length_prefixed(out_public, &child) ||
|
||||
!point_to_cbb(&child, group, &pub_affine[0]) ||
|
||||
!CBB_add_u16_length_prefixed(out_public, &child) ||
|
||||
!point_to_cbb(&child, group, &pub_affine[1]) ||
|
||||
!CBB_add_u16_length_prefixed(out_public, &child) ||
|
||||
!point_to_cbb(&child, group, &pub_affine[2]) ||
|
||||
!CBB_flush(out_public)) {
|
||||
if (!cbb_add_prefixed_point(out_public, group, &pub_affine[0],
|
||||
method->prefix_point) ||
|
||||
!cbb_add_prefixed_point(out_public, group, &pub_affine[1],
|
||||
method->prefix_point) ||
|
||||
!cbb_add_prefixed_point(out_public, group, &pub_affine[2],
|
||||
method->prefix_point)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
@@ -190,13 +213,14 @@ static int pmbtoken_generate_key(const PMBTOKEN_METHOD *method,
|
||||
static int pmbtoken_client_key_from_bytes(const PMBTOKEN_METHOD *method,
|
||||
PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len) {
|
||||
// TODO(https://crbug.com/boringssl/331): When updating the key format, remove
|
||||
// the redundant length prefixes.
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, in, len);
|
||||
if (!cbs_get_prefixed_point(&cbs, method->group, &key->pub0) ||
|
||||
!cbs_get_prefixed_point(&cbs, method->group, &key->pub1) ||
|
||||
!cbs_get_prefixed_point(&cbs, method->group, &key->pubs) ||
|
||||
if (!cbs_get_prefixed_point(&cbs, method->group, &key->pub0,
|
||||
method->prefix_point) ||
|
||||
!cbs_get_prefixed_point(&cbs, method->group, &key->pub1,
|
||||
method->prefix_point) ||
|
||||
!cbs_get_prefixed_point(&cbs, method->group, &key->pubs,
|
||||
method->prefix_point) ||
|
||||
CBS_len(&cbs) != 0) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
return 0;
|
||||
@@ -286,12 +310,8 @@ static STACK_OF(PMBTOKEN_PRETOKEN) *
|
||||
goto err;
|
||||
}
|
||||
|
||||
// TODO(https://crbug.com/boringssl/331): When updating the key format,
|
||||
// remove the redundant length prefixes.
|
||||
CBB child;
|
||||
if (!CBB_add_u16_length_prefixed(cbb, &child) ||
|
||||
!point_to_cbb(&child, group, &pretoken->Tp) ||
|
||||
!CBB_flush(cbb)) {
|
||||
if (!cbb_add_prefixed_point(cbb, group, &pretoken->Tp,
|
||||
method->prefix_point)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@@ -724,43 +744,37 @@ static int pmbtoken_sign(const PMBTOKEN_METHOD *method,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (num_to_issue > ((size_t)-1) / sizeof(EC_RAW_POINT) ||
|
||||
num_to_issue > ((size_t)-1) / sizeof(EC_SCALAR)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
EC_RAW_POINT *Tps = NULL;
|
||||
EC_RAW_POINT *Sps = NULL;
|
||||
EC_RAW_POINT *Wps = NULL;
|
||||
EC_RAW_POINT *Wsps = NULL;
|
||||
EC_SCALAR *es = NULL;
|
||||
EC_RAW_POINT *Tps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
EC_RAW_POINT *Sps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
EC_RAW_POINT *Wps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
EC_RAW_POINT *Wsps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
EC_SCALAR *es = OPENSSL_malloc(num_to_issue * sizeof(EC_SCALAR));
|
||||
CBB batch_cbb;
|
||||
CBB_zero(&batch_cbb);
|
||||
if (method->batched_proof) {
|
||||
if (num_to_issue > ((size_t)-1) / sizeof(EC_RAW_POINT) ||
|
||||
num_to_issue > ((size_t)-1) / sizeof(EC_SCALAR)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
}
|
||||
Tps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
Sps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
Wps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
Wsps = OPENSSL_malloc(num_to_issue * sizeof(EC_RAW_POINT));
|
||||
es = OPENSSL_malloc(num_to_issue * sizeof(EC_SCALAR));
|
||||
if (!Tps ||
|
||||
!Sps ||
|
||||
!Wps ||
|
||||
!Wsps ||
|
||||
!es ||
|
||||
!CBB_init(&batch_cbb, 0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pubs) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub1)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (!Tps ||
|
||||
!Sps ||
|
||||
!Wps ||
|
||||
!Wsps ||
|
||||
!es ||
|
||||
!CBB_init(&batch_cbb, 0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pubs) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub1)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_to_issue; i++) {
|
||||
EC_AFFINE Tp_affine;
|
||||
EC_RAW_POINT Tp;
|
||||
if (!cbs_get_prefixed_point(cbs, group, &Tp_affine)) {
|
||||
if (!cbs_get_prefixed_point(cbs, group, &Tp_affine, method->prefix_point)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
@@ -776,7 +790,6 @@ static int pmbtoken_sign(const PMBTOKEN_METHOD *method,
|
||||
// The |jacobians| and |affines| contain Sp, Wp, and Wsp.
|
||||
EC_RAW_POINT jacobians[3];
|
||||
EC_AFFINE affines[3];
|
||||
CBB child;
|
||||
if (!method->hash_s(group, &jacobians[0], &Tp_affine, s) ||
|
||||
!ec_point_mul_scalar_batch(group, &jacobians[1], &Tp, &xb,
|
||||
&jacobians[0], &yb, NULL, NULL) ||
|
||||
@@ -784,34 +797,22 @@ static int pmbtoken_sign(const PMBTOKEN_METHOD *method,
|
||||
&jacobians[0], &key->ys, NULL, NULL) ||
|
||||
!ec_jacobian_to_affine_batch(group, affines, jacobians, 3) ||
|
||||
!CBB_add_bytes(cbb, s, PMBTOKEN_NONCE_SIZE) ||
|
||||
// TODO(https://crbug.com/boringssl/331): When updating the key format,
|
||||
// remove the redundant length prefixes.
|
||||
!CBB_add_u16_length_prefixed(cbb, &child) ||
|
||||
!point_to_cbb(&child, group, &affines[1]) ||
|
||||
!CBB_add_u16_length_prefixed(cbb, &child) ||
|
||||
!point_to_cbb(&child, group, &affines[2])) {
|
||||
!cbb_add_prefixed_point(cbb, group, &affines[1], method->prefix_point) ||
|
||||
!cbb_add_prefixed_point(cbb, group, &affines[2], method->prefix_point)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!method->batched_proof) {
|
||||
if (!CBB_add_u16_length_prefixed(cbb, &child) ||
|
||||
!dleq_generate(method, &child, key, &Tp, &jacobians[0], &jacobians[1],
|
||||
&jacobians[2], private_metadata)) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
if (!point_to_cbb(&batch_cbb, group, &Tp_affine) ||
|
||||
!point_to_cbb(&batch_cbb, group, &affines[0]) ||
|
||||
!point_to_cbb(&batch_cbb, group, &affines[1]) ||
|
||||
!point_to_cbb(&batch_cbb, group, &affines[2])) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
Tps[i] = Tp;
|
||||
Sps[i] = jacobians[0];
|
||||
Wps[i] = jacobians[1];
|
||||
Wsps[i] = jacobians[2];
|
||||
if (!point_to_cbb(&batch_cbb, group, &Tp_affine) ||
|
||||
!point_to_cbb(&batch_cbb, group, &affines[0]) ||
|
||||
!point_to_cbb(&batch_cbb, group, &affines[1]) ||
|
||||
!point_to_cbb(&batch_cbb, group, &affines[2])) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
Tps[i] = Tp;
|
||||
Sps[i] = jacobians[0];
|
||||
Wps[i] = jacobians[1];
|
||||
Wsps[i] = jacobians[2];
|
||||
|
||||
if (!CBB_flush(cbb)) {
|
||||
goto err;
|
||||
@@ -821,41 +822,43 @@ static int pmbtoken_sign(const PMBTOKEN_METHOD *method,
|
||||
// The DLEQ batching construction is described in appendix B of
|
||||
// https://eprint.iacr.org/2020/072/20200324:214215. Note the additional
|
||||
// computations all act on public inputs.
|
||||
if (method->batched_proof) {
|
||||
for (size_t i = 0; i < num_to_issue; i++) {
|
||||
if (!hash_c_batch(method, &es[i], &batch_cbb, i)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
EC_RAW_POINT Tp_batch, Sp_batch, Wp_batch, Wsp_batch;
|
||||
if (!ec_point_mul_scalar_public_batch(group, &Tp_batch,
|
||||
/*g_scalar=*/NULL, Tps, es,
|
||||
num_to_issue) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Sp_batch,
|
||||
/*g_scalar=*/NULL, Sps, es,
|
||||
num_to_issue) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wp_batch,
|
||||
/*g_scalar=*/NULL, Wps, es,
|
||||
num_to_issue) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wsp_batch,
|
||||
/*g_scalar=*/NULL, Wsps, es,
|
||||
num_to_issue)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CBB proof;
|
||||
if (!CBB_add_u16_length_prefixed(cbb, &proof) ||
|
||||
!dleq_generate(method, &proof, key, &Tp_batch, &Sp_batch, &Wp_batch,
|
||||
&Wsp_batch, private_metadata) ||
|
||||
!CBB_flush(cbb)) {
|
||||
for (size_t i = 0; i < num_to_issue; i++) {
|
||||
if (!hash_c_batch(method, &es[i], &batch_cbb, i)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
EC_RAW_POINT Tp_batch, Sp_batch, Wp_batch, Wsp_batch;
|
||||
if (!ec_point_mul_scalar_public_batch(group, &Tp_batch,
|
||||
/*g_scalar=*/NULL, Tps, es,
|
||||
num_to_issue) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Sp_batch,
|
||||
/*g_scalar=*/NULL, Sps, es,
|
||||
num_to_issue) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wp_batch,
|
||||
/*g_scalar=*/NULL, Wps, es,
|
||||
num_to_issue) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wsp_batch,
|
||||
/*g_scalar=*/NULL, Wsps, es,
|
||||
num_to_issue)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CBB proof;
|
||||
if (!CBB_add_u16_length_prefixed(cbb, &proof) ||
|
||||
!dleq_generate(method, &proof, key, &Tp_batch, &Sp_batch, &Wp_batch,
|
||||
&Wsp_batch, private_metadata) ||
|
||||
!CBB_flush(cbb)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Skip over any unused requests.
|
||||
size_t point_len = 1 + 2 * BN_num_bytes(&group->field);
|
||||
if (!CBS_skip(cbs, (2 + point_len) * (num_requested - num_to_issue))) {
|
||||
size_t token_len = point_len;
|
||||
if (method->prefix_point) {
|
||||
token_len += 2;
|
||||
}
|
||||
if (!CBS_skip(cbs, token_len * (num_requested - num_to_issue))) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
@@ -890,36 +893,29 @@ static STACK_OF(TRUST_TOKEN) *
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EC_RAW_POINT *Tps = NULL;
|
||||
EC_RAW_POINT *Sps = NULL;
|
||||
EC_RAW_POINT *Wps = NULL;
|
||||
EC_RAW_POINT *Wsps = NULL;
|
||||
EC_SCALAR *es = NULL;
|
||||
if (count > ((size_t)-1) / sizeof(EC_RAW_POINT) ||
|
||||
count > ((size_t)-1) / sizeof(EC_SCALAR)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
EC_RAW_POINT *Tps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
EC_RAW_POINT *Sps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
EC_RAW_POINT *Wps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
EC_RAW_POINT *Wsps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
EC_SCALAR *es = OPENSSL_malloc(count * sizeof(EC_SCALAR));
|
||||
CBB batch_cbb;
|
||||
CBB_zero(&batch_cbb);
|
||||
if (method->batched_proof) {
|
||||
if (count > ((size_t)-1) / sizeof(EC_RAW_POINT) ||
|
||||
count > ((size_t)-1) / sizeof(EC_SCALAR)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
}
|
||||
Tps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
Sps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
Wps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
Wsps = OPENSSL_malloc(count * sizeof(EC_RAW_POINT));
|
||||
es = OPENSSL_malloc(count * sizeof(EC_SCALAR));
|
||||
if (!Tps ||
|
||||
!Sps ||
|
||||
!Wps ||
|
||||
!Wsps ||
|
||||
!es ||
|
||||
!CBB_init(&batch_cbb, 0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pubs) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub1)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (!Tps ||
|
||||
!Sps ||
|
||||
!Wps ||
|
||||
!Wsps ||
|
||||
!es ||
|
||||
!CBB_init(&batch_cbb, 0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pubs) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub0) ||
|
||||
!point_to_cbb(&batch_cbb, method->group, &key->pub1)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
@@ -928,77 +924,54 @@ static STACK_OF(TRUST_TOKEN) *
|
||||
|
||||
uint8_t s[PMBTOKEN_NONCE_SIZE];
|
||||
EC_AFFINE Wp_affine, Wsp_affine;
|
||||
CBS proof;
|
||||
if (!CBS_copy_bytes(cbs, s, PMBTOKEN_NONCE_SIZE) ||
|
||||
!cbs_get_prefixed_point(cbs, group, &Wp_affine) ||
|
||||
!cbs_get_prefixed_point(cbs, group, &Wsp_affine)) {
|
||||
!cbs_get_prefixed_point(cbs, group, &Wp_affine, method->prefix_point) ||
|
||||
!cbs_get_prefixed_point(cbs, group, &Wsp_affine,
|
||||
method->prefix_point)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
EC_RAW_POINT Tp, Wp, Wsp, Sp;
|
||||
ec_affine_to_jacobian(group, &Tp, &pretoken->Tp);
|
||||
ec_affine_to_jacobian(group, &Wp, &Wp_affine);
|
||||
ec_affine_to_jacobian(group, &Wsp, &Wsp_affine);
|
||||
if (!method->hash_s(group, &Sp, &pretoken->Tp, s)) {
|
||||
ec_affine_to_jacobian(group, &Tps[i], &pretoken->Tp);
|
||||
ec_affine_to_jacobian(group, &Wps[i], &Wp_affine);
|
||||
ec_affine_to_jacobian(group, &Wsps[i], &Wsp_affine);
|
||||
if (!method->hash_s(group, &Sps[i], &pretoken->Tp, s)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!method->batched_proof) {
|
||||
if(!CBS_get_u16_length_prefixed(cbs, &proof)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!dleq_verify(method, &proof, key, &Tp, &Sp, &Wp, &Wsp)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (CBS_len(&proof) != 0) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
EC_AFFINE Sp_affine;
|
||||
if (!point_to_cbb(&batch_cbb, group, &pretoken->Tp) ||
|
||||
!ec_jacobian_to_affine(group, &Sp_affine, &Sp) ||
|
||||
!point_to_cbb(&batch_cbb, group, &Sp_affine) ||
|
||||
!point_to_cbb(&batch_cbb, group, &Wp_affine) ||
|
||||
!point_to_cbb(&batch_cbb, group, &Wsp_affine)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
Tps[i] = Tp;
|
||||
Sps[i] = Sp;
|
||||
Wps[i] = Wp;
|
||||
Wsps[i] = Wsp;
|
||||
EC_AFFINE Sp_affine;
|
||||
if (!point_to_cbb(&batch_cbb, group, &pretoken->Tp) ||
|
||||
!ec_jacobian_to_affine(group, &Sp_affine, &Sps[i]) ||
|
||||
!point_to_cbb(&batch_cbb, group, &Sp_affine) ||
|
||||
!point_to_cbb(&batch_cbb, group, &Wp_affine) ||
|
||||
!point_to_cbb(&batch_cbb, group, &Wsp_affine)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Unblind the token.
|
||||
EC_RAW_POINT jacobians[3];
|
||||
EC_AFFINE affines[3];
|
||||
if (!ec_point_mul_scalar(group, &jacobians[0], &Sp, &pretoken->r) ||
|
||||
!ec_point_mul_scalar(group, &jacobians[1], &Wp, &pretoken->r) ||
|
||||
!ec_point_mul_scalar(group, &jacobians[2], &Wsp, &pretoken->r) ||
|
||||
if (!ec_point_mul_scalar(group, &jacobians[0], &Sps[i], &pretoken->r) ||
|
||||
!ec_point_mul_scalar(group, &jacobians[1], &Wps[i], &pretoken->r) ||
|
||||
!ec_point_mul_scalar(group, &jacobians[2], &Wsps[i], &pretoken->r) ||
|
||||
!ec_jacobian_to_affine_batch(group, affines, jacobians, 3)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Serialize the token. Include |key_id| to avoid an extra copy in the layer
|
||||
// above.
|
||||
CBB token_cbb, child;
|
||||
CBB token_cbb;
|
||||
size_t point_len = 1 + 2 * BN_num_bytes(&group->field);
|
||||
if (!CBB_init(&token_cbb, 4 + PMBTOKEN_NONCE_SIZE + 3 * (2 + point_len)) ||
|
||||
!CBB_add_u32(&token_cbb, key_id) ||
|
||||
!CBB_add_bytes(&token_cbb, pretoken->t, PMBTOKEN_NONCE_SIZE) ||
|
||||
// TODO(https://crbug.com/boringssl/331): When updating the key format,
|
||||
// remove the redundant length prefixes.
|
||||
!CBB_add_u16_length_prefixed(&token_cbb, &child) ||
|
||||
!point_to_cbb(&child, group, &affines[0]) ||
|
||||
!CBB_add_u16_length_prefixed(&token_cbb, &child) ||
|
||||
!point_to_cbb(&child, group, &affines[1]) ||
|
||||
!CBB_add_u16_length_prefixed(&token_cbb, &child) ||
|
||||
!point_to_cbb(&child, group, &affines[2]) ||
|
||||
!cbb_add_prefixed_point(&token_cbb, group, &affines[0],
|
||||
method->prefix_point) ||
|
||||
!cbb_add_prefixed_point(&token_cbb, group, &affines[1],
|
||||
method->prefix_point) ||
|
||||
!cbb_add_prefixed_point(&token_cbb, group, &affines[2],
|
||||
method->prefix_point) ||
|
||||
!CBB_flush(&token_cbb)) {
|
||||
CBB_cleanup(&token_cbb);
|
||||
goto err;
|
||||
@@ -1018,32 +991,30 @@ static STACK_OF(TRUST_TOKEN) *
|
||||
// The DLEQ batching construction is described in appendix B of
|
||||
// https://eprint.iacr.org/2020/072/20200324:214215. Note the additional
|
||||
// computations all act on public inputs.
|
||||
if (method->batched_proof) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (!hash_c_batch(method, &es[i], &batch_cbb, i)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
EC_RAW_POINT Tp_batch, Sp_batch, Wp_batch, Wsp_batch;
|
||||
if (!ec_point_mul_scalar_public_batch(group, &Tp_batch,
|
||||
/*g_scalar=*/NULL, Tps, es, count) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Sp_batch,
|
||||
/*g_scalar=*/NULL, Sps, es, count) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wp_batch,
|
||||
/*g_scalar=*/NULL, Wps, es, count) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wsp_batch,
|
||||
/*g_scalar=*/NULL, Wsps, es, count)) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (!hash_c_batch(method, &es[i], &batch_cbb, i)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
CBS proof;
|
||||
if (!CBS_get_u16_length_prefixed(cbs, &proof) ||
|
||||
!dleq_verify(method, &proof, key, &Tp_batch, &Sp_batch, &Wp_batch,
|
||||
&Wsp_batch) ||
|
||||
CBS_len(&proof) != 0) {
|
||||
goto err;
|
||||
}
|
||||
EC_RAW_POINT Tp_batch, Sp_batch, Wp_batch, Wsp_batch;
|
||||
if (!ec_point_mul_scalar_public_batch(group, &Tp_batch,
|
||||
/*g_scalar=*/NULL, Tps, es, count) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Sp_batch,
|
||||
/*g_scalar=*/NULL, Sps, es, count) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wp_batch,
|
||||
/*g_scalar=*/NULL, Wps, es, count) ||
|
||||
!ec_point_mul_scalar_public_batch(group, &Wsp_batch,
|
||||
/*g_scalar=*/NULL, Wsps, es, count)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CBS proof;
|
||||
if (!CBS_get_u16_length_prefixed(cbs, &proof) ||
|
||||
!dleq_verify(method, &proof, key, &Tp_batch, &Sp_batch, &Wp_batch,
|
||||
&Wsp_batch) ||
|
||||
CBS_len(&proof) != 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
@@ -1072,9 +1043,9 @@ static int pmbtoken_read(const PMBTOKEN_METHOD *method,
|
||||
CBS_init(&cbs, token, token_len);
|
||||
EC_AFFINE S, W, Ws;
|
||||
if (!CBS_copy_bytes(&cbs, out_nonce, PMBTOKEN_NONCE_SIZE) ||
|
||||
!cbs_get_prefixed_point(&cbs, group, &S) ||
|
||||
!cbs_get_prefixed_point(&cbs, group, &W) ||
|
||||
!cbs_get_prefixed_point(&cbs, group, &Ws) ||
|
||||
!cbs_get_prefixed_point(&cbs, group, &S, method->prefix_point) ||
|
||||
!cbs_get_prefixed_point(&cbs, group, &W, method->prefix_point) ||
|
||||
!cbs_get_prefixed_point(&cbs, group, &Ws, method->prefix_point) ||
|
||||
CBS_len(&cbs) != 0) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_TOKEN);
|
||||
return 0;
|
||||
@@ -1127,202 +1098,6 @@ static int pmbtoken_read(const PMBTOKEN_METHOD *method,
|
||||
}
|
||||
|
||||
|
||||
// PMBTokens experiment v0.
|
||||
|
||||
static int pmbtoken_exp0_hash_t(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const uint8_t t[PMBTOKEN_NONCE_SIZE]) {
|
||||
const uint8_t kHashTLabel[] = "PMBTokensV0 HashT";
|
||||
return ec_hash_to_curve_p521_xmd_sha512_sswu_draft06(
|
||||
group, out, kHashTLabel, sizeof(kHashTLabel), t, PMBTOKEN_NONCE_SIZE);
|
||||
}
|
||||
|
||||
static int pmbtoken_exp0_hash_s(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const EC_AFFINE *t,
|
||||
const uint8_t s[PMBTOKEN_NONCE_SIZE]) {
|
||||
const uint8_t kHashSLabel[] = "PMBTokensV0 HashS";
|
||||
int ret = 0;
|
||||
CBB cbb;
|
||||
uint8_t *buf = NULL;
|
||||
size_t len;
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!point_to_cbb(&cbb, group, t) ||
|
||||
!CBB_add_bytes(&cbb, s, PMBTOKEN_NONCE_SIZE) ||
|
||||
!CBB_finish(&cbb, &buf, &len) ||
|
||||
!ec_hash_to_curve_p521_xmd_sha512_sswu_draft06(
|
||||
group, out, kHashSLabel, sizeof(kHashSLabel), buf, len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(buf);
|
||||
CBB_cleanup(&cbb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pmbtoken_exp0_hash_c(const EC_GROUP *group, EC_SCALAR *out,
|
||||
uint8_t *buf, size_t len) {
|
||||
const uint8_t kHashCLabel[] = "PMBTokensV0 HashC";
|
||||
return ec_hash_to_scalar_p521_xmd_sha512_draft06(
|
||||
group, out, kHashCLabel, sizeof(kHashCLabel), buf, len);
|
||||
}
|
||||
|
||||
// H for PMBTokens v0 was generated with the following Python code.
|
||||
/*
|
||||
import hashlib
|
||||
|
||||
SEED_H = 'PrivacyPass H'
|
||||
|
||||
A = -3
|
||||
B = 0x051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00
|
||||
P = 2**521 - 1
|
||||
|
||||
def get_y(x):
|
||||
y2 = (x**3 + A*x + B) % P
|
||||
y = pow(y2, (P+1)/4, P)
|
||||
if (y*y) % P != y2:
|
||||
raise ValueError("point not on curve")
|
||||
return y
|
||||
|
||||
def bit(h,i):
|
||||
return (ord(h[i/8]) >> (i%8)) & 1
|
||||
|
||||
b = 521
|
||||
def decode_point(so):
|
||||
s = hashlib.sha256(so + '0').digest() + hashlib.sha256(so + '1').digest() + \
|
||||
hashlib.sha256(so + '2').digest()
|
||||
|
||||
x = 0
|
||||
for i in range(0,b):
|
||||
x = x + (long(bit(s,i))<<i)
|
||||
if x >= P:
|
||||
raise ValueError("x out of range")
|
||||
y = get_y(x)
|
||||
if y & 1 != bit(s,b-1): y = P-y
|
||||
return (x, y)
|
||||
|
||||
|
||||
def gen_point(seed):
|
||||
v = hashlib.sha256(seed).digest()
|
||||
it = 1
|
||||
while True:
|
||||
try:
|
||||
x,y = decode_point(v)
|
||||
except Exception, e:
|
||||
print e
|
||||
it += 1
|
||||
v = hashlib.sha256(v).digest()
|
||||
continue
|
||||
print "Found in %d iterations:" % it
|
||||
print " x = %d" % x
|
||||
print " y = %d" % y
|
||||
print " Encoded (hex): (%x, %x)" % (x, y)
|
||||
return (x, y)
|
||||
|
||||
if __name__ == "__main__":
|
||||
gen_point(SEED_H)
|
||||
*/
|
||||
static int pmbtoken_exp0_ok = 0;
|
||||
static PMBTOKEN_METHOD pmbtoken_exp0_method;
|
||||
static CRYPTO_once_t pmbtoken_exp0_method_once = CRYPTO_ONCE_INIT;
|
||||
|
||||
static void pmbtoken_exp0_init_method_impl(void) {
|
||||
static const uint8_t kH[] = {
|
||||
0x04, 0x01, 0xf0, 0xa9, 0xf7, 0x9e, 0xbc, 0x12, 0x6c, 0xef, 0xd1, 0xab,
|
||||
0x29, 0x10, 0x03, 0x6f, 0x4e, 0xf5, 0xbd, 0xeb, 0x0f, 0x6b, 0xc0, 0x5c,
|
||||
0x0e, 0xce, 0xfe, 0x59, 0x45, 0xd1, 0x3e, 0x25, 0x33, 0x7e, 0x4c, 0xda,
|
||||
0x64, 0x53, 0x54, 0x4e, 0xf9, 0x76, 0x0d, 0x6d, 0xc5, 0x39, 0x2a, 0xd4,
|
||||
0xce, 0x84, 0x6e, 0x31, 0xc2, 0x86, 0x21, 0xf9, 0x5c, 0x98, 0xb9, 0x3d,
|
||||
0x01, 0x74, 0x9f, 0xc5, 0x1e, 0x47, 0x24, 0x00, 0x5c, 0x17, 0x62, 0x51,
|
||||
0x7d, 0x32, 0x5e, 0x29, 0xac, 0x52, 0x14, 0x75, 0x6f, 0x36, 0xd9, 0xc7,
|
||||
0xfa, 0xbb, 0xa9, 0x3b, 0x9d, 0x70, 0x49, 0x1e, 0xb4, 0x53, 0xbc, 0x55,
|
||||
0xea, 0xad, 0x8f, 0x26, 0x1d, 0xe0, 0xbc, 0xf3, 0x50, 0x5c, 0x7e, 0x66,
|
||||
0x41, 0xb5, 0x61, 0x70, 0x12, 0x72, 0xac, 0x6a, 0xb0, 0x6e, 0x78, 0x3d,
|
||||
0x17, 0x08, 0xe3, 0xdf, 0x3c, 0xff, 0xa6, 0xa0, 0xea, 0x96, 0x67, 0x92,
|
||||
0xcd,
|
||||
};
|
||||
|
||||
pmbtoken_exp0_ok =
|
||||
pmbtoken_init_method(&pmbtoken_exp0_method, NID_secp521r1, kH, sizeof(kH),
|
||||
pmbtoken_exp0_hash_t, pmbtoken_exp0_hash_s,
|
||||
pmbtoken_exp0_hash_c, /*batched_proof=*/0);
|
||||
}
|
||||
|
||||
static int pmbtoken_exp0_init_method(void) {
|
||||
CRYPTO_once(&pmbtoken_exp0_method_once, pmbtoken_exp0_init_method_impl);
|
||||
if (!pmbtoken_exp0_ok) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pmbtoken_exp0_generate_key(CBB *out_private, CBB *out_public) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pmbtoken_generate_key(&pmbtoken_exp0_method, out_private, out_public);
|
||||
}
|
||||
|
||||
int pmbtoken_exp0_client_key_from_bytes(PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_client_key_from_bytes(&pmbtoken_exp0_method, key, in, len);
|
||||
}
|
||||
|
||||
int pmbtoken_exp0_issuer_key_from_bytes(PMBTOKEN_ISSUER_KEY *key,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_issuer_key_from_bytes(&pmbtoken_exp0_method, key, in, len);
|
||||
}
|
||||
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) * pmbtoken_exp0_blind(CBB *cbb, size_t count) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return NULL;
|
||||
}
|
||||
return pmbtoken_blind(&pmbtoken_exp0_method, cbb, count);
|
||||
}
|
||||
|
||||
int pmbtoken_exp0_sign(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_sign(&pmbtoken_exp0_method, key, cbb, cbs, num_requested,
|
||||
num_to_issue, private_metadata);
|
||||
}
|
||||
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
pmbtoken_exp0_unblind(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens,
|
||||
CBS *cbs, size_t count, uint32_t key_id) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return NULL;
|
||||
}
|
||||
return pmbtoken_unblind(&pmbtoken_exp0_method, key, pretokens, cbs, count,
|
||||
key_id);
|
||||
}
|
||||
|
||||
int pmbtoken_exp0_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len) {
|
||||
if (!pmbtoken_exp0_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_read(&pmbtoken_exp0_method, key, out_nonce,
|
||||
out_private_metadata, token, token_len);
|
||||
}
|
||||
|
||||
|
||||
// PMBTokens experiment v1.
|
||||
|
||||
static int pmbtoken_exp1_hash_t(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
@@ -1387,7 +1162,7 @@ static void pmbtoken_exp1_init_method_impl(void) {
|
||||
pmbtoken_exp1_ok =
|
||||
pmbtoken_init_method(&pmbtoken_exp1_method, NID_secp384r1, kH, sizeof(kH),
|
||||
pmbtoken_exp1_hash_t, pmbtoken_exp1_hash_s,
|
||||
pmbtoken_exp1_hash_c, /*batched_proof=*/1);
|
||||
pmbtoken_exp1_hash_c, 1);
|
||||
}
|
||||
|
||||
static int pmbtoken_exp1_init_method(void) {
|
||||
@@ -1472,3 +1247,153 @@ int pmbtoken_exp1_get_h_for_testing(uint8_t out[97]) {
|
||||
ec_point_to_bytes(pmbtoken_exp1_method.group, &h,
|
||||
POINT_CONVERSION_UNCOMPRESSED, out, 97) == 97;
|
||||
}
|
||||
|
||||
// PMBTokens experiment v2.
|
||||
|
||||
static int pmbtoken_exp2_hash_t(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const uint8_t t[PMBTOKEN_NONCE_SIZE]) {
|
||||
const uint8_t kHashTLabel[] = "PMBTokens Experiment V2 HashT";
|
||||
return ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
group, out, kHashTLabel, sizeof(kHashTLabel), t, PMBTOKEN_NONCE_SIZE);
|
||||
}
|
||||
|
||||
static int pmbtoken_exp2_hash_s(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const EC_AFFINE *t,
|
||||
const uint8_t s[PMBTOKEN_NONCE_SIZE]) {
|
||||
const uint8_t kHashSLabel[] = "PMBTokens Experiment V2 HashS";
|
||||
int ret = 0;
|
||||
CBB cbb;
|
||||
uint8_t *buf = NULL;
|
||||
size_t len;
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!point_to_cbb(&cbb, group, t) ||
|
||||
!CBB_add_bytes(&cbb, s, PMBTOKEN_NONCE_SIZE) ||
|
||||
!CBB_finish(&cbb, &buf, &len) ||
|
||||
!ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
group, out, kHashSLabel, sizeof(kHashSLabel), buf, len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(buf);
|
||||
CBB_cleanup(&cbb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pmbtoken_exp2_hash_c(const EC_GROUP *group, EC_SCALAR *out,
|
||||
uint8_t *buf, size_t len) {
|
||||
const uint8_t kHashCLabel[] = "PMBTokens Experiment V2 HashC";
|
||||
return ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
||||
group, out, kHashCLabel, sizeof(kHashCLabel), buf, len);
|
||||
}
|
||||
|
||||
static int pmbtoken_exp2_ok = 0;
|
||||
static PMBTOKEN_METHOD pmbtoken_exp2_method;
|
||||
static CRYPTO_once_t pmbtoken_exp2_method_once = CRYPTO_ONCE_INIT;
|
||||
|
||||
static void pmbtoken_exp2_init_method_impl(void) {
|
||||
// This is the output of |ec_hash_to_scalar_p384_xmd_sha512_draft07| with DST
|
||||
// "PMBTokens Experiment V2 HashH" and message "generator".
|
||||
static const uint8_t kH[] = {
|
||||
0x04, 0xbc, 0x27, 0x24, 0x99, 0xfa, 0xc9, 0xa4, 0x74, 0x6f, 0xf9,
|
||||
0x07, 0x81, 0x55, 0xf8, 0x1f, 0x6f, 0xda, 0x09, 0xe7, 0x8c, 0x5d,
|
||||
0x9e, 0x4e, 0x14, 0x7c, 0x53, 0x14, 0xbc, 0x7e, 0x29, 0x57, 0x92,
|
||||
0x17, 0x94, 0x6e, 0xd2, 0xdf, 0xa5, 0x31, 0x1b, 0x4e, 0xb7, 0xfc,
|
||||
0x93, 0xe3, 0x6e, 0x14, 0x1f, 0x4f, 0x14, 0xf3, 0xe5, 0x47, 0x61,
|
||||
0x1c, 0x2c, 0x72, 0x25, 0xf0, 0x4a, 0x45, 0x23, 0x2d, 0x57, 0x93,
|
||||
0x0e, 0xb2, 0x55, 0xb8, 0x57, 0x25, 0x4c, 0x1e, 0xdb, 0xfd, 0x58,
|
||||
0x70, 0x17, 0x9a, 0xbb, 0x9e, 0x5e, 0x93, 0x9e, 0x92, 0xd3, 0xe8,
|
||||
0x25, 0x62, 0xbf, 0x59, 0xb2, 0xd2, 0x3d, 0x71, 0xff
|
||||
};
|
||||
|
||||
pmbtoken_exp2_ok =
|
||||
pmbtoken_init_method(&pmbtoken_exp2_method, NID_secp384r1, kH, sizeof(kH),
|
||||
pmbtoken_exp2_hash_t, pmbtoken_exp2_hash_s,
|
||||
pmbtoken_exp2_hash_c, 0);
|
||||
}
|
||||
|
||||
static int pmbtoken_exp2_init_method(void) {
|
||||
CRYPTO_once(&pmbtoken_exp2_method_once, pmbtoken_exp2_init_method_impl);
|
||||
if (!pmbtoken_exp2_ok) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pmbtoken_exp2_generate_key(CBB *out_private, CBB *out_public) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pmbtoken_generate_key(&pmbtoken_exp2_method, out_private, out_public);
|
||||
}
|
||||
|
||||
int pmbtoken_exp2_client_key_from_bytes(PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_client_key_from_bytes(&pmbtoken_exp2_method, key, in, len);
|
||||
}
|
||||
|
||||
int pmbtoken_exp2_issuer_key_from_bytes(PMBTOKEN_ISSUER_KEY *key,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_issuer_key_from_bytes(&pmbtoken_exp2_method, key, in, len);
|
||||
}
|
||||
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) * pmbtoken_exp2_blind(CBB *cbb, size_t count) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return NULL;
|
||||
}
|
||||
return pmbtoken_blind(&pmbtoken_exp2_method, cbb, count);
|
||||
}
|
||||
|
||||
int pmbtoken_exp2_sign(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_sign(&pmbtoken_exp2_method, key, cbb, cbs, num_requested,
|
||||
num_to_issue, private_metadata);
|
||||
}
|
||||
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
pmbtoken_exp2_unblind(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens,
|
||||
CBS *cbs, size_t count, uint32_t key_id) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return NULL;
|
||||
}
|
||||
return pmbtoken_unblind(&pmbtoken_exp2_method, key, pretokens, cbs, count,
|
||||
key_id);
|
||||
}
|
||||
|
||||
int pmbtoken_exp2_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
return pmbtoken_read(&pmbtoken_exp2_method, key, out_nonce,
|
||||
out_private_metadata, token, token_len);
|
||||
}
|
||||
|
||||
int pmbtoken_exp2_get_h_for_testing(uint8_t out[97]) {
|
||||
if (!pmbtoken_exp2_init_method()) {
|
||||
return 0;
|
||||
}
|
||||
EC_AFFINE h;
|
||||
return ec_jacobian_to_affine(pmbtoken_exp2_method.group, &h,
|
||||
&pmbtoken_exp2_method.h) &&
|
||||
ec_point_to_bytes(pmbtoken_exp2_method.group, &h,
|
||||
POINT_CONVERSION_UNCOMPRESSED, out, 97) == 97;
|
||||
}
|
||||
@@ -27,21 +27,6 @@
|
||||
// protocol for issuing and redeeming tokens built on top of the PMBTokens
|
||||
// construction.
|
||||
|
||||
const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v0(void) {
|
||||
static const TRUST_TOKEN_METHOD kMethod = {
|
||||
pmbtoken_exp0_generate_key,
|
||||
pmbtoken_exp0_client_key_from_bytes,
|
||||
pmbtoken_exp0_issuer_key_from_bytes,
|
||||
pmbtoken_exp0_blind,
|
||||
pmbtoken_exp0_sign,
|
||||
pmbtoken_exp0_unblind,
|
||||
pmbtoken_exp0_read,
|
||||
0 /* don't use token hash */,
|
||||
0 /* don't use batched proof */,
|
||||
};
|
||||
return &kMethod;
|
||||
}
|
||||
|
||||
const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v1(void) {
|
||||
static const TRUST_TOKEN_METHOD kMethod = {
|
||||
pmbtoken_exp1_generate_key,
|
||||
@@ -51,8 +36,41 @@ const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v1(void) {
|
||||
pmbtoken_exp1_sign,
|
||||
pmbtoken_exp1_unblind,
|
||||
pmbtoken_exp1_read,
|
||||
1 /* use token hash */,
|
||||
1 /* use batched proof */,
|
||||
1, /* has_private_metadata */
|
||||
3, /* max_keys */
|
||||
1, /* has_srr */
|
||||
};
|
||||
return &kMethod;
|
||||
}
|
||||
|
||||
const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v2_pp(void) {
|
||||
static const TRUST_TOKEN_METHOD kMethod = {
|
||||
pmbtoken_exp2_generate_key,
|
||||
pmbtoken_exp2_client_key_from_bytes,
|
||||
pmbtoken_exp2_issuer_key_from_bytes,
|
||||
pmbtoken_exp2_blind,
|
||||
pmbtoken_exp2_sign,
|
||||
pmbtoken_exp2_unblind,
|
||||
pmbtoken_exp2_read,
|
||||
0, /* has_private_metadata */
|
||||
6, /* max_keys */
|
||||
0, /* has_srr */
|
||||
};
|
||||
return &kMethod;
|
||||
}
|
||||
|
||||
const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v2_pmb(void) {
|
||||
static const TRUST_TOKEN_METHOD kMethod = {
|
||||
pmbtoken_exp2_generate_key,
|
||||
pmbtoken_exp2_client_key_from_bytes,
|
||||
pmbtoken_exp2_issuer_key_from_bytes,
|
||||
pmbtoken_exp2_blind,
|
||||
pmbtoken_exp2_sign,
|
||||
pmbtoken_exp2_unblind,
|
||||
pmbtoken_exp2_read,
|
||||
1, /* has_private_metadata */
|
||||
3, /* max_keys */
|
||||
0, /* has_srr */
|
||||
};
|
||||
return &kMethod;
|
||||
}
|
||||
@@ -148,7 +166,8 @@ void TRUST_TOKEN_CLIENT_free(TRUST_TOKEN_CLIENT *ctx) {
|
||||
|
||||
int TRUST_TOKEN_CLIENT_add_key(TRUST_TOKEN_CLIENT *ctx, size_t *out_key_index,
|
||||
const uint8_t *key, size_t key_len) {
|
||||
if (ctx->num_keys == OPENSSL_ARRAY_SIZE(ctx->keys)) {
|
||||
if (ctx->num_keys == OPENSSL_ARRAY_SIZE(ctx->keys) ||
|
||||
ctx->num_keys >= ctx->method->max_keys) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_TOO_MANY_KEYS);
|
||||
return 0;
|
||||
}
|
||||
@@ -170,6 +189,9 @@ int TRUST_TOKEN_CLIENT_add_key(TRUST_TOKEN_CLIENT *ctx, size_t *out_key_index,
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_set_srr_key(TRUST_TOKEN_CLIENT *ctx, EVP_PKEY *key) {
|
||||
if (!ctx->method->has_srr) {
|
||||
return 1;
|
||||
}
|
||||
EVP_PKEY_free(ctx->srr_key);
|
||||
EVP_PKEY_up_ref(key);
|
||||
ctx->srr_key = key;
|
||||
@@ -287,15 +309,10 @@ int TRUST_TOKEN_CLIENT_begin_redemption(TRUST_TOKEN_CLIENT *ctx, uint8_t **out,
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_finish_redemption(TRUST_TOKEN_CLIENT *ctx,
|
||||
uint8_t **out_srr, size_t *out_srr_len,
|
||||
uint8_t **out_rr, size_t *out_rr_len,
|
||||
uint8_t **out_sig, size_t *out_sig_len,
|
||||
const uint8_t *response,
|
||||
size_t response_len) {
|
||||
if (ctx->srr_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_NO_SRR_KEY_CONFIGURED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS in, srr, sig;
|
||||
CBS_init(&in, response, response_len);
|
||||
if (!CBS_get_u16_length_prefixed(&in, &srr) ||
|
||||
@@ -304,16 +321,24 @@ int TRUST_TOKEN_CLIENT_finish_redemption(TRUST_TOKEN_CLIENT *ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_MD_CTX md_ctx;
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
int sig_ok = EVP_DigestVerifyInit(&md_ctx, NULL, NULL, NULL, ctx->srr_key) &&
|
||||
EVP_DigestVerify(&md_ctx, CBS_data(&sig), CBS_len(&sig),
|
||||
CBS_data(&srr), CBS_len(&srr));
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
if (ctx->method->has_srr) {
|
||||
if (ctx->srr_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_NO_SRR_KEY_CONFIGURED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!sig_ok) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_SRR_SIGNATURE_ERROR);
|
||||
return 0;
|
||||
EVP_MD_CTX md_ctx;
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
int sig_ok =
|
||||
EVP_DigestVerifyInit(&md_ctx, NULL, NULL, NULL, ctx->srr_key) &&
|
||||
EVP_DigestVerify(&md_ctx, CBS_data(&sig), CBS_len(&sig), CBS_data(&srr),
|
||||
CBS_len(&srr));
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
|
||||
if (!sig_ok) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_SRR_SIGNATURE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *srr_buf = NULL, *sig_buf = NULL;
|
||||
@@ -326,8 +351,8 @@ int TRUST_TOKEN_CLIENT_finish_redemption(TRUST_TOKEN_CLIENT *ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_srr = srr_buf;
|
||||
*out_srr_len = srr_len;
|
||||
*out_rr = srr_buf;
|
||||
*out_rr_len = srr_len;
|
||||
*out_sig = sig_buf;
|
||||
*out_sig_len = sig_len;
|
||||
return 1;
|
||||
@@ -363,7 +388,8 @@ void TRUST_TOKEN_ISSUER_free(TRUST_TOKEN_ISSUER *ctx) {
|
||||
|
||||
int TRUST_TOKEN_ISSUER_add_key(TRUST_TOKEN_ISSUER *ctx, const uint8_t *key,
|
||||
size_t key_len) {
|
||||
if (ctx->num_keys == OPENSSL_ARRAY_SIZE(ctx->keys)) {
|
||||
if (ctx->num_keys == OPENSSL_ARRAY_SIZE(ctx->keys) ||
|
||||
ctx->num_keys >= ctx->method->max_keys) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_TOO_MANY_KEYS);
|
||||
return 0;
|
||||
}
|
||||
@@ -428,7 +454,8 @@ int TRUST_TOKEN_ISSUER_issue(const TRUST_TOKEN_ISSUER *ctx, uint8_t **out,
|
||||
|
||||
const struct trust_token_issuer_key_st *key =
|
||||
trust_token_issuer_get_key(ctx, public_metadata);
|
||||
if (key == NULL || private_metadata > 1) {
|
||||
if (key == NULL || private_metadata > 1 ||
|
||||
(!ctx->method->has_private_metadata && private_metadata != 0)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_METADATA);
|
||||
return 0;
|
||||
}
|
||||
@@ -597,16 +624,8 @@ int TRUST_TOKEN_ISSUER_redeem(const TRUST_TOKEN_ISSUER *ctx, uint8_t **out,
|
||||
SHA256_Update(&sha_ctx, CBS_data(&token_copy), CBS_len(&token_copy));
|
||||
SHA256_Final(token_hash, &sha_ctx);
|
||||
|
||||
uint8_t metadata_obfuscator;
|
||||
if (ctx->method->use_token_hash) {
|
||||
metadata_obfuscator =
|
||||
get_metadata_obfuscator(ctx->metadata_key, ctx->metadata_key_len,
|
||||
token_hash, sizeof(token_hash));
|
||||
} else {
|
||||
metadata_obfuscator =
|
||||
get_metadata_obfuscator(ctx->metadata_key, ctx->metadata_key_len,
|
||||
CBS_data(&client_data), CBS_len(&client_data));
|
||||
}
|
||||
uint8_t metadata_obfuscator = get_metadata_obfuscator(
|
||||
ctx->metadata_key, ctx->metadata_key_len, token_hash, sizeof(token_hash));
|
||||
|
||||
// The SRR is constructed as per the format described in
|
||||
// https://docs.google.com/document/d/1TNnya6B8pyomDK2F1R9CL3dY10OAmqWlnCxsWyOBDVQ/edit#heading=h.7mkzvhpqb8l5
|
||||
@@ -625,10 +644,7 @@ int TRUST_TOKEN_ISSUER_redeem(const TRUST_TOKEN_ISSUER *ctx, uint8_t **out,
|
||||
assert(strlen(kClientDataLabel) < strlen(kExpiryTimestampLabel));
|
||||
assert(strlen(kPublicLabel) < strlen(kPrivateLabel));
|
||||
|
||||
size_t map_entries = 3;
|
||||
if (ctx->method->use_token_hash) {
|
||||
map_entries = 4;
|
||||
}
|
||||
size_t map_entries = 4;
|
||||
|
||||
if (!CBB_init(&srr, 0) ||
|
||||
!add_cbor_map(&srr, map_entries) || // SRR map
|
||||
@@ -637,20 +653,10 @@ int TRUST_TOKEN_ISSUER_redeem(const TRUST_TOKEN_ISSUER *ctx, uint8_t **out,
|
||||
!add_cbor_text(&srr, kPublicLabel, strlen(kPublicLabel)) ||
|
||||
!add_cbor_int(&srr, public_metadata) ||
|
||||
!add_cbor_text(&srr, kPrivateLabel, strlen(kPrivateLabel)) ||
|
||||
!add_cbor_int(&srr, private_metadata ^ metadata_obfuscator)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ctx->method->use_token_hash) {
|
||||
if (!add_cbor_text(&srr, kTokenHashLabel, strlen(kTokenHashLabel)) ||
|
||||
!add_cbor_bytes(&srr, token_hash, sizeof(token_hash))) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!add_cbor_text(&srr, kClientDataLabel, strlen(kClientDataLabel)) ||
|
||||
!add_cbor_int(&srr, private_metadata ^ metadata_obfuscator) ||
|
||||
!add_cbor_text(&srr, kTokenHashLabel, strlen(kTokenHashLabel)) ||
|
||||
!add_cbor_bytes(&srr, token_hash, sizeof(token_hash)) ||
|
||||
!add_cbor_text(&srr, kClientDataLabel, strlen(kClientDataLabel)) ||
|
||||
!CBB_add_bytes(&srr, CBS_data(&client_data), CBS_len(&client_data)) ||
|
||||
!add_cbor_text(&srr, kExpiryTimestampLabel,
|
||||
strlen(kExpiryTimestampLabel)) ||
|
||||
|
||||
@@ -296,7 +296,7 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf,
|
||||
*/
|
||||
|
||||
static int do_dump(unsigned long lflags, char_io *io_ch, void *arg,
|
||||
ASN1_STRING *str)
|
||||
const ASN1_STRING *str)
|
||||
{
|
||||
/*
|
||||
* Placing the ASN1_STRING in a temp ASN1_TYPE allows the DER encoding to
|
||||
@@ -354,7 +354,7 @@ static const signed char tag2nbyte[] = {
|
||||
*/
|
||||
|
||||
static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
|
||||
ASN1_STRING *str)
|
||||
const ASN1_STRING *str)
|
||||
{
|
||||
int outlen, len;
|
||||
int type;
|
||||
@@ -446,7 +446,7 @@ static int do_indent(char_io *io_ch, void *arg, int indent)
|
||||
#define FN_WIDTH_LN 25
|
||||
#define FN_WIDTH_SN 10
|
||||
|
||||
static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
|
||||
static int do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n,
|
||||
int indent, unsigned long flags)
|
||||
{
|
||||
int i, prev = -1, orflags, cnt;
|
||||
@@ -584,7 +584,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
|
||||
|
||||
/* Wrappers round the main functions */
|
||||
|
||||
int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent,
|
||||
int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent,
|
||||
unsigned long flags)
|
||||
{
|
||||
if (flags == XN_FLAG_COMPAT)
|
||||
@@ -593,7 +593,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent,
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent,
|
||||
int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent,
|
||||
unsigned long flags)
|
||||
{
|
||||
if (flags == XN_FLAG_COMPAT) {
|
||||
@@ -610,13 +610,13 @@ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent,
|
||||
}
|
||||
#endif
|
||||
|
||||
int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
|
||||
int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags)
|
||||
{
|
||||
return do_print_ex(send_bio_chars, out, flags, str);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
|
||||
int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags)
|
||||
{
|
||||
return do_print_ex(send_fp_chars, fp, flags, str);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ typedef struct {
|
||||
int exp_count;
|
||||
} tag_exp_arg;
|
||||
|
||||
static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
|
||||
static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
|
||||
int *perr);
|
||||
static int bitstr_cb(const char *elem, int len, void *bitstr);
|
||||
static int asn1_cb(const char *elem, int len, void *bitstr);
|
||||
@@ -136,7 +136,7 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
|
||||
static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
|
||||
static int asn1_str2tag(const char *tagstr, int len);
|
||||
|
||||
ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf)
|
||||
ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf)
|
||||
{
|
||||
X509V3_CTX cnf;
|
||||
|
||||
@@ -147,7 +147,7 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf)
|
||||
return ASN1_generate_v3(str, &cnf);
|
||||
}
|
||||
|
||||
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
|
||||
ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf)
|
||||
{
|
||||
int err = 0;
|
||||
ASN1_TYPE *ret = generate_v3(str, cnf, 0, &err);
|
||||
@@ -156,7 +156,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
|
||||
static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
|
||||
int *perr)
|
||||
{
|
||||
ASN1_TYPE *ret;
|
||||
|
||||
@@ -91,10 +91,10 @@ int X509_CRL_print(BIO *out, X509_CRL *x)
|
||||
BIO_printf(out, "%8sIssuer: %s\n", "", p);
|
||||
OPENSSL_free(p);
|
||||
BIO_printf(out, "%8sLast Update: ", "");
|
||||
ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));
|
||||
ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x));
|
||||
BIO_printf(out, "\n%8sNext Update: ", "");
|
||||
if (X509_CRL_get_nextUpdate(x))
|
||||
ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));
|
||||
if (X509_CRL_get0_nextUpdate(x))
|
||||
ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x));
|
||||
else
|
||||
BIO_printf(out, "NONE");
|
||||
BIO_printf(out, "\n");
|
||||
|
||||
@@ -494,7 +494,7 @@ err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
|
||||
int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
|
||||
{
|
||||
char *s, *c, *b;
|
||||
int ret = 0, l, i;
|
||||
|
||||
@@ -65,73 +65,6 @@
|
||||
* it to avoid downstream churn. */
|
||||
OPENSSL_DECLARE_ERROR_REASON(X509, UNSUPPORTED_ALGORITHM)
|
||||
|
||||
int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version,
|
||||
int ptype, void *pval, uint8_t *penc, int penclen) {
|
||||
uint8_t **ppenc = NULL;
|
||||
if (version >= 0) {
|
||||
if (!ASN1_INTEGER_set(priv->version, version)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (penc) {
|
||||
int pmtype;
|
||||
ASN1_OCTET_STRING *oct;
|
||||
|
||||
oct = ASN1_OCTET_STRING_new();
|
||||
if (!oct) {
|
||||
return 0;
|
||||
}
|
||||
oct->data = penc;
|
||||
ppenc = &oct->data;
|
||||
oct->length = penclen;
|
||||
if (priv->broken == PKCS8_NO_OCTET) {
|
||||
pmtype = V_ASN1_SEQUENCE;
|
||||
} else {
|
||||
pmtype = V_ASN1_OCTET_STRING;
|
||||
}
|
||||
ASN1_TYPE_set(priv->pkey, pmtype, oct);
|
||||
}
|
||||
|
||||
if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) {
|
||||
/* If call fails do not swallow 'enc' */
|
||||
if (ppenc) {
|
||||
*ppenc = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, const uint8_t **pk, int *ppklen,
|
||||
X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8) {
|
||||
if (ppkalg) {
|
||||
*ppkalg = p8->pkeyalg->algorithm;
|
||||
}
|
||||
|
||||
if (p8->pkey->type == V_ASN1_OCTET_STRING) {
|
||||
p8->broken = PKCS8_OK;
|
||||
if (pk) {
|
||||
*pk = p8->pkey->value.octet_string->data;
|
||||
*ppklen = p8->pkey->value.octet_string->length;
|
||||
}
|
||||
} else if (p8->pkey->type == V_ASN1_SEQUENCE) {
|
||||
p8->broken = PKCS8_NO_OCTET;
|
||||
if (pk) {
|
||||
*pk = p8->pkey->value.sequence->data;
|
||||
*ppklen = p8->pkey->value.sequence->length;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pa) {
|
||||
*pa = p8->pkeyalg;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) {
|
||||
const uint8_t *s;
|
||||
int i, n;
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../x509v3/internal.h"
|
||||
|
||||
|
||||
int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
|
||||
@@ -130,7 +131,7 @@ int X509_CRL_match(const X509_CRL *a, const X509_CRL *b)
|
||||
return OPENSSL_memcmp(a->sha1_hash, b->sha1_hash, 20);
|
||||
}
|
||||
|
||||
X509_NAME *X509_get_issuer_name(X509 *a)
|
||||
X509_NAME *X509_get_issuer_name(const X509 *a)
|
||||
{
|
||||
return (a->cert_info->issuer);
|
||||
}
|
||||
@@ -145,7 +146,7 @@ unsigned long X509_issuer_name_hash_old(X509 *x)
|
||||
return (X509_NAME_hash_old(x->cert_info->issuer));
|
||||
}
|
||||
|
||||
X509_NAME *X509_get_subject_name(X509 *a)
|
||||
X509_NAME *X509_get_subject_name(const X509 *a)
|
||||
{
|
||||
return (a->cert_info->subject);
|
||||
}
|
||||
@@ -155,6 +156,11 @@ ASN1_INTEGER *X509_get_serialNumber(X509 *a)
|
||||
return (a->cert_info->serialNumber);
|
||||
}
|
||||
|
||||
const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x509)
|
||||
{
|
||||
return x509->cert_info->serialNumber;
|
||||
}
|
||||
|
||||
unsigned long X509_subject_name_hash(X509 *x)
|
||||
{
|
||||
return (X509_NAME_hash(x->cert_info->subject));
|
||||
@@ -175,12 +181,18 @@ unsigned long X509_subject_name_hash_old(X509 *x)
|
||||
*/
|
||||
int X509_cmp(const X509 *a, const X509 *b)
|
||||
{
|
||||
int rv;
|
||||
/* ensure hash is valid */
|
||||
X509_check_purpose((X509 *)a, -1, 0);
|
||||
X509_check_purpose((X509 *)b, -1, 0);
|
||||
/* Fill in the |sha1_hash| fields.
|
||||
*
|
||||
* TODO(davidben): This may fail, in which case the the hash will be all
|
||||
* zeros. This produces a consistent comparison (failures are sticky), but
|
||||
* not a good one. OpenSSL now returns -2, but this is not a consistent
|
||||
* comparison and may cause misbehaving sorts by transitivity. For now, we
|
||||
* retain the old OpenSSL behavior, which was to ignore the error. See
|
||||
* https://crbug.com/boringssl/355. */
|
||||
x509v3_cache_extensions((X509 *)a);
|
||||
x509v3_cache_extensions((X509 *)b);
|
||||
|
||||
rv = OPENSSL_memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
|
||||
int rv = OPENSSL_memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
|
||||
if (rv)
|
||||
return rv;
|
||||
/* Check for match against stored encoding too */
|
||||
|
||||
@@ -62,27 +62,28 @@
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
int X509_CRL_get_ext_count(X509_CRL *x)
|
||||
int X509_CRL_get_ext_count(const X509_CRL *x)
|
||||
{
|
||||
return (X509v3_get_ext_count(x->crl->extensions));
|
||||
}
|
||||
|
||||
int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos)
|
||||
int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_NID(x->crl->extensions, nid, lastpos));
|
||||
}
|
||||
|
||||
int X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos)
|
||||
int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, const ASN1_OBJECT *obj,
|
||||
int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_OBJ(x->crl->extensions, obj, lastpos));
|
||||
}
|
||||
|
||||
int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos)
|
||||
int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_critical(x->crl->extensions, crit, lastpos));
|
||||
}
|
||||
|
||||
X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc)
|
||||
X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc)
|
||||
{
|
||||
return (X509v3_get_ext(x->crl->extensions, loc));
|
||||
}
|
||||
@@ -92,7 +93,7 @@ X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
|
||||
return (X509v3_delete_ext(x->crl->extensions, loc));
|
||||
}
|
||||
|
||||
void *X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx)
|
||||
void *X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit, int *idx)
|
||||
{
|
||||
return X509V3_get_d2i(x->crl->extensions, nid, crit, idx);
|
||||
}
|
||||
@@ -108,28 +109,28 @@ int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
|
||||
return (X509v3_add_ext(&(x->crl->extensions), ex, loc) != NULL);
|
||||
}
|
||||
|
||||
int X509_get_ext_count(X509 *x)
|
||||
int X509_get_ext_count(const X509 *x)
|
||||
{
|
||||
return (X509v3_get_ext_count(x->cert_info->extensions));
|
||||
}
|
||||
|
||||
int X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
|
||||
int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_NID(x->cert_info->extensions, nid, lastpos));
|
||||
}
|
||||
|
||||
int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
|
||||
int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_OBJ(x->cert_info->extensions, obj, lastpos));
|
||||
}
|
||||
|
||||
int X509_get_ext_by_critical(X509 *x, int crit, int lastpos)
|
||||
int X509_get_ext_by_critical(const X509 *x, int crit, int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_critical
|
||||
(x->cert_info->extensions, crit, lastpos));
|
||||
}
|
||||
|
||||
X509_EXTENSION *X509_get_ext(X509 *x, int loc)
|
||||
X509_EXTENSION *X509_get_ext(const X509 *x, int loc)
|
||||
{
|
||||
return (X509v3_get_ext(x->cert_info->extensions, loc));
|
||||
}
|
||||
@@ -144,7 +145,7 @@ int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
|
||||
return (X509v3_add_ext(&(x->cert_info->extensions), ex, loc) != NULL);
|
||||
}
|
||||
|
||||
void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
|
||||
void *X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx)
|
||||
{
|
||||
return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx);
|
||||
}
|
||||
@@ -156,28 +157,29 @@ int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
|
||||
flags);
|
||||
}
|
||||
|
||||
int X509_REVOKED_get_ext_count(X509_REVOKED *x)
|
||||
int X509_REVOKED_get_ext_count(const X509_REVOKED *x)
|
||||
{
|
||||
return (X509v3_get_ext_count(x->extensions));
|
||||
}
|
||||
|
||||
int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos)
|
||||
int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_NID(x->extensions, nid, lastpos));
|
||||
}
|
||||
|
||||
int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj,
|
||||
int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, const ASN1_OBJECT *obj,
|
||||
int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_OBJ(x->extensions, obj, lastpos));
|
||||
}
|
||||
|
||||
int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos)
|
||||
int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, int crit,
|
||||
int lastpos)
|
||||
{
|
||||
return (X509v3_get_ext_by_critical(x->extensions, crit, lastpos));
|
||||
}
|
||||
|
||||
X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc)
|
||||
X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc)
|
||||
{
|
||||
return (X509v3_get_ext(x->extensions, loc));
|
||||
}
|
||||
@@ -192,7 +194,8 @@ int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
|
||||
return (X509v3_add_ext(&(x->extensions), ex, loc) != NULL);
|
||||
}
|
||||
|
||||
void *X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx)
|
||||
void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *x, int nid, int *crit,
|
||||
int *idx)
|
||||
{
|
||||
return X509V3_get_d2i(x->extensions, nid, crit, idx);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
#define NAME_ONELINE_MAX (1024 * 1024)
|
||||
|
||||
char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
|
||||
char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
|
||||
{
|
||||
X509_NAME_ENTRY *ne;
|
||||
size_t i;
|
||||
|
||||
@@ -107,6 +107,16 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
long X509_REQ_get_version(const X509_REQ *req)
|
||||
{
|
||||
return ASN1_INTEGER_get(req->req_info->version);
|
||||
}
|
||||
|
||||
X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req)
|
||||
{
|
||||
return req->req_info->subject;
|
||||
}
|
||||
|
||||
EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)
|
||||
{
|
||||
if ((req == NULL) || (req->req_info == NULL))
|
||||
|
||||
@@ -60,6 +60,16 @@
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
|
||||
long X509_get_version(const X509 *x509)
|
||||
{
|
||||
return ASN1_INTEGER_get(x509->cert_info->version);
|
||||
}
|
||||
|
||||
X509_CINF *X509_get_cert_info(const X509 *x509)
|
||||
{
|
||||
return x509->cert_info;
|
||||
}
|
||||
|
||||
int X509_set_version(X509 *x, long version)
|
||||
{
|
||||
if (x == NULL)
|
||||
@@ -107,7 +117,7 @@ int X509_set_subject_name(X509 *x, X509_NAME *name)
|
||||
return (X509_NAME_set(&x->cert_info->subject, name));
|
||||
}
|
||||
|
||||
int X509_set_notBefore(X509 *x, const ASN1_TIME *tm)
|
||||
int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm)
|
||||
{
|
||||
ASN1_TIME *in;
|
||||
|
||||
@@ -124,6 +134,11 @@ int X509_set_notBefore(X509 *x, const ASN1_TIME *tm)
|
||||
return (in != NULL);
|
||||
}
|
||||
|
||||
int X509_set_notBefore(X509 *x, const ASN1_TIME *tm)
|
||||
{
|
||||
return X509_set1_notBefore(x, tm);
|
||||
}
|
||||
|
||||
const ASN1_TIME *X509_get0_notBefore(const X509 *x)
|
||||
{
|
||||
return x->cert_info->validity->notBefore;
|
||||
@@ -137,7 +152,15 @@ ASN1_TIME *X509_getm_notBefore(X509 *x)
|
||||
return x->cert_info->validity->notBefore;
|
||||
}
|
||||
|
||||
int X509_set_notAfter(X509 *x, const ASN1_TIME *tm)
|
||||
ASN1_TIME *X509_get_notBefore(const X509 *x509)
|
||||
{
|
||||
// In OpenSSL, this function is an alias for |X509_getm_notBefore|, but our
|
||||
// |X509_getm_notBefore| is const-correct. |X509_get_notBefore| was
|
||||
// originally a macro, so it needs to capture both get0 and getm use cases.
|
||||
return x509->cert_info->validity->notBefore;
|
||||
}
|
||||
|
||||
int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm)
|
||||
{
|
||||
ASN1_TIME *in;
|
||||
|
||||
@@ -154,6 +177,11 @@ int X509_set_notAfter(X509 *x, const ASN1_TIME *tm)
|
||||
return (in != NULL);
|
||||
}
|
||||
|
||||
int X509_set_notAfter(X509 *x, const ASN1_TIME *tm)
|
||||
{
|
||||
return X509_set1_notAfter(x, tm);
|
||||
}
|
||||
|
||||
const ASN1_TIME *X509_get0_notAfter(const X509 *x)
|
||||
{
|
||||
return x->cert_info->validity->notAfter;
|
||||
@@ -167,6 +195,25 @@ ASN1_TIME *X509_getm_notAfter(X509 *x)
|
||||
return x->cert_info->validity->notAfter;
|
||||
}
|
||||
|
||||
ASN1_TIME *X509_get_notAfter(const X509 *x509)
|
||||
{
|
||||
// In OpenSSL, this function is an alias for |X509_getm_notAfter|, but our
|
||||
// |X509_getm_notAfter| is const-correct. |X509_get_notAfter| was
|
||||
// originally a macro, so it needs to capture both get0 and getm use cases.
|
||||
return x509->cert_info->validity->notAfter;
|
||||
}
|
||||
|
||||
void X509_get0_uids(const X509 *x509, const ASN1_BIT_STRING **out_issuer_uid,
|
||||
const ASN1_BIT_STRING **out_subject_uid)
|
||||
{
|
||||
if (out_issuer_uid != NULL) {
|
||||
*out_issuer_uid = x509->cert_info->issuerUID;
|
||||
}
|
||||
if (out_subject_uid != NULL) {
|
||||
*out_subject_uid = x509->cert_info->subjectUID;
|
||||
}
|
||||
}
|
||||
|
||||
int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
|
||||
{
|
||||
if ((x == NULL) || (x->cert_info == NULL))
|
||||
@@ -174,7 +221,7 @@ int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
|
||||
return (X509_PUBKEY_set(&(x->cert_info->key), pkey));
|
||||
}
|
||||
|
||||
STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x)
|
||||
const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x)
|
||||
{
|
||||
return x->cert_info->extensions;
|
||||
}
|
||||
@@ -183,3 +230,18 @@ const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x)
|
||||
{
|
||||
return x->cert_info->signature;
|
||||
}
|
||||
|
||||
void X509_CINF_set_modified(X509_CINF *cinf)
|
||||
{
|
||||
cinf->enc.modified = 1;
|
||||
}
|
||||
|
||||
const X509_ALGOR *X509_CINF_get_signature(const X509_CINF *cinf)
|
||||
{
|
||||
return cinf->signature;
|
||||
}
|
||||
|
||||
X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x509)
|
||||
{
|
||||
return x509->cert_info->key;
|
||||
}
|
||||
@@ -59,6 +59,8 @@
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
#include "../x509v3/internal.h"
|
||||
|
||||
static int tr_cmp(const X509_TRUST **a, const X509_TRUST **b);
|
||||
static void trtable_free(X509_TRUST *p);
|
||||
|
||||
@@ -258,17 +260,17 @@ void X509_TRUST_cleanup(void)
|
||||
trtable = NULL;
|
||||
}
|
||||
|
||||
int X509_TRUST_get_flags(X509_TRUST *xp)
|
||||
int X509_TRUST_get_flags(const X509_TRUST *xp)
|
||||
{
|
||||
return xp->flags;
|
||||
}
|
||||
|
||||
char *X509_TRUST_get0_name(X509_TRUST *xp)
|
||||
char *X509_TRUST_get0_name(const X509_TRUST *xp)
|
||||
{
|
||||
return xp->name;
|
||||
}
|
||||
|
||||
int X509_TRUST_get_trust(X509_TRUST *xp)
|
||||
int X509_TRUST_get_trust(const X509_TRUST *xp)
|
||||
{
|
||||
return xp->trust;
|
||||
}
|
||||
@@ -293,7 +295,8 @@ static int trust_1oid(X509_TRUST *trust, X509 *x, int flags)
|
||||
|
||||
static int trust_compat(X509_TRUST *trust, X509 *x, int flags)
|
||||
{
|
||||
X509_check_purpose(x, -1, 0);
|
||||
if (!x509v3_cache_extensions(x))
|
||||
return X509_TRUST_UNTRUSTED;
|
||||
if (x->ex_flags & EXFLAG_SS)
|
||||
return X509_TRUST_TRUSTED;
|
||||
else
|
||||
|
||||
@@ -56,144 +56,144 @@
|
||||
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
|
||||
const char *X509_verify_cert_error_string(long n)
|
||||
const char *X509_verify_cert_error_string(long err)
|
||||
{
|
||||
switch ((int)n) {
|
||||
switch (err) {
|
||||
case X509_V_OK:
|
||||
return ("ok");
|
||||
return "ok";
|
||||
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
|
||||
return ("unable to get issuer certificate");
|
||||
return "unable to get issuer certificate";
|
||||
case X509_V_ERR_UNABLE_TO_GET_CRL:
|
||||
return ("unable to get certificate CRL");
|
||||
return "unable to get certificate CRL";
|
||||
case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
|
||||
return ("unable to decrypt certificate's signature");
|
||||
return "unable to decrypt certificate's signature";
|
||||
case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
|
||||
return ("unable to decrypt CRL's signature");
|
||||
return "unable to decrypt CRL's signature";
|
||||
case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
|
||||
return ("unable to decode issuer public key");
|
||||
return "unable to decode issuer public key";
|
||||
case X509_V_ERR_CERT_SIGNATURE_FAILURE:
|
||||
return ("certificate signature failure");
|
||||
return "certificate signature failure";
|
||||
case X509_V_ERR_CRL_SIGNATURE_FAILURE:
|
||||
return ("CRL signature failure");
|
||||
return "CRL signature failure";
|
||||
case X509_V_ERR_CERT_NOT_YET_VALID:
|
||||
return ("certificate is not yet valid");
|
||||
return "certificate is not yet valid";
|
||||
case X509_V_ERR_CRL_NOT_YET_VALID:
|
||||
return ("CRL is not yet valid");
|
||||
return "CRL is not yet valid";
|
||||
case X509_V_ERR_CERT_HAS_EXPIRED:
|
||||
return ("certificate has expired");
|
||||
return "certificate has expired";
|
||||
case X509_V_ERR_CRL_HAS_EXPIRED:
|
||||
return ("CRL has expired");
|
||||
return "CRL has expired";
|
||||
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
|
||||
return ("format error in certificate's notBefore field");
|
||||
return "format error in certificate's notBefore field";
|
||||
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
|
||||
return ("format error in certificate's notAfter field");
|
||||
return "format error in certificate's notAfter field";
|
||||
case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
|
||||
return ("format error in CRL's lastUpdate field");
|
||||
return "format error in CRL's lastUpdate field";
|
||||
case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
|
||||
return ("format error in CRL's nextUpdate field");
|
||||
return "format error in CRL's nextUpdate field";
|
||||
case X509_V_ERR_OUT_OF_MEM:
|
||||
return ("out of memory");
|
||||
return "out of memory";
|
||||
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
|
||||
return ("self signed certificate");
|
||||
return "self signed certificate";
|
||||
case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
|
||||
return ("self signed certificate in certificate chain");
|
||||
return "self signed certificate in certificate chain";
|
||||
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
|
||||
return ("unable to get local issuer certificate");
|
||||
return "unable to get local issuer certificate";
|
||||
case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
|
||||
return ("unable to verify the first certificate");
|
||||
return "unable to verify the first certificate";
|
||||
case X509_V_ERR_CERT_CHAIN_TOO_LONG:
|
||||
return ("certificate chain too long");
|
||||
return "certificate chain too long";
|
||||
case X509_V_ERR_CERT_REVOKED:
|
||||
return ("certificate revoked");
|
||||
return "certificate revoked";
|
||||
case X509_V_ERR_INVALID_CA:
|
||||
return ("invalid CA certificate");
|
||||
return "invalid CA certificate";
|
||||
case X509_V_ERR_INVALID_NON_CA:
|
||||
return ("invalid non-CA certificate (has CA markings)");
|
||||
return "invalid non-CA certificate (has CA markings)";
|
||||
case X509_V_ERR_PATH_LENGTH_EXCEEDED:
|
||||
return ("path length constraint exceeded");
|
||||
return "path length constraint exceeded";
|
||||
case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
|
||||
return ("proxy path length constraint exceeded");
|
||||
return "proxy path length constraint exceeded";
|
||||
case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
|
||||
return
|
||||
("proxy certificates not allowed, please set the appropriate flag");
|
||||
"proxy certificates not allowed, please set the appropriate flag";
|
||||
case X509_V_ERR_INVALID_PURPOSE:
|
||||
return ("unsupported certificate purpose");
|
||||
return "unsupported certificate purpose";
|
||||
case X509_V_ERR_CERT_UNTRUSTED:
|
||||
return ("certificate not trusted");
|
||||
return "certificate not trusted";
|
||||
case X509_V_ERR_CERT_REJECTED:
|
||||
return ("certificate rejected");
|
||||
return "certificate rejected";
|
||||
case X509_V_ERR_APPLICATION_VERIFICATION:
|
||||
return ("application verification failure");
|
||||
return "application verification failure";
|
||||
case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
|
||||
return ("subject issuer mismatch");
|
||||
return "subject issuer mismatch";
|
||||
case X509_V_ERR_AKID_SKID_MISMATCH:
|
||||
return ("authority and subject key identifier mismatch");
|
||||
return "authority and subject key identifier mismatch";
|
||||
case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
|
||||
return ("authority and issuer serial number mismatch");
|
||||
return "authority and issuer serial number mismatch";
|
||||
case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
|
||||
return ("key usage does not include certificate signing");
|
||||
return "key usage does not include certificate signing";
|
||||
case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
|
||||
return ("unable to get CRL issuer certificate");
|
||||
return "unable to get CRL issuer certificate";
|
||||
case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
|
||||
return ("unhandled critical extension");
|
||||
return "unhandled critical extension";
|
||||
case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
|
||||
return ("key usage does not include CRL signing");
|
||||
return "key usage does not include CRL signing";
|
||||
case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE:
|
||||
return ("key usage does not include digital signature");
|
||||
return "key usage does not include digital signature";
|
||||
case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
|
||||
return ("unhandled critical CRL extension");
|
||||
return "unhandled critical CRL extension";
|
||||
case X509_V_ERR_INVALID_EXTENSION:
|
||||
return ("invalid or inconsistent certificate extension");
|
||||
return "invalid or inconsistent certificate extension";
|
||||
case X509_V_ERR_INVALID_POLICY_EXTENSION:
|
||||
return ("invalid or inconsistent certificate policy extension");
|
||||
return "invalid or inconsistent certificate policy extension";
|
||||
case X509_V_ERR_NO_EXPLICIT_POLICY:
|
||||
return ("no explicit policy");
|
||||
return "no explicit policy";
|
||||
case X509_V_ERR_DIFFERENT_CRL_SCOPE:
|
||||
return ("Different CRL scope");
|
||||
return "Different CRL scope";
|
||||
case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE:
|
||||
return ("Unsupported extension feature");
|
||||
return "Unsupported extension feature";
|
||||
case X509_V_ERR_UNNESTED_RESOURCE:
|
||||
return ("RFC 3779 resource not subset of parent's resources");
|
||||
return "RFC 3779 resource not subset of parent's resources";
|
||||
|
||||
case X509_V_ERR_PERMITTED_VIOLATION:
|
||||
return ("permitted subtree violation");
|
||||
return "permitted subtree violation";
|
||||
case X509_V_ERR_EXCLUDED_VIOLATION:
|
||||
return ("excluded subtree violation");
|
||||
return "excluded subtree violation";
|
||||
case X509_V_ERR_SUBTREE_MINMAX:
|
||||
return ("name constraints minimum and maximum not supported");
|
||||
return "name constraints minimum and maximum not supported";
|
||||
case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:
|
||||
return ("unsupported name constraint type");
|
||||
return "unsupported name constraint type";
|
||||
case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX:
|
||||
return ("unsupported or invalid name constraint syntax");
|
||||
return "unsupported or invalid name constraint syntax";
|
||||
case X509_V_ERR_UNSUPPORTED_NAME_SYNTAX:
|
||||
return ("unsupported or invalid name syntax");
|
||||
return "unsupported or invalid name syntax";
|
||||
case X509_V_ERR_CRL_PATH_VALIDATION_ERROR:
|
||||
return ("CRL path validation error");
|
||||
return "CRL path validation error";
|
||||
|
||||
case X509_V_ERR_SUITE_B_INVALID_VERSION:
|
||||
return ("Suite B: certificate version invalid");
|
||||
return "Suite B: certificate version invalid";
|
||||
case X509_V_ERR_SUITE_B_INVALID_ALGORITHM:
|
||||
return ("Suite B: invalid public key algorithm");
|
||||
return "Suite B: invalid public key algorithm";
|
||||
case X509_V_ERR_SUITE_B_INVALID_CURVE:
|
||||
return ("Suite B: invalid ECC curve");
|
||||
return "Suite B: invalid ECC curve";
|
||||
case X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM:
|
||||
return ("Suite B: invalid signature algorithm");
|
||||
return "Suite B: invalid signature algorithm";
|
||||
case X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED:
|
||||
return ("Suite B: curve not allowed for this LOS");
|
||||
return "Suite B: curve not allowed for this LOS";
|
||||
case X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256:
|
||||
return ("Suite B: cannot sign P-384 with P-256");
|
||||
return "Suite B: cannot sign P-384 with P-256";
|
||||
|
||||
case X509_V_ERR_HOSTNAME_MISMATCH:
|
||||
return ("Hostname mismatch");
|
||||
return "Hostname mismatch";
|
||||
case X509_V_ERR_EMAIL_MISMATCH:
|
||||
return ("Email address mismatch");
|
||||
return "Email address mismatch";
|
||||
case X509_V_ERR_IP_ADDRESS_MISMATCH:
|
||||
return ("IP address mismatch");
|
||||
return "IP address mismatch";
|
||||
|
||||
case X509_V_ERR_INVALID_CALL:
|
||||
return ("Invalid certificate verification context");
|
||||
return "Invalid certificate verification context";
|
||||
case X509_V_ERR_STORE_LOOKUP:
|
||||
return ("Issuer certificate lookup error");
|
||||
return "Issuer certificate lookup error";
|
||||
|
||||
case X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS:
|
||||
return "Issuer has name constraints but leaf has no SANs";
|
||||
|
||||
@@ -181,7 +181,7 @@ STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
|
||||
|
||||
X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
|
||||
int crit,
|
||||
ASN1_OCTET_STRING *data)
|
||||
const ASN1_OCTET_STRING *data)
|
||||
{
|
||||
const ASN1_OBJECT *obj;
|
||||
X509_EXTENSION *ret;
|
||||
@@ -197,7 +197,7 @@ X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
|
||||
|
||||
X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
|
||||
const ASN1_OBJECT *obj, int crit,
|
||||
ASN1_OCTET_STRING *data)
|
||||
const ASN1_OCTET_STRING *data)
|
||||
{
|
||||
X509_EXTENSION *ret;
|
||||
|
||||
@@ -242,7 +242,7 @@ int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)
|
||||
return (1);
|
||||
}
|
||||
|
||||
int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
|
||||
int X509_EXTENSION_set_data(X509_EXTENSION *ex, const ASN1_OCTET_STRING *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
@@ -146,14 +146,16 @@ static int null_callback(int ok, X509_STORE_CTX *e)
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* Return 1 is a certificate is self signed */
|
||||
static int cert_self_signed(X509 *x)
|
||||
/* cert_self_signed checks if |x| is self-signed. If |x| is valid, it returns
|
||||
* one and sets |*out_is_self_signed| to the result. If |x| is invalid, it
|
||||
* returns zero. */
|
||||
static int cert_self_signed(X509 *x, int *out_is_self_signed)
|
||||
{
|
||||
X509_check_purpose(x, -1, 0);
|
||||
if (x->ex_flags & EXFLAG_SS)
|
||||
return 1;
|
||||
else
|
||||
if (!x509v3_cache_extensions(x)) {
|
||||
return 0;
|
||||
}
|
||||
*out_is_self_signed = (x->ex_flags & EXFLAG_SS) != 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Given a certificate try and find an exact match in the store */
|
||||
@@ -263,8 +265,14 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
|
||||
* X509_V_ERR_CERT_CHAIN_TOO_LONG error code
|
||||
* later. */
|
||||
|
||||
int is_self_signed;
|
||||
if (!cert_self_signed(x, &is_self_signed)) {
|
||||
ctx->error = X509_V_ERR_INVALID_EXTENSION;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* If we are self signed, we break */
|
||||
if (cert_self_signed(x))
|
||||
if (is_self_signed)
|
||||
break;
|
||||
/*
|
||||
* If asked see if we can find issuer in trusted store first
|
||||
@@ -323,7 +331,14 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
|
||||
*/
|
||||
i = sk_X509_num(ctx->chain);
|
||||
x = sk_X509_value(ctx->chain, i - 1);
|
||||
if (cert_self_signed(x)) {
|
||||
|
||||
int is_self_signed;
|
||||
if (!cert_self_signed(x, &is_self_signed)) {
|
||||
ctx->error = X509_V_ERR_INVALID_EXTENSION;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (is_self_signed) {
|
||||
/* we have a self signed certificate */
|
||||
if (sk_X509_num(ctx->chain) == 1) {
|
||||
/*
|
||||
@@ -368,8 +383,12 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
|
||||
/* If we have enough, we break */
|
||||
if (depth < num)
|
||||
break;
|
||||
if (!cert_self_signed(x, &is_self_signed)) {
|
||||
ctx->error = X509_V_ERR_INVALID_EXTENSION;
|
||||
goto end;
|
||||
}
|
||||
/* If we are self signed, we break */
|
||||
if (cert_self_signed(x))
|
||||
if (is_self_signed)
|
||||
break;
|
||||
ok = ctx->get_issuer(&xtmp, ctx, x);
|
||||
|
||||
@@ -1018,7 +1037,7 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
|
||||
else
|
||||
ptime = NULL;
|
||||
|
||||
i = X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
|
||||
i = X509_cmp_time(X509_CRL_get0_lastUpdate(crl), ptime);
|
||||
if (i == 0) {
|
||||
if (!notify)
|
||||
return 0;
|
||||
@@ -1035,8 +1054,8 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (X509_CRL_get_nextUpdate(crl)) {
|
||||
i = X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime);
|
||||
if (X509_CRL_get0_nextUpdate(crl)) {
|
||||
i = X509_cmp_time(X509_CRL_get0_nextUpdate(crl), ptime);
|
||||
|
||||
if (i == 0) {
|
||||
if (!notify)
|
||||
@@ -1081,8 +1100,8 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
|
||||
/* If current CRL is equivalent use it if it is newer */
|
||||
if (crl_score == best_score && best_crl != NULL) {
|
||||
int day, sec;
|
||||
if (ASN1_TIME_diff(&day, &sec, X509_CRL_get_lastUpdate(best_crl),
|
||||
X509_CRL_get_lastUpdate(crl)) == 0)
|
||||
if (ASN1_TIME_diff(&day, &sec, X509_CRL_get0_lastUpdate(best_crl),
|
||||
X509_CRL_get0_lastUpdate(crl)) == 0)
|
||||
continue;
|
||||
/*
|
||||
* ASN1_TIME_diff never returns inconsistent signs for |day|
|
||||
@@ -2039,9 +2058,9 @@ X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer,
|
||||
if (!X509_CRL_set_issuer_name(crl, X509_CRL_get_issuer(newer)))
|
||||
goto memerr;
|
||||
|
||||
if (!X509_CRL_set_lastUpdate(crl, X509_CRL_get_lastUpdate(newer)))
|
||||
if (!X509_CRL_set1_lastUpdate(crl, X509_CRL_get0_lastUpdate(newer)))
|
||||
goto memerr;
|
||||
if (!X509_CRL_set_nextUpdate(crl, X509_CRL_get_nextUpdate(newer)))
|
||||
if (!X509_CRL_set1_nextUpdate(crl, X509_CRL_get0_nextUpdate(newer)))
|
||||
goto memerr;
|
||||
|
||||
/* Set base CRL number: must be critical */
|
||||
@@ -2288,8 +2307,6 @@ void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
|
||||
int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
|
||||
STACK_OF(X509) *chain)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
X509_STORE_CTX_zero(ctx);
|
||||
ctx->ctx = store;
|
||||
ctx->cert = x509;
|
||||
@@ -2297,78 +2314,74 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
|
||||
|
||||
CRYPTO_new_ex_data(&ctx->ex_data);
|
||||
|
||||
if (store == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_PASSED_NULL_PARAMETER);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ctx->param = X509_VERIFY_PARAM_new();
|
||||
if (!ctx->param)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Inherit callbacks and flags from X509_STORE if not set use defaults.
|
||||
* Inherit callbacks and flags from X509_STORE.
|
||||
*/
|
||||
|
||||
if (store)
|
||||
ret = X509_VERIFY_PARAM_inherit(ctx->param, store->param);
|
||||
else
|
||||
ctx->param->inh_flags |= X509_VP_FLAG_DEFAULT | X509_VP_FLAG_ONCE;
|
||||
ctx->verify_cb = store->verify_cb;
|
||||
ctx->cleanup = store->cleanup;
|
||||
|
||||
if (store) {
|
||||
ctx->verify_cb = store->verify_cb;
|
||||
ctx->cleanup = store->cleanup;
|
||||
} else
|
||||
ctx->cleanup = 0;
|
||||
|
||||
if (ret)
|
||||
ret = X509_VERIFY_PARAM_inherit(ctx->param,
|
||||
X509_VERIFY_PARAM_lookup("default"));
|
||||
|
||||
if (ret == 0)
|
||||
if (!X509_VERIFY_PARAM_inherit(ctx->param, store->param) ||
|
||||
!X509_VERIFY_PARAM_inherit(ctx->param,
|
||||
X509_VERIFY_PARAM_lookup("default"))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (store && store->check_issued)
|
||||
if (store->check_issued)
|
||||
ctx->check_issued = store->check_issued;
|
||||
else
|
||||
ctx->check_issued = check_issued;
|
||||
|
||||
if (store && store->get_issuer)
|
||||
if (store->get_issuer)
|
||||
ctx->get_issuer = store->get_issuer;
|
||||
else
|
||||
ctx->get_issuer = X509_STORE_CTX_get1_issuer;
|
||||
|
||||
if (store && store->verify_cb)
|
||||
if (store->verify_cb)
|
||||
ctx->verify_cb = store->verify_cb;
|
||||
else
|
||||
ctx->verify_cb = null_callback;
|
||||
|
||||
if (store && store->verify)
|
||||
if (store->verify)
|
||||
ctx->verify = store->verify;
|
||||
else
|
||||
ctx->verify = internal_verify;
|
||||
|
||||
if (store && store->check_revocation)
|
||||
if (store->check_revocation)
|
||||
ctx->check_revocation = store->check_revocation;
|
||||
else
|
||||
ctx->check_revocation = check_revocation;
|
||||
|
||||
if (store && store->get_crl)
|
||||
if (store->get_crl)
|
||||
ctx->get_crl = store->get_crl;
|
||||
else
|
||||
ctx->get_crl = NULL;
|
||||
|
||||
if (store && store->check_crl)
|
||||
if (store->check_crl)
|
||||
ctx->check_crl = store->check_crl;
|
||||
else
|
||||
ctx->check_crl = check_crl;
|
||||
|
||||
if (store && store->cert_crl)
|
||||
if (store->cert_crl)
|
||||
ctx->cert_crl = store->cert_crl;
|
||||
else
|
||||
ctx->cert_crl = cert_crl;
|
||||
|
||||
if (store && store->lookup_certs)
|
||||
if (store->lookup_certs)
|
||||
ctx->lookup_certs = store->lookup_certs;
|
||||
else
|
||||
ctx->lookup_certs = X509_STORE_get1_certs;
|
||||
|
||||
if (store && store->lookup_crls)
|
||||
if (store->lookup_crls)
|
||||
ctx->lookup_crls = store->lookup_crls;
|
||||
else
|
||||
ctx->lookup_crls = X509_STORE_get1_crls;
|
||||
|
||||
@@ -79,7 +79,7 @@ int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
|
||||
return (X509_NAME_set(&x->crl->issuer, name));
|
||||
}
|
||||
|
||||
int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
|
||||
int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
|
||||
{
|
||||
ASN1_TIME *in;
|
||||
|
||||
@@ -96,7 +96,7 @@ int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
|
||||
return (in != NULL);
|
||||
}
|
||||
|
||||
int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
|
||||
int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
|
||||
{
|
||||
ASN1_TIME *in;
|
||||
|
||||
@@ -135,6 +135,11 @@ int X509_CRL_up_ref(X509_CRL *crl)
|
||||
return 1;
|
||||
}
|
||||
|
||||
long X509_CRL_get_version(const X509_CRL *crl)
|
||||
{
|
||||
return ASN1_INTEGER_get(crl->crl->version);
|
||||
}
|
||||
|
||||
const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl)
|
||||
{
|
||||
return crl->crl->lastUpdate;
|
||||
@@ -145,6 +150,31 @@ const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl)
|
||||
return crl->crl->nextUpdate;
|
||||
}
|
||||
|
||||
ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl)
|
||||
{
|
||||
return crl->crl->lastUpdate;
|
||||
}
|
||||
|
||||
ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl)
|
||||
{
|
||||
return crl->crl->nextUpdate;
|
||||
}
|
||||
|
||||
X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl)
|
||||
{
|
||||
return crl->crl->issuer;
|
||||
}
|
||||
|
||||
STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl)
|
||||
{
|
||||
return crl->crl->revoked;
|
||||
}
|
||||
|
||||
const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl)
|
||||
{
|
||||
return crl->crl->extensions;
|
||||
}
|
||||
|
||||
void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
|
||||
const X509_ALGOR **palg)
|
||||
{
|
||||
@@ -203,6 +233,12 @@ int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
|
||||
return (in != NULL);
|
||||
}
|
||||
|
||||
const STACK_OF(X509_EXTENSION) *
|
||||
X509_REVOKED_get0_extensions(const X509_REVOKED *r)
|
||||
{
|
||||
return r->extensions;
|
||||
}
|
||||
|
||||
int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp)
|
||||
{
|
||||
crl->crl->enc.modified = 1;
|
||||
|
||||
@@ -66,7 +66,8 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
|
||||
int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, char *buf,
|
||||
int len)
|
||||
{
|
||||
const ASN1_OBJECT *obj;
|
||||
|
||||
@@ -76,7 +77,7 @@ int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
|
||||
return (X509_NAME_get_text_by_OBJ(name, obj, buf, len));
|
||||
}
|
||||
|
||||
int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj,
|
||||
int X509_NAME_get_text_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj,
|
||||
char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
@@ -94,14 +95,14 @@ int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj,
|
||||
return (i);
|
||||
}
|
||||
|
||||
int X509_NAME_entry_count(X509_NAME *name)
|
||||
int X509_NAME_entry_count(const X509_NAME *name)
|
||||
{
|
||||
if (name == NULL)
|
||||
return (0);
|
||||
return (sk_X509_NAME_ENTRY_num(name->entries));
|
||||
}
|
||||
|
||||
int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
|
||||
int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, int lastpos)
|
||||
{
|
||||
const ASN1_OBJECT *obj;
|
||||
|
||||
@@ -112,7 +113,7 @@ int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
|
||||
}
|
||||
|
||||
/* NOTE: you should be passsing -1, not 0 as lastpos */
|
||||
int X509_NAME_get_index_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj,
|
||||
int X509_NAME_get_index_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj,
|
||||
int lastpos)
|
||||
{
|
||||
int n;
|
||||
@@ -133,7 +134,7 @@ int X509_NAME_get_index_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj,
|
||||
return (-1);
|
||||
}
|
||||
|
||||
X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
|
||||
X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc)
|
||||
{
|
||||
if (name == NULL || loc < 0
|
||||
|| sk_X509_NAME_ENTRY_num(name->entries) <= (size_t)loc)
|
||||
@@ -374,14 +375,14 @@ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
|
||||
return (1);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
|
||||
ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne)
|
||||
{
|
||||
if (ne == NULL)
|
||||
return (NULL);
|
||||
return (ne->object);
|
||||
}
|
||||
|
||||
ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
|
||||
ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne)
|
||||
{
|
||||
if (ne == NULL)
|
||||
return (NULL);
|
||||
|
||||
@@ -66,20 +66,20 @@
|
||||
#include <CCryptoBoringSSL_rsa.h>
|
||||
#include <CCryptoBoringSSL_stack.h>
|
||||
|
||||
int X509_verify(X509 *a, EVP_PKEY *r)
|
||||
int X509_verify(X509 *x509, EVP_PKEY *pkey)
|
||||
{
|
||||
if (X509_ALGOR_cmp(a->sig_alg, a->cert_info->signature)) {
|
||||
if (X509_ALGOR_cmp(x509->sig_alg, x509->cert_info->signature)) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_SIGNATURE_ALGORITHM_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
return (ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), a->sig_alg,
|
||||
a->signature, a->cert_info, r));
|
||||
return ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), x509->sig_alg,
|
||||
x509->signature, x509->cert_info, pkey);
|
||||
}
|
||||
|
||||
int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
|
||||
int X509_REQ_verify(X509_REQ *req, EVP_PKEY *pkey)
|
||||
{
|
||||
return (ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO),
|
||||
a->sig_alg, a->signature, a->req_info, r));
|
||||
return ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO),
|
||||
req->sig_alg, req->signature, req->req_info, pkey);
|
||||
}
|
||||
|
||||
int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
|
||||
@@ -131,10 +131,10 @@ int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
|
||||
x->signature, x->spkac, pkey, md));
|
||||
}
|
||||
|
||||
int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
|
||||
int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *spki, EVP_PKEY *pkey)
|
||||
{
|
||||
return (ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,
|
||||
x->signature, x->spkac, pkey));
|
||||
return (ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), spki->sig_algor,
|
||||
spki->signature, spki->spkac, pkey));
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
|
||||
@@ -86,7 +86,7 @@ struct x509_crl_method_st {
|
||||
};
|
||||
|
||||
static int X509_REVOKED_cmp(const X509_REVOKED **a, const X509_REVOKED **b);
|
||||
static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
|
||||
static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
|
||||
|
||||
ASN1_SEQUENCE(X509_REVOKED) = {
|
||||
ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER),
|
||||
@@ -126,6 +126,9 @@ static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
* affect the output of X509_CRL_print().
|
||||
*/
|
||||
case ASN1_OP_D2I_POST:
|
||||
/* TODO(davidben): Check that default |versions| are never encoded and
|
||||
* that |extensions| is only present in v2. */
|
||||
|
||||
(void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp);
|
||||
break;
|
||||
}
|
||||
@@ -226,6 +229,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
STACK_OF(X509_EXTENSION) *exts;
|
||||
X509_EXTENSION *ext;
|
||||
size_t idx;
|
||||
int i;
|
||||
|
||||
switch (operation) {
|
||||
case ASN1_OP_NEW_POST:
|
||||
@@ -242,26 +246,44 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
break;
|
||||
|
||||
case ASN1_OP_D2I_POST:
|
||||
X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
|
||||
if (!X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
crl->idp = X509_CRL_get_ext_d2i(crl,
|
||||
NID_issuing_distribution_point, NULL,
|
||||
NID_issuing_distribution_point, &i,
|
||||
NULL);
|
||||
if (crl->idp)
|
||||
setup_idp(crl, crl->idp);
|
||||
if (crl->idp != NULL) {
|
||||
if (!setup_idp(crl, crl->idp)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (i != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
crl->akid = X509_CRL_get_ext_d2i(crl,
|
||||
NID_authority_key_identifier, NULL,
|
||||
NID_authority_key_identifier, &i,
|
||||
NULL);
|
||||
if (crl->akid == NULL && i != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
crl->crl_number = X509_CRL_get_ext_d2i(crl,
|
||||
NID_crl_number, NULL, NULL);
|
||||
NID_crl_number, &i, NULL);
|
||||
if (crl->crl_number == NULL && i != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
crl->base_crl_number = X509_CRL_get_ext_d2i(crl,
|
||||
NID_delta_crl, NULL,
|
||||
crl->base_crl_number = X509_CRL_get_ext_d2i(crl, NID_delta_crl, &i,
|
||||
NULL);
|
||||
if (crl->base_crl_number == NULL && i != -1) {
|
||||
return 0;
|
||||
}
|
||||
/* Delta CRLs must have CRL number */
|
||||
if (crl->base_crl_number && !crl->crl_number)
|
||||
crl->flags |= EXFLAG_INVALID;
|
||||
if (crl->base_crl_number && !crl->crl_number) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_DELTA_CRL_WITHOUT_CRL_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* See if we have any unhandled critical CRL extensions and indicate
|
||||
@@ -319,7 +341,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
|
||||
/* Convert IDP into a more convenient form */
|
||||
|
||||
static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
|
||||
static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
|
||||
{
|
||||
int idp_only = 0;
|
||||
/* Set various flags according to IDP */
|
||||
@@ -352,7 +374,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
|
||||
crl->idp_reasons &= CRLDP_ALL_REASONS;
|
||||
}
|
||||
|
||||
DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl));
|
||||
return DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl));
|
||||
}
|
||||
|
||||
ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = {
|
||||
@@ -389,10 +411,10 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
|
||||
int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *pkey)
|
||||
{
|
||||
if (crl->meth->crl_verify)
|
||||
return crl->meth->crl_verify(crl, r);
|
||||
return crl->meth->crl_verify(crl, pkey);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,18 +197,8 @@ static int x509_name_ex_d2i(ASN1_VALUE **val,
|
||||
char opt, ASN1_TLC *ctx)
|
||||
{
|
||||
const unsigned char *p = *in, *q;
|
||||
union {
|
||||
STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
|
||||
ASN1_VALUE *a;
|
||||
} intname = {
|
||||
NULL
|
||||
};
|
||||
union {
|
||||
X509_NAME *x;
|
||||
ASN1_VALUE *a;
|
||||
} nm = {
|
||||
NULL
|
||||
};
|
||||
STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
|
||||
X509_NAME *nm = NULL;
|
||||
size_t i, j;
|
||||
int ret;
|
||||
STACK_OF(X509_NAME_ENTRY) *entries;
|
||||
@@ -220,46 +210,48 @@ static int x509_name_ex_d2i(ASN1_VALUE **val,
|
||||
q = p;
|
||||
|
||||
/* Get internal representation of Name */
|
||||
ret = ASN1_item_ex_d2i(&intname.a,
|
||||
ASN1_VALUE *intname_val = NULL;
|
||||
ret = ASN1_item_ex_d2i(&intname_val,
|
||||
&p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
|
||||
tag, aclass, opt, ctx);
|
||||
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
intname = (STACK_OF(STACK_OF_X509_NAME_ENTRY) *)intname_val;
|
||||
|
||||
if (*val)
|
||||
x509_name_ex_free(val, NULL);
|
||||
if (!x509_name_ex_new(&nm.a, NULL))
|
||||
ASN1_VALUE *nm_val = NULL;
|
||||
if (!x509_name_ex_new(&nm_val, NULL))
|
||||
goto err;
|
||||
nm = (X509_NAME *)nm_val;
|
||||
/* We've decoded it: now cache encoding */
|
||||
if (!BUF_MEM_grow(nm.x->bytes, p - q))
|
||||
if (!BUF_MEM_grow(nm->bytes, p - q))
|
||||
goto err;
|
||||
OPENSSL_memcpy(nm.x->bytes->data, q, p - q);
|
||||
OPENSSL_memcpy(nm->bytes->data, q, p - q);
|
||||
|
||||
/* Convert internal representation to X509_NAME structure */
|
||||
for (i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) {
|
||||
entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i);
|
||||
for (i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname); i++) {
|
||||
entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname, i);
|
||||
for (j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
|
||||
entry = sk_X509_NAME_ENTRY_value(entries, j);
|
||||
entry->set = i;
|
||||
if (!sk_X509_NAME_ENTRY_push(nm.x->entries, entry))
|
||||
if (!sk_X509_NAME_ENTRY_push(nm->entries, entry))
|
||||
goto err;
|
||||
(void)sk_X509_NAME_ENTRY_set(entries, j, NULL);
|
||||
}
|
||||
}
|
||||
ret = x509_name_canon(nm.x);
|
||||
ret = x509_name_canon(nm);
|
||||
if (!ret)
|
||||
goto err;
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
|
||||
local_sk_X509_NAME_ENTRY_free);
|
||||
nm.x->modified = 0;
|
||||
*val = nm.a;
|
||||
nm->modified = 0;
|
||||
*val = (ASN1_VALUE *)nm;
|
||||
*in = p;
|
||||
return ret;
|
||||
err:
|
||||
if (nm.x != NULL)
|
||||
X509_NAME_free(nm.x);
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
|
||||
X509_NAME_free(nm);
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
|
||||
local_sk_X509_NAME_ENTRY_pop_free);
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_ASN1_LIB);
|
||||
return 0;
|
||||
@@ -288,20 +280,15 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out,
|
||||
|
||||
static int x509_name_encode(X509_NAME *a)
|
||||
{
|
||||
union {
|
||||
STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
|
||||
ASN1_VALUE *a;
|
||||
} intname = {
|
||||
NULL
|
||||
};
|
||||
int len;
|
||||
unsigned char *p;
|
||||
STACK_OF(X509_NAME_ENTRY) *entries = NULL;
|
||||
X509_NAME_ENTRY *entry;
|
||||
int set = -1;
|
||||
size_t i;
|
||||
intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
|
||||
if (!intname.s)
|
||||
STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname =
|
||||
sk_STACK_OF_X509_NAME_ENTRY_new_null();
|
||||
if (!intname)
|
||||
goto memerr;
|
||||
for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
|
||||
entry = sk_X509_NAME_ENTRY_value(a->entries, i);
|
||||
@@ -309,7 +296,7 @@ static int x509_name_encode(X509_NAME *a)
|
||||
entries = sk_X509_NAME_ENTRY_new_null();
|
||||
if (!entries)
|
||||
goto memerr;
|
||||
if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, entries)) {
|
||||
if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) {
|
||||
sk_X509_NAME_ENTRY_free(entries);
|
||||
goto memerr;
|
||||
}
|
||||
@@ -318,19 +305,20 @@ static int x509_name_encode(X509_NAME *a)
|
||||
if (!sk_X509_NAME_ENTRY_push(entries, entry))
|
||||
goto memerr;
|
||||
}
|
||||
len = ASN1_item_ex_i2d(&intname.a, NULL,
|
||||
ASN1_VALUE *intname_val = (ASN1_VALUE *)intname;
|
||||
len = ASN1_item_ex_i2d(&intname_val, NULL,
|
||||
ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
|
||||
if (!BUF_MEM_grow(a->bytes, len))
|
||||
goto memerr;
|
||||
p = (unsigned char *)a->bytes->data;
|
||||
ASN1_item_ex_i2d(&intname.a,
|
||||
ASN1_item_ex_i2d(&intname_val,
|
||||
&p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
|
||||
local_sk_X509_NAME_ENTRY_free);
|
||||
a->modified = 0;
|
||||
return len;
|
||||
memerr:
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
|
||||
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
|
||||
local_sk_X509_NAME_ENTRY_free);
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
|
||||
@@ -180,160 +180,6 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now two pseudo ASN1 routines that take an EVP_PKEY structure and encode or
|
||||
* decode as X509_PUBKEY
|
||||
*/
|
||||
|
||||
EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length)
|
||||
{
|
||||
X509_PUBKEY *xpk;
|
||||
EVP_PKEY *pktmp;
|
||||
xpk = d2i_X509_PUBKEY(NULL, pp, length);
|
||||
if (!xpk)
|
||||
return NULL;
|
||||
pktmp = X509_PUBKEY_get(xpk);
|
||||
X509_PUBKEY_free(xpk);
|
||||
if (!pktmp)
|
||||
return NULL;
|
||||
if (a) {
|
||||
EVP_PKEY_free(*a);
|
||||
*a = pktmp;
|
||||
}
|
||||
return pktmp;
|
||||
}
|
||||
|
||||
int i2d_PUBKEY(const EVP_PKEY *a, unsigned char **pp)
|
||||
{
|
||||
X509_PUBKEY *xpk = NULL;
|
||||
int ret;
|
||||
if (!a)
|
||||
return 0;
|
||||
if (!X509_PUBKEY_set(&xpk, (EVP_PKEY *)a))
|
||||
return 0;
|
||||
ret = i2d_X509_PUBKEY(xpk, pp);
|
||||
X509_PUBKEY_free(xpk);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following are equivalents but which return RSA and DSA keys
|
||||
*/
|
||||
RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
RSA *key;
|
||||
const unsigned char *q;
|
||||
q = *pp;
|
||||
pkey = d2i_PUBKEY(NULL, &q, length);
|
||||
if (!pkey)
|
||||
return NULL;
|
||||
key = EVP_PKEY_get1_RSA(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
if (!key)
|
||||
return NULL;
|
||||
*pp = q;
|
||||
if (a) {
|
||||
RSA_free(*a);
|
||||
*a = key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
int i2d_RSA_PUBKEY(const RSA *a, unsigned char **pp)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
int ret;
|
||||
if (!a)
|
||||
return 0;
|
||||
pktmp = EVP_PKEY_new();
|
||||
if (!pktmp) {
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
EVP_PKEY_set1_RSA(pktmp, (RSA *)a);
|
||||
ret = i2d_PUBKEY(pktmp, pp);
|
||||
EVP_PKEY_free(pktmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
DSA *key;
|
||||
const unsigned char *q;
|
||||
q = *pp;
|
||||
pkey = d2i_PUBKEY(NULL, &q, length);
|
||||
if (!pkey)
|
||||
return NULL;
|
||||
key = EVP_PKEY_get1_DSA(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
if (!key)
|
||||
return NULL;
|
||||
*pp = q;
|
||||
if (a) {
|
||||
DSA_free(*a);
|
||||
*a = key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
int ret;
|
||||
if (!a)
|
||||
return 0;
|
||||
pktmp = EVP_PKEY_new();
|
||||
if (!pktmp) {
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
EVP_PKEY_set1_DSA(pktmp, (DSA *)a);
|
||||
ret = i2d_PUBKEY(pktmp, pp);
|
||||
EVP_PKEY_free(pktmp);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
EC_KEY *key;
|
||||
const unsigned char *q;
|
||||
q = *pp;
|
||||
pkey = d2i_PUBKEY(NULL, &q, length);
|
||||
if (!pkey)
|
||||
return (NULL);
|
||||
key = EVP_PKEY_get1_EC_KEY(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
if (!key)
|
||||
return (NULL);
|
||||
*pp = q;
|
||||
if (a) {
|
||||
EC_KEY_free(*a);
|
||||
*a = key;
|
||||
}
|
||||
return (key);
|
||||
}
|
||||
|
||||
int i2d_EC_PUBKEY(const EC_KEY *a, unsigned char **pp)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
int ret;
|
||||
if (!a)
|
||||
return (0);
|
||||
if ((pktmp = EVP_PKEY_new()) == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
EVP_PKEY_set1_EC_KEY(pktmp, (EC_KEY *)a);
|
||||
ret = i2d_PUBKEY(pktmp, pp);
|
||||
EVP_PKEY_free(pktmp);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int X509_PUBKEY_set0_param(X509_PUBKEY *pub, const ASN1_OBJECT *aobj,
|
||||
int ptype, void *pval,
|
||||
unsigned char *penc, int penclen)
|
||||
|
||||
@@ -67,3 +67,23 @@ ASN1_SEQUENCE(X509_SIG) = {
|
||||
} ASN1_SEQUENCE_END(X509_SIG)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
|
||||
|
||||
void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **out_alg,
|
||||
const ASN1_OCTET_STRING **out_digest) {
|
||||
if (out_alg != NULL) {
|
||||
*out_alg = sig->algor;
|
||||
}
|
||||
if (out_digest != NULL) {
|
||||
*out_digest = sig->digest;
|
||||
}
|
||||
}
|
||||
|
||||
void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **out_alg,
|
||||
ASN1_OCTET_STRING **out_digest) {
|
||||
if (out_alg != NULL) {
|
||||
*out_alg = sig->algor;
|
||||
}
|
||||
if (out_digest != NULL) {
|
||||
*out_digest = sig->digest;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,6 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
switch (operation) {
|
||||
|
||||
case ASN1_OP_NEW_POST:
|
||||
ret->name = NULL;
|
||||
ret->ex_flags = 0;
|
||||
ret->ex_pathlen = -1;
|
||||
ret->skid = NULL;
|
||||
@@ -115,11 +114,37 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
ret->buf = NULL;
|
||||
break;
|
||||
|
||||
case ASN1_OP_D2I_POST:
|
||||
if (ret->name != NULL)
|
||||
OPENSSL_free(ret->name);
|
||||
ret->name = X509_NAME_oneline(ret->cert_info->subject, NULL, 0);
|
||||
case ASN1_OP_D2I_POST: {
|
||||
/* The version must be one of v1(0), v2(1), or v3(2). */
|
||||
long version = 0;
|
||||
if (ret->cert_info->version != NULL) {
|
||||
version = ASN1_INTEGER_get(ret->cert_info->version);
|
||||
/* TODO(https://crbug.com/boringssl/364): |version| = 0 should also
|
||||
* be rejected. This means an explicitly-encoded X.509v1 version.
|
||||
* v1 is DEFAULT, so DER requires it be omitted. */
|
||||
if (version < 0 || version > 2) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Per RFC5280, section 4.1.2.8, these fields require v2 or v3. */
|
||||
if (version == 0 && (ret->cert_info->issuerUID != NULL ||
|
||||
ret->cert_info->subjectUID != NULL)) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_INVALID_FIELD_FOR_VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Per RFC5280, section 4.1.2.9, extensions require v3. */
|
||||
/* Check disabled. TODO re-enable in Jan 2021.
|
||||
https://crbug.com/boringssl/375
|
||||
if (version != 2 && ret->cert_info->extensions != NULL) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_INVALID_FIELD_FOR_VERSION);
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_OP_FREE_POST:
|
||||
CRYPTO_MUTEX_cleanup(&ret->lock);
|
||||
@@ -132,7 +157,6 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
GENERAL_NAMES_free(ret->altname);
|
||||
NAME_CONSTRAINTS_free(ret->nc);
|
||||
CRYPTO_BUFFER_free(ret->buf);
|
||||
OPENSSL_free(ret->name);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
extern const X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
|
||||
extern const X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info,
|
||||
v3_sinfo;
|
||||
extern const X509V3_EXT_METHOD v3_info, v3_sinfo;
|
||||
extern const X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id,
|
||||
v3_akey_id;
|
||||
extern const X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_crl_invdate;
|
||||
@@ -96,7 +95,6 @@ static const X509V3_EXT_METHOD *const standard_exts[] = {
|
||||
&v3_ns_ia5_list[6],
|
||||
&v3_skey_id,
|
||||
&v3_key_usage,
|
||||
&v3_pkey_usage_period,
|
||||
&v3_alt[0],
|
||||
&v3_alt[1],
|
||||
&v3_bcons,
|
||||
@@ -108,7 +106,6 @@ static const X509V3_EXT_METHOD *const standard_exts[] = {
|
||||
&v3_delta_crl,
|
||||
&v3_crl_reason,
|
||||
&v3_crl_invdate,
|
||||
&v3_sxnet,
|
||||
&v3_info,
|
||||
#ifndef OPENSSL_NO_OCSP
|
||||
&v3_ocsp_nonce,
|
||||
|
||||
@@ -48,6 +48,11 @@ int x509v3_name_cmp(const char *name, const char *cmp);
|
||||
OPENSSL_EXPORT int x509v3_looks_like_dns_name(const unsigned char *in,
|
||||
size_t len);
|
||||
|
||||
// x509v3_cache_extensions fills in a number of fields relating to X.509
|
||||
// extensions in |x|. It returns one on success and zero if some extensions were
|
||||
// invalid.
|
||||
int x509v3_cache_extensions(X509 *x);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern C */
|
||||
|
||||
@@ -428,13 +428,17 @@ void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
|
||||
ctx->db_meth->free_section(ctx->db, section);
|
||||
}
|
||||
|
||||
static char *nconf_get_string(void *db, char *section, char *value)
|
||||
static char *nconf_get_string(void *db, const char *section, const char *value)
|
||||
{
|
||||
/* TODO(fork): this should return a const value. */
|
||||
/* TODO(fork): This returns a non-const pointer because |X509V3_CONF_METHOD|
|
||||
* allows |get_string| to return caller-owned pointers, provided they're
|
||||
* freed by |free_string|. |nconf_method| leaves |free_string| NULL, and
|
||||
* there are no other implementations of |X509V3_CONF_METHOD|, so this can
|
||||
* be simplified if we make it private. */
|
||||
return (char *)NCONF_get_string(db, section, value);
|
||||
}
|
||||
|
||||
static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, char *section)
|
||||
static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, const char *section)
|
||||
{
|
||||
return NCONF_get_section(db, section);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
|
||||
a->type = type;
|
||||
}
|
||||
|
||||
void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype)
|
||||
void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype)
|
||||
{
|
||||
if (ptype)
|
||||
*ptype = a->type;
|
||||
@@ -233,7 +233,7 @@ int GENERAL_NAME_set0_othername(GENERAL_NAME *gen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GENERAL_NAME_get0_otherName(GENERAL_NAME *gen,
|
||||
int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen,
|
||||
ASN1_OBJECT **poid, ASN1_TYPE **pvalue)
|
||||
{
|
||||
if (gen->type != GEN_OTHERNAME)
|
||||
|
||||
@@ -208,7 +208,7 @@ static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION *a)
|
||||
int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a)
|
||||
{
|
||||
i2a_ASN1_OBJECT(bp, a->method);
|
||||
#ifdef UNDEF
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
/* v3_pku.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
|
||||
PKEY_USAGE_PERIOD *usage, BIO *out,
|
||||
int indent);
|
||||
/*
|
||||
* static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
|
||||
* X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
|
||||
*/
|
||||
const X509V3_EXT_METHOD v3_pkey_usage_period = {
|
||||
NID_private_key_usage_period, 0, ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
ASN1_SEQUENCE(PKEY_USAGE_PERIOD) = {
|
||||
ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notBefore, ASN1_GENERALIZEDTIME, 0),
|
||||
ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notAfter, ASN1_GENERALIZEDTIME, 1)
|
||||
} ASN1_SEQUENCE_END(PKEY_USAGE_PERIOD)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
|
||||
|
||||
static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
|
||||
PKEY_USAGE_PERIOD *usage, BIO *out,
|
||||
int indent)
|
||||
{
|
||||
BIO_printf(out, "%*s", indent, "");
|
||||
if (usage->notBefore) {
|
||||
BIO_write(out, "Not Before: ", 12);
|
||||
ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
|
||||
if (usage->notAfter)
|
||||
BIO_write(out, ", ", 2);
|
||||
}
|
||||
if (usage->notAfter) {
|
||||
BIO_write(out, "Not After: ", 11);
|
||||
ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values)
|
||||
* X509V3_EXT_METHOD *method; X509V3_CTX *ctx; STACK_OF(CONF_VALUE) *values;
|
||||
* { return NULL; }
|
||||
*/
|
||||
@@ -68,6 +68,7 @@
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
|
||||
#define ku_reject(x, usage) \
|
||||
@@ -77,8 +78,6 @@
|
||||
#define ns_reject(x, usage) \
|
||||
(((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage)))
|
||||
|
||||
static void x509v3_cache_extensions(X509 *x);
|
||||
|
||||
static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x,
|
||||
int ca);
|
||||
static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x,
|
||||
@@ -144,7 +143,10 @@ int X509_check_purpose(X509 *x, int id, int ca)
|
||||
{
|
||||
int idx;
|
||||
const X509_PURPOSE *pt;
|
||||
x509v3_cache_extensions(x);
|
||||
if (!x509v3_cache_extensions(x)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (id == -1)
|
||||
return 1;
|
||||
idx = X509_PURPOSE_get_by_id(id);
|
||||
@@ -305,22 +307,22 @@ void X509_PURPOSE_cleanup(void)
|
||||
xptable = NULL;
|
||||
}
|
||||
|
||||
int X509_PURPOSE_get_id(X509_PURPOSE *xp)
|
||||
int X509_PURPOSE_get_id(const X509_PURPOSE *xp)
|
||||
{
|
||||
return xp->purpose;
|
||||
}
|
||||
|
||||
char *X509_PURPOSE_get0_name(X509_PURPOSE *xp)
|
||||
char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp)
|
||||
{
|
||||
return xp->name;
|
||||
}
|
||||
|
||||
char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp)
|
||||
char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp)
|
||||
{
|
||||
return xp->sname;
|
||||
}
|
||||
|
||||
int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
|
||||
int X509_PURPOSE_get_trust(const X509_PURPOSE *xp)
|
||||
{
|
||||
return xp->trust;
|
||||
}
|
||||
@@ -368,7 +370,7 @@ int X509_supported_extension(X509_EXTENSION *ex)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_dp(X509 *x, DIST_POINT *dp)
|
||||
static int setup_dp(X509 *x, DIST_POINT *dp)
|
||||
{
|
||||
X509_NAME *iname = NULL;
|
||||
size_t i;
|
||||
@@ -381,7 +383,7 @@ static void setup_dp(X509 *x, DIST_POINT *dp)
|
||||
} else
|
||||
dp->dp_reasons = CRLDP_ALL_REASONS;
|
||||
if (!dp->distpoint || (dp->distpoint->type != 1))
|
||||
return;
|
||||
return 1;
|
||||
for (i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++) {
|
||||
GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i);
|
||||
if (gen->type == GEN_DIRNAME) {
|
||||
@@ -392,19 +394,25 @@ static void setup_dp(X509 *x, DIST_POINT *dp)
|
||||
if (!iname)
|
||||
iname = X509_get_issuer_name(x);
|
||||
|
||||
DIST_POINT_set_dpname(dp->distpoint, iname);
|
||||
|
||||
return DIST_POINT_set_dpname(dp->distpoint, iname);
|
||||
}
|
||||
|
||||
static void setup_crldp(X509 *x)
|
||||
static int setup_crldp(X509 *x)
|
||||
{
|
||||
size_t i;
|
||||
x->crldp = X509_get_ext_d2i(x, NID_crl_distribution_points, NULL, NULL);
|
||||
for (i = 0; i < sk_DIST_POINT_num(x->crldp); i++)
|
||||
setup_dp(x, sk_DIST_POINT_value(x->crldp, i));
|
||||
int j;
|
||||
x->crldp = X509_get_ext_d2i(x, NID_crl_distribution_points, &j, NULL);
|
||||
if (x->crldp == NULL && j != -1) {
|
||||
return 0;
|
||||
}
|
||||
for (size_t i = 0; i < sk_DIST_POINT_num(x->crldp); i++) {
|
||||
if (!setup_dp(x, sk_DIST_POINT_value(x->crldp, i))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void x509v3_cache_extensions(X509 *x)
|
||||
int x509v3_cache_extensions(X509 *x)
|
||||
{
|
||||
BASIC_CONSTRAINTS *bs;
|
||||
PROXY_CERT_INFO_EXTENSION *pci;
|
||||
@@ -420,21 +428,22 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
CRYPTO_MUTEX_unlock_read(&x->lock);
|
||||
|
||||
if (is_set) {
|
||||
return;
|
||||
return (x->ex_flags & EXFLAG_INVALID) == 0;
|
||||
}
|
||||
|
||||
CRYPTO_MUTEX_lock_write(&x->lock);
|
||||
if (x->ex_flags & EXFLAG_SET) {
|
||||
CRYPTO_MUTEX_unlock_write(&x->lock);
|
||||
return;
|
||||
return (x->ex_flags & EXFLAG_INVALID) == 0;
|
||||
}
|
||||
|
||||
X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);
|
||||
if (!X509_digest(x, EVP_sha1(), x->sha1_hash, NULL))
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
/* V1 should mean no extensions ... */
|
||||
if (!X509_get_version(x))
|
||||
x->ex_flags |= EXFLAG_V1;
|
||||
/* Handle basic constraints */
|
||||
if ((bs = X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {
|
||||
if ((bs = X509_get_ext_d2i(x, NID_basic_constraints, &j, NULL))) {
|
||||
if (bs->ca)
|
||||
x->ex_flags |= EXFLAG_CA;
|
||||
if (bs->pathlen) {
|
||||
@@ -442,15 +451,23 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
|| !bs->ca) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
x->ex_pathlen = 0;
|
||||
} else
|
||||
} else {
|
||||
/* TODO(davidben): |ASN1_INTEGER_get| returns -1 on overflow,
|
||||
* which currently acts as if the constraint isn't present. This
|
||||
* works (an overflowing path length constraint may as well be
|
||||
* infinity), but Chromium's verifier simply treats values above
|
||||
* 255 as an error. */
|
||||
x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);
|
||||
}
|
||||
} else
|
||||
x->ex_pathlen = -1;
|
||||
BASIC_CONSTRAINTS_free(bs);
|
||||
x->ex_flags |= EXFLAG_BCONS;
|
||||
} else if (j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
/* Handle proxy certificates */
|
||||
if ((pci = X509_get_ext_d2i(x, NID_proxyCertInfo, NULL, NULL))) {
|
||||
if ((pci = X509_get_ext_d2i(x, NID_proxyCertInfo, &j, NULL))) {
|
||||
if (x->ex_flags & EXFLAG_CA
|
||||
|| X509_get_ext_by_NID(x, NID_subject_alt_name, -1) >= 0
|
||||
|| X509_get_ext_by_NID(x, NID_issuer_alt_name, -1) >= 0) {
|
||||
@@ -462,9 +479,11 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
x->ex_pcpathlen = -1;
|
||||
PROXY_CERT_INFO_EXTENSION_free(pci);
|
||||
x->ex_flags |= EXFLAG_PROXY;
|
||||
} else if (j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
/* Handle key usage */
|
||||
if ((usage = X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {
|
||||
if ((usage = X509_get_ext_d2i(x, NID_key_usage, &j, NULL))) {
|
||||
if (usage->length > 0) {
|
||||
x->ex_kusage = usage->data[0];
|
||||
if (usage->length > 1)
|
||||
@@ -473,9 +492,11 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
x->ex_kusage = 0;
|
||||
x->ex_flags |= EXFLAG_KUSAGE;
|
||||
ASN1_BIT_STRING_free(usage);
|
||||
} else if (j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
x->ex_xkusage = 0;
|
||||
if ((extusage = X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {
|
||||
if ((extusage = X509_get_ext_d2i(x, NID_ext_key_usage, &j, NULL))) {
|
||||
x->ex_flags |= EXFLAG_XKUSAGE;
|
||||
for (i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {
|
||||
switch (OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage, i))) {
|
||||
@@ -518,18 +539,28 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
}
|
||||
}
|
||||
sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);
|
||||
} else if (j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
|
||||
if ((ns = X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {
|
||||
if ((ns = X509_get_ext_d2i(x, NID_netscape_cert_type, &j, NULL))) {
|
||||
if (ns->length > 0)
|
||||
x->ex_nscert = ns->data[0];
|
||||
else
|
||||
x->ex_nscert = 0;
|
||||
x->ex_flags |= EXFLAG_NSCERT;
|
||||
ASN1_BIT_STRING_free(ns);
|
||||
} else if (j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
x->skid = X509_get_ext_d2i(x, NID_subject_key_identifier, &j, NULL);
|
||||
if (x->skid == NULL && j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
x->akid = X509_get_ext_d2i(x, NID_authority_key_identifier, &j, NULL);
|
||||
if (x->akid == NULL && j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
x->skid = X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);
|
||||
x->akid = X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);
|
||||
/* Does subject name match issuer ? */
|
||||
if (!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x))) {
|
||||
x->ex_flags |= EXFLAG_SI;
|
||||
@@ -538,11 +569,17 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
!ku_reject(x, KU_KEY_CERT_SIGN))
|
||||
x->ex_flags |= EXFLAG_SS;
|
||||
}
|
||||
x->altname = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
|
||||
x->nc = X509_get_ext_d2i(x, NID_name_constraints, &j, NULL);
|
||||
if (!x->nc && (j != -1))
|
||||
x->altname = X509_get_ext_d2i(x, NID_subject_alt_name, &j, NULL);
|
||||
if (x->altname == NULL && j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
setup_crldp(x);
|
||||
}
|
||||
x->nc = X509_get_ext_d2i(x, NID_name_constraints, &j, NULL);
|
||||
if (x->nc == NULL && j != -1) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
if (!setup_crldp(x)) {
|
||||
x->ex_flags |= EXFLAG_INVALID;
|
||||
}
|
||||
|
||||
for (j = 0; j < X509_get_ext_count(x); j++) {
|
||||
ex = X509_get_ext(x, j);
|
||||
@@ -559,6 +596,7 @@ static void x509v3_cache_extensions(X509 *x)
|
||||
x->ex_flags |= EXFLAG_SET;
|
||||
|
||||
CRYPTO_MUTEX_unlock_write(&x->lock);
|
||||
return (x->ex_flags & EXFLAG_INVALID) == 0;
|
||||
}
|
||||
|
||||
/* check_ca returns one if |x| should be considered a CA certificate and zero
|
||||
@@ -579,7 +617,9 @@ static int check_ca(const X509 *x)
|
||||
|
||||
int X509_check_ca(X509 *x)
|
||||
{
|
||||
x509v3_cache_extensions(x);
|
||||
if (!x509v3_cache_extensions(x)) {
|
||||
return 0;
|
||||
}
|
||||
return check_ca(x);
|
||||
}
|
||||
|
||||
@@ -761,8 +801,10 @@ int X509_check_issued(X509 *issuer, X509 *subject)
|
||||
if (X509_NAME_cmp(X509_get_subject_name(issuer),
|
||||
X509_get_issuer_name(subject)))
|
||||
return X509_V_ERR_SUBJECT_ISSUER_MISMATCH;
|
||||
x509v3_cache_extensions(issuer);
|
||||
x509v3_cache_extensions(subject);
|
||||
if (!x509v3_cache_extensions(issuer) ||
|
||||
!x509v3_cache_extensions(subject)) {
|
||||
return X509_V_ERR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
if (subject->akid) {
|
||||
int ret = X509_check_akid(issuer, subject->akid);
|
||||
@@ -819,15 +861,17 @@ int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid)
|
||||
|
||||
uint32_t X509_get_extension_flags(X509 *x)
|
||||
{
|
||||
/* Call for side-effect of computing hash and caching extensions */
|
||||
X509_check_purpose(x, -1, -1);
|
||||
/* Ignore the return value. On failure, |x->ex_flags| will include
|
||||
* |EXFLAG_INVALID|. */
|
||||
x509v3_cache_extensions(x);
|
||||
return x->ex_flags;
|
||||
}
|
||||
|
||||
uint32_t X509_get_key_usage(X509 *x)
|
||||
{
|
||||
/* Call for side-effect of computing hash and caching extensions */
|
||||
X509_check_purpose(x, -1, -1);
|
||||
if (!x509v3_cache_extensions(x)) {
|
||||
return 0;
|
||||
}
|
||||
if (x->ex_flags & EXFLAG_KUSAGE)
|
||||
return x->ex_kusage;
|
||||
return UINT32_MAX;
|
||||
@@ -835,9 +879,51 @@ uint32_t X509_get_key_usage(X509 *x)
|
||||
|
||||
uint32_t X509_get_extended_key_usage(X509 *x)
|
||||
{
|
||||
/* Call for side-effect of computing hash and caching extensions */
|
||||
X509_check_purpose(x, -1, -1);
|
||||
if (!x509v3_cache_extensions(x)) {
|
||||
return 0;
|
||||
}
|
||||
if (x->ex_flags & EXFLAG_XKUSAGE)
|
||||
return x->ex_xkusage;
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x509)
|
||||
{
|
||||
if (!x509v3_cache_extensions(x509)) {
|
||||
return NULL;
|
||||
}
|
||||
return x509->skid;
|
||||
}
|
||||
|
||||
const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x509)
|
||||
{
|
||||
if (!x509v3_cache_extensions(x509)) {
|
||||
return NULL;
|
||||
}
|
||||
return x509->akid != NULL ? x509->akid->keyid : NULL;
|
||||
}
|
||||
|
||||
const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x509)
|
||||
{
|
||||
if (!x509v3_cache_extensions(x509)) {
|
||||
return NULL;
|
||||
}
|
||||
return x509->akid != NULL ? x509->akid->issuer : NULL;
|
||||
}
|
||||
|
||||
const ASN1_INTEGER *X509_get0_authority_serial(X509 *x509)
|
||||
{
|
||||
if (!x509v3_cache_extensions(x509)) {
|
||||
return NULL;
|
||||
}
|
||||
return x509->akid != NULL ? x509->akid->serial : NULL;
|
||||
}
|
||||
|
||||
long X509_get_pathlen(X509 *x509)
|
||||
{
|
||||
if (!x509v3_cache_extensions(x509) ||
|
||||
(x509->ex_flags & EXFLAG_BCONS) == 0) {
|
||||
return -1;
|
||||
}
|
||||
return x509->ex_pathlen;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ const X509V3_EXT_METHOD v3_skey_id = {
|
||||
NULL
|
||||
};
|
||||
|
||||
char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct)
|
||||
char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, const ASN1_OCTET_STRING *oct)
|
||||
{
|
||||
return x509v3_bytes_to_hex(oct->data, oct->length);
|
||||
}
|
||||
|
||||
@@ -1,274 +0,0 @@
|
||||
/* v3_sxnet.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_conf.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
/* Support for Thawte strong extranet extension */
|
||||
|
||||
#define SXNET_TEST
|
||||
|
||||
static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
|
||||
int indent);
|
||||
#ifdef SXNET_TEST
|
||||
static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *nval);
|
||||
#endif
|
||||
const X509V3_EXT_METHOD v3_sxnet = {
|
||||
NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET),
|
||||
0, 0, 0, 0,
|
||||
0, 0,
|
||||
0,
|
||||
#ifdef SXNET_TEST
|
||||
(X509V3_EXT_V2I)sxnet_v2i,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
(X509V3_EXT_I2R)sxnet_i2r,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
|
||||
ASN1_SEQUENCE(SXNETID) = {
|
||||
ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(SXNETID)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SXNETID)
|
||||
|
||||
ASN1_SEQUENCE(SXNET) = {
|
||||
ASN1_SIMPLE(SXNET, version, ASN1_INTEGER),
|
||||
ASN1_SEQUENCE_OF(SXNET, ids, SXNETID)
|
||||
} ASN1_SEQUENCE_END(SXNET)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SXNET)
|
||||
|
||||
static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
|
||||
int indent)
|
||||
{
|
||||
long v;
|
||||
char *tmp;
|
||||
SXNETID *id;
|
||||
size_t i;
|
||||
v = ASN1_INTEGER_get(sx->version);
|
||||
BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v);
|
||||
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
|
||||
id = sk_SXNETID_value(sx->ids, i);
|
||||
tmp = i2s_ASN1_INTEGER(NULL, id->zone);
|
||||
BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
|
||||
OPENSSL_free(tmp);
|
||||
M_ASN1_OCTET_STRING_print(out, id->user);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef SXNET_TEST
|
||||
|
||||
/*
|
||||
* NBB: this is used for testing only. It should *not* be used for anything
|
||||
* else because it will just take static IDs from the configuration file and
|
||||
* they should really be separate values for each user.
|
||||
*/
|
||||
|
||||
static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *nval)
|
||||
{
|
||||
CONF_VALUE *cnf;
|
||||
SXNET *sx = NULL;
|
||||
size_t i;
|
||||
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
|
||||
cnf = sk_CONF_VALUE_value(nval, i);
|
||||
if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
|
||||
return NULL;
|
||||
}
|
||||
return sx;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Strong Extranet utility functions */
|
||||
|
||||
/* Add an id given the zone as an ASCII number */
|
||||
|
||||
int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen)
|
||||
{
|
||||
ASN1_INTEGER *izone = NULL;
|
||||
if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ERROR_CONVERTING_ZONE);
|
||||
return 0;
|
||||
}
|
||||
return SXNET_add_id_INTEGER(psx, izone, user, userlen);
|
||||
}
|
||||
|
||||
/* Add an id given the zone as an unsigned long */
|
||||
|
||||
int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
|
||||
int userlen)
|
||||
{
|
||||
ASN1_INTEGER *izone = NULL;
|
||||
if (!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
M_ASN1_INTEGER_free(izone);
|
||||
return 0;
|
||||
}
|
||||
return SXNET_add_id_INTEGER(psx, izone, user, userlen);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an id given the zone as an ASN1_INTEGER. Note this version uses the
|
||||
* passed integer and doesn't make a copy so don't free it up afterwards.
|
||||
*/
|
||||
|
||||
int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
|
||||
int userlen)
|
||||
{
|
||||
SXNET *sx = NULL;
|
||||
SXNETID *id = NULL;
|
||||
if (!psx || !zone || !user) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
|
||||
return 0;
|
||||
}
|
||||
if (userlen == -1)
|
||||
userlen = strlen(user);
|
||||
if (userlen > 64) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_USER_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
if (!*psx) {
|
||||
if (!(sx = SXNET_new()))
|
||||
goto err;
|
||||
if (!ASN1_INTEGER_set(sx->version, 0))
|
||||
goto err;
|
||||
*psx = sx;
|
||||
} else
|
||||
sx = *psx;
|
||||
if (SXNET_get_id_INTEGER(sx, zone)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_DUPLICATE_ZONE_ID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(id = SXNETID_new()))
|
||||
goto err;
|
||||
if (userlen == -1)
|
||||
userlen = strlen(user);
|
||||
|
||||
if (!M_ASN1_OCTET_STRING_set(id->user, user, userlen))
|
||||
goto err;
|
||||
if (!sk_SXNETID_push(sx->ids, id))
|
||||
goto err;
|
||||
id->zone = zone;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
SXNETID_free(id);
|
||||
SXNET_free(sx);
|
||||
*psx = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
|
||||
{
|
||||
ASN1_INTEGER *izone = NULL;
|
||||
ASN1_OCTET_STRING *oct;
|
||||
if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ERROR_CONVERTING_ZONE);
|
||||
return NULL;
|
||||
}
|
||||
oct = SXNET_get_id_INTEGER(sx, izone);
|
||||
M_ASN1_INTEGER_free(izone);
|
||||
return oct;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
|
||||
{
|
||||
ASN1_INTEGER *izone = NULL;
|
||||
ASN1_OCTET_STRING *oct;
|
||||
if (!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
M_ASN1_INTEGER_free(izone);
|
||||
return NULL;
|
||||
}
|
||||
oct = SXNET_get_id_INTEGER(sx, izone);
|
||||
M_ASN1_INTEGER_free(izone);
|
||||
return oct;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
|
||||
{
|
||||
SXNETID *id;
|
||||
size_t i;
|
||||
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
|
||||
id = sk_SXNETID_value(sx->ids, i);
|
||||
if (!M_ASN1_INTEGER_cmp(id->zone, zone))
|
||||
return id->user;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IMPLEMENT_ASN1_SET_OF(SXNETID)
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 53a17f55247101105ae35767d5c5a6c311843a8e
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 67818bea6690a230e2f42e8a588e0f54949bbbf1
|
||||
@@ -106,7 +106,10 @@ OPENSSL_EXPORT void AES_decrypt(const uint8_t *in, uint8_t *out,
|
||||
|
||||
// AES_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode) |len|
|
||||
// bytes from |in| to |out|. The |num| parameter must be set to zero on the
|
||||
// first call and |ivec| will be incremented.
|
||||
// first call and |ivec| will be incremented. This function may be called
|
||||
// in-place with |in| equal to |out|, but otherwise the buffers may not
|
||||
// partially overlap. A partial overlap may overwrite input data before it is
|
||||
// read.
|
||||
OPENSSL_EXPORT void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out,
|
||||
size_t len, const AES_KEY *key,
|
||||
uint8_t ivec[AES_BLOCK_SIZE],
|
||||
@@ -114,26 +117,35 @@ OPENSSL_EXPORT void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out,
|
||||
unsigned int *num);
|
||||
|
||||
// AES_ecb_encrypt encrypts (or decrypts, if |enc| == |AES_DECRYPT|) a single,
|
||||
// 16 byte block from |in| to |out|.
|
||||
// 16 byte block from |in| to |out|. This function may be called in-place with
|
||||
// |in| equal to |out|, but otherwise the buffers may not partially overlap. A
|
||||
// partial overlap may overwrite input data before it is read.
|
||||
OPENSSL_EXPORT void AES_ecb_encrypt(const uint8_t *in, uint8_t *out,
|
||||
const AES_KEY *key, const int enc);
|
||||
|
||||
// AES_cbc_encrypt encrypts (or decrypts, if |enc| == |AES_DECRYPT|) |len|
|
||||
// bytes from |in| to |out|. The length must be a multiple of the block size.
|
||||
// This function may be called in-place with |in| equal to |out|, but otherwise
|
||||
// the buffers may not partially overlap. A partial overlap may overwrite input
|
||||
// data before it is read.
|
||||
OPENSSL_EXPORT void AES_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const AES_KEY *key, uint8_t *ivec,
|
||||
const int enc);
|
||||
|
||||
// AES_ofb128_encrypt encrypts (or decrypts, it's the same in OFB mode) |len|
|
||||
// bytes from |in| to |out|. The |num| parameter must be set to zero on the
|
||||
// first call.
|
||||
// first call. This function may be called in-place with |in| equal to |out|,
|
||||
// but otherwise the buffers may not partially overlap. A partial overlap may
|
||||
// overwrite input data before it is read.
|
||||
OPENSSL_EXPORT void AES_ofb128_encrypt(const uint8_t *in, uint8_t *out,
|
||||
size_t len, const AES_KEY *key,
|
||||
uint8_t *ivec, int *num);
|
||||
|
||||
// AES_cfb128_encrypt encrypts (or decrypts, if |enc| == |AES_DECRYPT|) |len|
|
||||
// bytes from |in| to |out|. The |num| parameter must be set to zero on the
|
||||
// first call.
|
||||
// first call. This function may be called in-place with |in| equal to |out|,
|
||||
// but otherwise the buffers may not partially overlap. A partial overlap may
|
||||
// overwrite input data before it is read.
|
||||
OPENSSL_EXPORT void AES_cfb128_encrypt(const uint8_t *in, uint8_t *out,
|
||||
size_t len, const AES_KEY *key,
|
||||
uint8_t *ivec, int *num, int enc);
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#if __arm__ || __arm64__ || __aarch64__
|
||||
#ifndef OPENSSL_HEADER_ARM_ARCH_H
|
||||
#define OPENSSL_HEADER_ARM_ARCH_H
|
||||
@@ -117,6 +118,58 @@
|
||||
// ARMV8_PMULL indicates support for carryless multiplication.
|
||||
#define ARMV8_PMULL (1 << 5)
|
||||
|
||||
#if defined(__ASSEMBLER__)
|
||||
|
||||
// Support macros for
|
||||
// - Armv8.3-A Pointer Authentication and
|
||||
// - Armv8.5-A Branch Target Identification
|
||||
// features which require emitting a .note.gnu.property section with the
|
||||
// appropriate architecture-dependent feature bits set.
|
||||
// Read more: "ELF for the Arm® 64-bit Architecture"
|
||||
|
||||
#if (__ARM_FEATURE_BTI_DEFAULT == 1)
|
||||
#define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has Branch Target Identification
|
||||
#define AARCH64_VALID_CALL_TARGET hint #34 // BTI 'c'
|
||||
#else
|
||||
#define GNU_PROPERTY_AARCH64_BTI 0 // No Branch Target Identification
|
||||
#define AARCH64_VALID_CALL_TARGET
|
||||
#endif
|
||||
|
||||
#if ((__ARM_FEATURE_PAC_DEFAULT & 1) == 1) // Signed with A-key
|
||||
#define GNU_PROPERTY_AARCH64_POINTER_AUTH \
|
||||
(1 << 1) // Has Pointer Authentication
|
||||
#define AARCH64_SIGN_LINK_REGISTER hint #25 // PACIASP
|
||||
#define AARCH64_VALIDATE_LINK_REGISTER hint #29 // AUTIASP
|
||||
#elif ((__ARM_FEATURE_PAC_DEFAULT & 2) == 2) // Signed with B-key
|
||||
#define GNU_PROPERTY_AARCH64_POINTER_AUTH \
|
||||
(1 << 1) // Has Pointer Authentication
|
||||
#define AARCH64_SIGN_LINK_REGISTER hint #27 // PACIBSP
|
||||
#define AARCH64_VALIDATE_LINK_REGISTER hint #31 // AUTIBSP
|
||||
#else
|
||||
#define GNU_PROPERTY_AARCH64_POINTER_AUTH 0 // No Pointer Authentication
|
||||
#if defined(__ARM_FEATURE_BTI_DEFAULT)
|
||||
#define AARCH64_SIGN_LINK_REGISTER AARCH64_VALID_CALL_TARGET
|
||||
#else
|
||||
#define AARCH64_SIGN_LINK_REGISTER
|
||||
#endif
|
||||
#define AARCH64_VALIDATE_LINK_REGISTER
|
||||
#endif
|
||||
|
||||
#if (GNU_PROPERTY_AARCH64_POINTER_AUTH != 0) || (GNU_PROPERTY_AARCH64_BTI != 0)
|
||||
.pushsection note.gnu.property, "a";
|
||||
.balign 8;
|
||||
.long 4;
|
||||
.long 0x10;
|
||||
.long 0x5;
|
||||
.asciz "GNU";
|
||||
.long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
|
||||
.long 4;
|
||||
.long (GNU_PROPERTY_AARCH64_POINTER_AUTH | GNU_PROPERTY_AARCH64_BTI);
|
||||
.long 0
|
||||
.popsection
|
||||
#endif
|
||||
|
||||
#endif /* defined __ASSEMBLER__ */
|
||||
|
||||
#endif // OPENSSL_HEADER_ARM_ARCH_H
|
||||
#endif // __arm__ || __arm64__ || __aarch64__
|
||||
@@ -487,7 +487,6 @@ typedef struct BIT_STRING_BITNAME_st {
|
||||
|
||||
|
||||
#define M_ASN1_STRING_length(x) ((x)->length)
|
||||
#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
|
||||
#define M_ASN1_STRING_type(x) ((x)->type)
|
||||
#define M_ASN1_STRING_data(x) ((x)->data)
|
||||
|
||||
@@ -619,14 +618,14 @@ typedef struct BIT_STRING_BITNAME_st {
|
||||
|
||||
DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
|
||||
OPENSSL_EXPORT int ASN1_TYPE_get(ASN1_TYPE *a);
|
||||
OPENSSL_EXPORT int ASN1_TYPE_get(const ASN1_TYPE *a);
|
||||
OPENSSL_EXPORT void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
|
||||
OPENSSL_EXPORT int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
|
||||
OPENSSL_EXPORT int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
|
||||
|
||||
OPENSSL_EXPORT ASN1_OBJECT * ASN1_OBJECT_new(void );
|
||||
OPENSSL_EXPORT void ASN1_OBJECT_free(ASN1_OBJECT *a);
|
||||
OPENSSL_EXPORT int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
|
||||
OPENSSL_EXPORT int i2d_ASN1_OBJECT(const ASN1_OBJECT *a,unsigned char **pp);
|
||||
OPENSSL_EXPORT ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp,
|
||||
long length);
|
||||
OPENSSL_EXPORT ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp,
|
||||
@@ -648,23 +647,23 @@ OPENSSL_EXPORT int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len
|
||||
OPENSSL_EXPORT void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
|
||||
OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *x);
|
||||
OPENSSL_EXPORT void ASN1_STRING_length_set(ASN1_STRING *x, int n);
|
||||
OPENSSL_EXPORT int ASN1_STRING_type(ASN1_STRING *x);
|
||||
OPENSSL_EXPORT int ASN1_STRING_type(const ASN1_STRING *x);
|
||||
OPENSSL_EXPORT unsigned char * ASN1_STRING_data(ASN1_STRING *x);
|
||||
OPENSSL_EXPORT const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x);
|
||||
|
||||
DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
|
||||
OPENSSL_EXPORT int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
|
||||
OPENSSL_EXPORT int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a,unsigned char **pp);
|
||||
OPENSSL_EXPORT ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,const unsigned char **pp, long length);
|
||||
OPENSSL_EXPORT int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length );
|
||||
OPENSSL_EXPORT int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
|
||||
OPENSSL_EXPORT int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
|
||||
OPENSSL_EXPORT int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len);
|
||||
OPENSSL_EXPORT int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n);
|
||||
OPENSSL_EXPORT int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, unsigned char *flags, int flags_len);
|
||||
|
||||
OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
|
||||
OPENSSL_EXPORT int d2i_ASN1_BOOLEAN(int *a,const unsigned char **pp,long length);
|
||||
|
||||
DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
|
||||
OPENSSL_EXPORT int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
|
||||
OPENSSL_EXPORT int i2c_ASN1_INTEGER(const ASN1_INTEGER *a,unsigned char **pp);
|
||||
OPENSSL_EXPORT ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp, long length);
|
||||
OPENSSL_EXPORT ASN1_INTEGER * ASN1_INTEGER_dup(const ASN1_INTEGER *x);
|
||||
OPENSSL_EXPORT int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
|
||||
@@ -713,15 +712,15 @@ DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
|
||||
|
||||
OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
|
||||
OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s,time_t t, int offset_day, long offset_sec);
|
||||
OPENSSL_EXPORT int ASN1_TIME_check(ASN1_TIME *t);
|
||||
OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
|
||||
OPENSSL_EXPORT int ASN1_TIME_check(const ASN1_TIME *t);
|
||||
OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
|
||||
OPENSSL_EXPORT int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
|
||||
|
||||
OPENSSL_EXPORT int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
|
||||
OPENSSL_EXPORT int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a);
|
||||
OPENSSL_EXPORT int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type);
|
||||
OPENSSL_EXPORT int i2t_ASN1_OBJECT(char *buf,int buf_len, const ASN1_OBJECT *a);
|
||||
|
||||
OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, const char *sn, const char *ln);
|
||||
|
||||
@@ -732,9 +731,9 @@ OPENSSL_EXPORT ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *
|
||||
OPENSSL_EXPORT BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai,BIGNUM *bn);
|
||||
|
||||
OPENSSL_EXPORT int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
|
||||
OPENSSL_EXPORT long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
|
||||
OPENSSL_EXPORT ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
|
||||
OPENSSL_EXPORT BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
|
||||
OPENSSL_EXPORT long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
|
||||
OPENSSL_EXPORT ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai);
|
||||
OPENSSL_EXPORT BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai,BIGNUM *bn);
|
||||
|
||||
/* General */
|
||||
/* given a string, return the correct type, max is the maximum length */
|
||||
@@ -753,7 +752,7 @@ OPENSSL_EXPORT void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
OPENSSL_EXPORT void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
|
||||
OPENSSL_EXPORT int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
|
||||
OPENSSL_EXPORT int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
|
||||
OPENSSL_EXPORT int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags);
|
||||
#endif
|
||||
|
||||
OPENSSL_EXPORT int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
|
||||
@@ -764,12 +763,12 @@ OPENSSL_EXPORT int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
|
||||
OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
|
||||
OPENSSL_EXPORT int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a);
|
||||
OPENSSL_EXPORT int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
|
||||
OPENSSL_EXPORT int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
|
||||
OPENSSL_EXPORT int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags);
|
||||
OPENSSL_EXPORT const char *ASN1_tag2str(int tag);
|
||||
|
||||
/* Used to load and write netscape format cert */
|
||||
|
||||
OPENSSL_EXPORT void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
|
||||
OPENSSL_EXPORT void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it);
|
||||
|
||||
OPENSSL_EXPORT ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
|
||||
|
||||
@@ -793,8 +792,8 @@ OPENSSL_EXPORT ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, const unsigned char
|
||||
OPENSSL_EXPORT int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
|
||||
OPENSSL_EXPORT int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
|
||||
|
||||
OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
|
||||
OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
|
||||
OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf);
|
||||
OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Loaded 100 of 190 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user