mirror of
https://github.com/apple/swift-crypto
synced 2026-11-26 04:47:49 +00:00
Update BoringSSL to a9670a8b476470e6f874fef3554e8059683e1413 (#95)
This commit is contained in:
1 parent
f47c1950ae
commit
9b5ef28601
149 files changed
+4186
-3562
No files matched your search
+1
-1
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 25773430c07075a368416c3646fa4b07daf4968a
|
||||
// BoringSSL Commit: a9670a8b476470e6f874fef3554e8059683e1413
|
||||
|
||||
import PackageDescription
|
||||
|
||||
|
||||
-1
@@ -34,7 +34,6 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/asn1/asn1_lib.c"
|
||||
"crypto/asn1/asn1_par.c"
|
||||
"crypto/asn1/asn_pack.c"
|
||||
"crypto/asn1/f_enum.c"
|
||||
"crypto/asn1/f_int.c"
|
||||
"crypto/asn1/f_string.c"
|
||||
"crypto/asn1/tasn_dec.c"
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d, int len)
|
||||
@@ -70,8 +71,8 @@ int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d, int len)
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
static int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits) {
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits) {
|
||||
int len = str->length;
|
||||
if (str->flags & ASN1_STRING_FLAG_BITS_LEFT) {
|
||||
// If the string is already empty, it cannot have padding bits.
|
||||
@@ -79,8 +80,8 @@ static int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
return len;
|
||||
}
|
||||
|
||||
// TODO(davidben): If we move this logic to |ASN1_BIT_STRING_set_bit|, can
|
||||
// we remove this representation?
|
||||
// TODO(https://crbug.com/boringssl/447): If we move this logic to
|
||||
// |ASN1_BIT_STRING_set_bit|, can we remove this representation?
|
||||
while (len > 0 && str->data[len - 1] == 0) {
|
||||
len--;
|
||||
}
|
||||
@@ -158,11 +159,20 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
|
||||
p = *pp;
|
||||
padding = *(p++);
|
||||
len--;
|
||||
if (padding > 7) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Unused bits in a BIT STRING must be zero. */
|
||||
uint8_t padding_mask = (1 << padding) - 1;
|
||||
if (padding != 0 &&
|
||||
(len < 1 || (p[len - 1] & padding_mask) != 0)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* We do this to preserve the settings. If we modify the settings, via
|
||||
* the _set_bit function, we will recalculate on output
|
||||
@@ -170,21 +180,19 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
|
||||
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | padding); /* set */
|
||||
|
||||
if (len-- > 1) { /* using one because of the bits left byte */
|
||||
s = (unsigned char *)OPENSSL_malloc((int)len);
|
||||
if (len > 0) {
|
||||
s = OPENSSL_memdup(p, len);
|
||||
if (s == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
OPENSSL_memcpy(s, p, (int)len);
|
||||
s[len - 1] &= (0xff << padding);
|
||||
p += len;
|
||||
} else
|
||||
} else {
|
||||
s = NULL;
|
||||
}
|
||||
|
||||
ret->length = (int)len;
|
||||
if (ret->data != NULL)
|
||||
OPENSSL_free(ret->data);
|
||||
OPENSSL_free(ret->data);
|
||||
ret->data = s;
|
||||
ret->type = V_ASN1_BIT_STRING;
|
||||
if (a != NULL)
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
|
||||
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **pp)
|
||||
{
|
||||
int r;
|
||||
unsigned char *p, *allocated = NULL;
|
||||
@@ -71,7 +71,7 @@ int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
|
||||
if (*pp == NULL) {
|
||||
if ((p = allocated = OPENSSL_malloc(r)) == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
p = *pp;
|
||||
@@ -88,36 +88,35 @@ int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
|
||||
return r;
|
||||
}
|
||||
|
||||
int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length)
|
||||
{
|
||||
int ret = -1;
|
||||
const unsigned char *p;
|
||||
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *a, const unsigned char **pp,
|
||||
long length) {
|
||||
const unsigned char *p = *pp;
|
||||
long len;
|
||||
int inf, tag, xclass;
|
||||
int i = 0;
|
||||
|
||||
p = *pp;
|
||||
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
|
||||
if (inf & 0x80) {
|
||||
i = ASN1_R_BAD_OBJECT_HEADER;
|
||||
goto err;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tag != V_ASN1_BOOLEAN) {
|
||||
i = ASN1_R_EXPECTING_A_BOOLEAN;
|
||||
goto err;
|
||||
if (inf & V_ASN1_CONSTRUCTED) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tag != V_ASN1_BOOLEAN || xclass != V_ASN1_UNIVERSAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPECTING_A_BOOLEAN);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len != 1) {
|
||||
i = ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
|
||||
goto err;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
||||
return -1;
|
||||
}
|
||||
ret = (int)*(p++);
|
||||
if (a != NULL)
|
||||
ASN1_BOOLEAN ret = (ASN1_BOOLEAN)*(p++);
|
||||
if (a != NULL) {
|
||||
(*a) = ret;
|
||||
}
|
||||
*pp = p;
|
||||
return (ret);
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(ASN1, i);
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -69,20 +69,26 @@
|
||||
|
||||
int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
|
||||
{
|
||||
unsigned char *p, *allocated = NULL;
|
||||
int objsize;
|
||||
if (a == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((a == NULL) || (a->data == NULL))
|
||||
return (0);
|
||||
if (a->length == 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
|
||||
if (pp == NULL || objsize == -1)
|
||||
int objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
|
||||
if (pp == NULL || objsize == -1) {
|
||||
return objsize;
|
||||
}
|
||||
|
||||
unsigned char *p, *allocated = NULL;
|
||||
if (*pp == NULL) {
|
||||
if ((p = allocated = OPENSSL_malloc(objsize)) == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
p = *pp;
|
||||
@@ -104,54 +110,65 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a)
|
||||
return OBJ_obj2txt(buf, buf_len, a, 0);
|
||||
}
|
||||
|
||||
static int write_str(BIO *bp, const char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
return BIO_write(bp, str, len) == len ? len : -1;
|
||||
}
|
||||
|
||||
int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
|
||||
{
|
||||
char buf[80], *p = buf;
|
||||
int i;
|
||||
|
||||
if ((a == NULL) || (a->data == NULL))
|
||||
return (BIO_write(bp, "NULL", 4));
|
||||
i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
|
||||
if (i > (int)(sizeof(buf) - 1)) {
|
||||
p = OPENSSL_malloc(i + 1);
|
||||
if (!p)
|
||||
return -1;
|
||||
i2t_ASN1_OBJECT(p, i + 1, a);
|
||||
if (a == NULL || a->data == NULL) {
|
||||
return write_str(bp, "NULL");
|
||||
}
|
||||
if (i <= 0)
|
||||
return BIO_write(bp, "<INVALID>", 9);
|
||||
BIO_write(bp, p, i);
|
||||
if (p != buf)
|
||||
OPENSSL_free(p);
|
||||
return (i);
|
||||
|
||||
char buf[80], *allocated = NULL;
|
||||
const char *str = buf;
|
||||
int len = i2t_ASN1_OBJECT(buf, sizeof(buf), a);
|
||||
if (len > (int)sizeof(buf) - 1) {
|
||||
/* The input was truncated. Allocate a buffer that fits. */
|
||||
allocated = OPENSSL_malloc(len + 1);
|
||||
if (allocated == NULL) {
|
||||
return -1;
|
||||
}
|
||||
len = i2t_ASN1_OBJECT(allocated, len + 1, a);
|
||||
str = allocated;
|
||||
}
|
||||
if (len <= 0) {
|
||||
str = "<INVALID>";
|
||||
}
|
||||
|
||||
int ret = write_str(bp, str);
|
||||
OPENSSL_free(allocated);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
long length)
|
||||
{
|
||||
const unsigned char *p;
|
||||
long len;
|
||||
int tag, xclass;
|
||||
int inf, i;
|
||||
ASN1_OBJECT *ret = NULL;
|
||||
p = *pp;
|
||||
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
|
||||
const unsigned char *p = *pp;
|
||||
int inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
|
||||
if (inf & 0x80) {
|
||||
i = ASN1_R_BAD_OBJECT_HEADER;
|
||||
goto err;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (tag != V_ASN1_OBJECT) {
|
||||
i = ASN1_R_EXPECTING_AN_OBJECT;
|
||||
goto err;
|
||||
if (inf & V_ASN1_CONSTRUCTED) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return NULL;
|
||||
}
|
||||
ret = c2i_ASN1_OBJECT(a, &p, len);
|
||||
if (ret)
|
||||
|
||||
if (tag != V_ASN1_OBJECT || xclass != V_ASN1_UNIVERSAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPECTING_AN_OBJECT);
|
||||
return NULL;
|
||||
}
|
||||
ASN1_OBJECT *ret = c2i_ASN1_OBJECT(a, &p, len);
|
||||
if (ret) {
|
||||
*pp = p;
|
||||
}
|
||||
return ret;
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(ASN1, i);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
|
||||
@@ -56,18 +56,23 @@
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <stdlib.h> /* For bsearch */
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_stack.h>
|
||||
|
||||
DEFINE_STACK_OF(ASN1_STRING_TABLE)
|
||||
#include "../internal.h"
|
||||
#include "../lhash/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
|
||||
static void st_free(ASN1_STRING_TABLE *tbl);
|
||||
|
||||
DEFINE_LHASH_OF(ASN1_STRING_TABLE)
|
||||
|
||||
static LHASH_OF(ASN1_STRING_TABLE) *string_tables = NULL;
|
||||
static struct CRYPTO_STATIC_MUTEX string_tables_lock = CRYPTO_STATIC_MUTEX_INIT;
|
||||
|
||||
void ASN1_STRING_set_default_mask(unsigned long mask)
|
||||
{
|
||||
@@ -83,34 +88,36 @@ int ASN1_STRING_set_default_mask_asc(const char *p)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const ASN1_STRING_TABLE *asn1_string_table_get(int nid);
|
||||
|
||||
/*
|
||||
* The following function generates an ASN1_STRING based on limits in a
|
||||
* table. Frequently the types and length of an ASN1_STRING are restricted by
|
||||
* a corresponding OID. For example certificates and certificate requests.
|
||||
*/
|
||||
|
||||
ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
|
||||
const unsigned char *in, int inlen,
|
||||
int inform, int nid)
|
||||
ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
|
||||
int len, int inform, int nid)
|
||||
{
|
||||
ASN1_STRING_TABLE *tbl;
|
||||
ASN1_STRING *str = NULL;
|
||||
unsigned long mask;
|
||||
int ret;
|
||||
if (!out)
|
||||
if (!out) {
|
||||
out = &str;
|
||||
tbl = ASN1_STRING_TABLE_get(nid);
|
||||
if (tbl) {
|
||||
mask = tbl->mask;
|
||||
if (!(tbl->flags & STABLE_NO_MASK))
|
||||
mask &= B_ASN1_UTF8STRING;
|
||||
ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
|
||||
tbl->minsize, tbl->maxsize);
|
||||
} else {
|
||||
ret = ASN1_mbstring_copy(out, in, inlen, inform, B_ASN1_UTF8STRING);
|
||||
}
|
||||
if (ret <= 0)
|
||||
const ASN1_STRING_TABLE *tbl = asn1_string_table_get(nid);
|
||||
if (tbl != NULL) {
|
||||
unsigned long mask = tbl->mask;
|
||||
if (!(tbl->flags & STABLE_NO_MASK)) {
|
||||
mask &= B_ASN1_UTF8STRING;
|
||||
}
|
||||
ret = ASN1_mbstring_ncopy(out, in, len, inform, mask, tbl->minsize,
|
||||
tbl->maxsize);
|
||||
} else {
|
||||
ret = ASN1_mbstring_copy(out, in, len, inform, B_ASN1_UTF8STRING);
|
||||
}
|
||||
if (ret <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
return *out;
|
||||
}
|
||||
|
||||
@@ -118,15 +125,13 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
|
||||
* Now the tables and helper functions for the string table:
|
||||
*/
|
||||
|
||||
/* size limits: this stuff is taken straight from RFC 3280 */
|
||||
|
||||
/* See RFC 5280. */
|
||||
#define ub_name 32768
|
||||
#define ub_common_name 64
|
||||
#define ub_locality_name 128
|
||||
#define ub_state_name 128
|
||||
#define ub_organization_name 64
|
||||
#define ub_organization_unit_name 64
|
||||
#define ub_title 64
|
||||
#define ub_email_address 128
|
||||
#define ub_serial_number 64
|
||||
|
||||
@@ -157,120 +162,105 @@ static const ASN1_STRING_TABLE tbl_standard[] = {
|
||||
{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
|
||||
};
|
||||
|
||||
static int sk_table_cmp(const ASN1_STRING_TABLE **a,
|
||||
const ASN1_STRING_TABLE **b)
|
||||
static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b)
|
||||
{
|
||||
return (*a)->nid - (*b)->nid;
|
||||
if (a->nid < b->nid) {
|
||||
return -1;
|
||||
}
|
||||
if (a->nid > b->nid) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int table_cmp(const void *in_a, const void *in_b)
|
||||
static int table_cmp_void(const void *a, const void *b)
|
||||
{
|
||||
const ASN1_STRING_TABLE *a = in_a;
|
||||
const ASN1_STRING_TABLE *b = in_b;
|
||||
return a->nid - b->nid;
|
||||
return table_cmp(a, b);
|
||||
}
|
||||
|
||||
ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
|
||||
static uint32_t table_hash(const ASN1_STRING_TABLE *tbl)
|
||||
{
|
||||
int found;
|
||||
size_t idx;
|
||||
ASN1_STRING_TABLE *ttmp;
|
||||
ASN1_STRING_TABLE fnd;
|
||||
fnd.nid = nid;
|
||||
|
||||
ttmp =
|
||||
bsearch(&fnd, tbl_standard,
|
||||
sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE),
|
||||
sizeof(ASN1_STRING_TABLE), table_cmp);
|
||||
if (ttmp)
|
||||
return ttmp;
|
||||
if (!stable)
|
||||
return NULL;
|
||||
sk_ASN1_STRING_TABLE_sort(stable);
|
||||
found = sk_ASN1_STRING_TABLE_find(stable, &idx, &fnd);
|
||||
if (!found)
|
||||
return NULL;
|
||||
return sk_ASN1_STRING_TABLE_value(stable, idx);
|
||||
return OPENSSL_hash32(&tbl->nid, sizeof(tbl->nid));
|
||||
}
|
||||
|
||||
int ASN1_STRING_TABLE_add(int nid,
|
||||
long minsize, long maxsize, unsigned long mask,
|
||||
unsigned long flags)
|
||||
static const ASN1_STRING_TABLE *asn1_string_table_get(int nid)
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp;
|
||||
char new_nid = 0;
|
||||
flags &= ~STABLE_FLAGS_MALLOC;
|
||||
if (!stable)
|
||||
stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
|
||||
if (!stable) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
ASN1_STRING_TABLE key;
|
||||
key.nid = nid;
|
||||
const ASN1_STRING_TABLE *tbl =
|
||||
bsearch(&key, tbl_standard, OPENSSL_ARRAY_SIZE(tbl_standard),
|
||||
sizeof(ASN1_STRING_TABLE), table_cmp_void);
|
||||
if (tbl != NULL) {
|
||||
return tbl;
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_read(&string_tables_lock);
|
||||
if (string_tables != NULL) {
|
||||
tbl = lh_ASN1_STRING_TABLE_retrieve(string_tables, &key);
|
||||
}
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(&string_tables_lock);
|
||||
/* Note returning |tbl| without the lock is only safe because
|
||||
* |ASN1_STRING_TABLE_add| cannot modify or delete existing entries. If we
|
||||
* wish to support that, this function must copy the result under a lock. */
|
||||
return tbl;
|
||||
}
|
||||
|
||||
int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
|
||||
unsigned long mask, unsigned long flags)
|
||||
{
|
||||
/* Existing entries cannot be overwritten. */
|
||||
if (asn1_string_table_get(nid) != NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
if (!(tmp = ASN1_STRING_TABLE_get(nid))) {
|
||||
tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
|
||||
if (!tmp) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&string_tables_lock);
|
||||
|
||||
if (string_tables == NULL) {
|
||||
string_tables = lh_ASN1_STRING_TABLE_new(table_hash, table_cmp);
|
||||
if (string_tables == NULL) {
|
||||
goto err;
|
||||
}
|
||||
tmp->flags = flags | STABLE_FLAGS_MALLOC;
|
||||
tmp->nid = nid;
|
||||
tmp->minsize = tmp->maxsize = -1;
|
||||
new_nid = 1;
|
||||
} else
|
||||
tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
|
||||
if (minsize != -1)
|
||||
tmp->minsize = minsize;
|
||||
if (maxsize != -1)
|
||||
tmp->maxsize = maxsize;
|
||||
tmp->mask = mask;
|
||||
if (new_nid)
|
||||
sk_ASN1_STRING_TABLE_push(stable, tmp);
|
||||
return 1;
|
||||
} else {
|
||||
/* Check again for an existing entry. One may have been added while
|
||||
* unlocked. */
|
||||
ASN1_STRING_TABLE key;
|
||||
key.nid = nid;
|
||||
if (lh_ASN1_STRING_TABLE_retrieve(string_tables, &key) != NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
ASN1_STRING_TABLE *tbl = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
|
||||
if (tbl == NULL) {
|
||||
goto err;
|
||||
}
|
||||
tbl->nid = nid;
|
||||
tbl->flags = flags;
|
||||
tbl->minsize = minsize;
|
||||
tbl->maxsize = maxsize;
|
||||
tbl->mask = mask;
|
||||
ASN1_STRING_TABLE *old_tbl;
|
||||
if (!lh_ASN1_STRING_TABLE_insert(string_tables, &old_tbl, tbl)) {
|
||||
OPENSSL_free(tbl);
|
||||
goto err;
|
||||
}
|
||||
assert(old_tbl == NULL);
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&string_tables_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_STRING_TABLE_cleanup(void)
|
||||
{
|
||||
STACK_OF(ASN1_STRING_TABLE) *tmp;
|
||||
tmp = stable;
|
||||
if (!tmp)
|
||||
return;
|
||||
stable = NULL;
|
||||
sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
|
||||
}
|
||||
|
||||
static void st_free(ASN1_STRING_TABLE *tbl)
|
||||
{
|
||||
if (tbl->flags & STABLE_FLAGS_MALLOC)
|
||||
OPENSSL_free(tbl);
|
||||
void asn1_get_string_table_for_testing(const ASN1_STRING_TABLE **out_ptr,
|
||||
size_t *out_len) {
|
||||
*out_ptr = tbl_standard;
|
||||
*out_len = OPENSSL_ARRAY_SIZE(tbl_standard);
|
||||
}
|
||||
|
||||
#ifdef STRING_TABLE_TEST
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp;
|
||||
int i, last_nid = -1;
|
||||
|
||||
for (tmp = tbl_standard, i = 0;
|
||||
i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) {
|
||||
if (tmp->nid < last_nid) {
|
||||
last_nid = 0;
|
||||
break;
|
||||
}
|
||||
last_nid = tmp->nid;
|
||||
}
|
||||
|
||||
if (last_nid != 0) {
|
||||
printf("Table order OK\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
for (tmp = tbl_standard, i = 0;
|
||||
i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++)
|
||||
printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
|
||||
OBJ_nid2ln(tmp->nid));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_TIME)
|
||||
|
||||
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
|
||||
{
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/* Cross-module errors from crypto/x509/i2d_pr.c. */
|
||||
@@ -103,8 +104,7 @@ OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE)
|
||||
|
||||
static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
|
||||
long max);
|
||||
static int asn1_get_length(const unsigned char **pp, long *rl, long max);
|
||||
static void asn1_put_length(unsigned char **pp, int length);
|
||||
|
||||
int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
@@ -113,7 +113,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
int i, ret;
|
||||
long l;
|
||||
const unsigned char *p = *pp;
|
||||
int tag, xclass, inf;
|
||||
int tag, xclass;
|
||||
long max = omax;
|
||||
|
||||
if (!max)
|
||||
@@ -152,58 +152,43 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
|
||||
*ptag = tag;
|
||||
*pclass = xclass;
|
||||
if (!asn1_get_length(&p, &inf, plength, max))
|
||||
if (!asn1_get_length(&p, plength, max))
|
||||
goto err;
|
||||
|
||||
if (inf && !(ret & V_ASN1_CONSTRUCTED))
|
||||
goto err;
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
|
||||
(int)p, *plength, omax, (int)*pp, (int)(p + *plength),
|
||||
(int)(omax + *pp));
|
||||
|
||||
#endif
|
||||
if (*plength > (omax - (p - *pp))) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
/*
|
||||
* Set this so that even if things are not long enough the values are
|
||||
* set correctly
|
||||
*/
|
||||
ret |= 0x80;
|
||||
return 0x80;
|
||||
}
|
||||
*pp = p;
|
||||
return (ret | inf);
|
||||
return ret;
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return (0x80);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
|
||||
long max)
|
||||
static int asn1_get_length(const unsigned char **pp, long *rl, long max)
|
||||
{
|
||||
const unsigned char *p = *pp;
|
||||
unsigned long ret = 0;
|
||||
unsigned long i;
|
||||
|
||||
if (max-- < 1)
|
||||
if (max-- < 1) {
|
||||
return 0;
|
||||
}
|
||||
if (*p == 0x80) {
|
||||
*inf = 1;
|
||||
ret = 0;
|
||||
p++;
|
||||
/* We do not support BER indefinite-length encoding. */
|
||||
return 0;
|
||||
}
|
||||
i = *p & 0x7f;
|
||||
if (*(p++) & 0x80) {
|
||||
if (i > sizeof(ret) || max < (long)i)
|
||||
return 0;
|
||||
while (i-- > 0) {
|
||||
ret <<= 8L;
|
||||
ret |= *(p++);
|
||||
}
|
||||
} else {
|
||||
*inf = 0;
|
||||
i = *p & 0x7f;
|
||||
if (*(p++) & 0x80) {
|
||||
if (i > sizeof(ret) || max < (long)i)
|
||||
return 0;
|
||||
while (i-- > 0) {
|
||||
ret <<= 8L;
|
||||
ret |= *(p++);
|
||||
}
|
||||
} else
|
||||
ret = i;
|
||||
ret = i;
|
||||
}
|
||||
/*
|
||||
* Bound the length to comfortably fit in an int. Lengths in this module
|
||||
@@ -406,17 +391,44 @@ void ASN1_STRING_free(ASN1_STRING *str)
|
||||
|
||||
int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
|
||||
{
|
||||
int i;
|
||||
/* Capture padding bits and implicit truncation in BIT STRINGs. */
|
||||
int a_length = a->length, b_length = b->length;
|
||||
uint8_t a_padding = 0, b_padding = 0;
|
||||
if (a->type == V_ASN1_BIT_STRING) {
|
||||
a_length = asn1_bit_string_length(a, &a_padding);
|
||||
}
|
||||
if (b->type == V_ASN1_BIT_STRING) {
|
||||
b_length = asn1_bit_string_length(b, &b_padding);
|
||||
}
|
||||
|
||||
i = (a->length - b->length);
|
||||
if (i == 0) {
|
||||
i = OPENSSL_memcmp(a->data, b->data, a->length);
|
||||
if (i == 0)
|
||||
return (a->type - b->type);
|
||||
else
|
||||
return (i);
|
||||
} else
|
||||
return (i);
|
||||
if (a_length < b_length) {
|
||||
return -1;
|
||||
}
|
||||
if (a_length > b_length) {
|
||||
return 1;
|
||||
}
|
||||
/* In a BIT STRING, the number of bits is 8 * length - padding. Invert this
|
||||
* comparison so we compare by lengths. */
|
||||
if (a_padding > b_padding) {
|
||||
return -1;
|
||||
}
|
||||
if (a_padding < b_padding) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ret = OPENSSL_memcmp(a->data, b->data, a_length);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Comparing the type first is more natural, but this matches OpenSSL. */
|
||||
if (a->type < b->type) {
|
||||
return -1;
|
||||
}
|
||||
if (a->type > b->type) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_STRING_length(const ASN1_STRING *str)
|
||||
|
||||
@@ -59,47 +59,43 @@
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
/* ASN1_ITEM versions of the above */
|
||||
|
||||
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
|
||||
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **out)
|
||||
{
|
||||
ASN1_STRING *octmp;
|
||||
|
||||
if (!oct || !*oct) {
|
||||
if (!(octmp = ASN1_STRING_new())) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
if (oct)
|
||||
*oct = octmp;
|
||||
} else
|
||||
octmp = *oct;
|
||||
|
||||
if (octmp->data) {
|
||||
OPENSSL_free(octmp->data);
|
||||
octmp->data = NULL;
|
||||
}
|
||||
|
||||
if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
|
||||
uint8_t *new_data = NULL;
|
||||
int len = ASN1_item_i2d(obj, &new_data, it);
|
||||
if (len <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ENCODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
if (!octmp->data) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
return octmp;
|
||||
}
|
||||
|
||||
/* Extract an ASN1 object from an ASN1_STRING */
|
||||
ASN1_STRING *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_STRING_new();
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_free(new_data);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
ASN1_STRING_set0(ret, new_data, len);
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
|
||||
{
|
||||
const unsigned char *p;
|
||||
void *ret;
|
||||
|
||||
p = oct->data;
|
||||
if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
|
||||
const unsigned char *p = oct->data;
|
||||
void *ret = ASN1_item_d2i(NULL, &p, oct->length, it);
|
||||
if (ret == NULL || p != oct->data + oct->length) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
ASN1_item_free(ret, it);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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 acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS 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 AUTHOR OR 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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
/* Based on a_int.c: equivalent ENUMERATED functions */
|
||||
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) != 2)
|
||||
goto err;
|
||||
n = 2;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return (n);
|
||||
err:
|
||||
return (-1);
|
||||
}
|
||||
@@ -95,3 +95,8 @@ int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
|
||||
err:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
|
||||
{
|
||||
return i2a_ASN1_INTEGER(bp, a);
|
||||
}
|
||||
@@ -62,6 +62,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@@ -106,6 +107,25 @@ struct asn1_object_st {
|
||||
int flags; /* Should we free this one */
|
||||
};
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void);
|
||||
|
||||
// ASN1_ENCODING structure: this is used to save the received
|
||||
// encoding of an ASN1 type. This is useful to get round
|
||||
// problems with invalid encodings which can break signatures.
|
||||
typedef struct ASN1_ENCODING_st {
|
||||
unsigned char *enc; // DER encoding
|
||||
long len; // Length of encoding
|
||||
int modified; // set to 1 if 'enc' is invalid
|
||||
// alias_only is zero if |enc| owns the buffer that it points to
|
||||
// (although |enc| may still be NULL). If one, |enc| points into a
|
||||
// buffer that is owned elsewhere.
|
||||
unsigned alias_only : 1;
|
||||
// alias_only_on_next_parse is one iff the next parsing operation
|
||||
// should avoid taking a copy of the input and rather set
|
||||
// |alias_only|.
|
||||
unsigned alias_only_on_next_parse : 1;
|
||||
} ASN1_ENCODING;
|
||||
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d);
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d);
|
||||
|
||||
@@ -123,15 +143,31 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt,
|
||||
ASN1_TLC *ctx);
|
||||
|
||||
/* ASN1_item_ex_i2d encodes |*pval| as a value of type |it| to |out| under the
|
||||
* i2d output convention. It returns a non-zero length on success and -1 on
|
||||
* error. If |tag| is -1. the tag and class come from |it|. Otherwise, the tag
|
||||
* number is |tag| and the class is |aclass|. This is used for implicit tagging.
|
||||
* This function treats a missing value as an error, not an optional field. */
|
||||
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass);
|
||||
|
||||
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
/* asn1_get_choice_selector returns the CHOICE selector value for |*pval|, which
|
||||
* must of type |it|. */
|
||||
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
|
||||
|
||||
/* asn1_get_field_ptr returns a pointer to the field in |*pval| corresponding to
|
||||
* |tt|. */
|
||||
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
|
||||
/* asn1_do_adb returns the |ASN1_TEMPLATE| for the ANY DEFINED BY field |tt|,
|
||||
* based on the selector INTEGER or OID in |*pval|. If |tt| is not an ADB field,
|
||||
* it returns |tt|. If the selector does not match any value, it returns NULL.
|
||||
* If |nullerr| is non-zero, it will additionally push an error to the error
|
||||
* queue when there is no match. */
|
||||
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||
int nullerr);
|
||||
|
||||
@@ -140,8 +176,13 @@ int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
/* asn1_enc_restore, if |*pval| has a saved encoding, writes it to |out| under
|
||||
* the i2d output convention, sets |*len| to the length, and returns one. If it
|
||||
* has no saved encoding, it returns zero. */
|
||||
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||
const ASN1_ITEM *it);
|
||||
|
||||
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
|
||||
const ASN1_ITEM *it);
|
||||
|
||||
@@ -154,6 +195,27 @@ const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
|
||||
* ASN.1 PrintableString, and zero otherwise. */
|
||||
int asn1_is_printable(uint32_t value);
|
||||
|
||||
/* asn1_bit_string_length returns the number of bytes in |str| and sets
|
||||
* |*out_padding_bits| to the number of padding bits.
|
||||
*
|
||||
* This function should be used instead of |ASN1_STRING_length| to correctly
|
||||
* handle the non-|ASN1_STRING_FLAG_BITS_LEFT| case. */
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits);
|
||||
|
||||
typedef struct {
|
||||
int nid;
|
||||
long minsize;
|
||||
long maxsize;
|
||||
unsigned long mask;
|
||||
unsigned long flags;
|
||||
} ASN1_STRING_TABLE;
|
||||
|
||||
/* asn1_get_string_table_for_testing sets |*out_ptr| and |*out_len| to the table
|
||||
* of built-in |ASN1_STRING_TABLE| values. It is exported for testing. */
|
||||
OPENSSL_EXPORT void asn1_get_string_table_for_testing(
|
||||
const ASN1_STRING_TABLE **out_ptr, size_t *out_len);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern C */
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_buf.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
@@ -76,16 +75,9 @@
|
||||
#define ASN1_MAX_CONSTRUCTED_NEST 30
|
||||
|
||||
static int asn1_check_eoc(const unsigned char **in, long len);
|
||||
static int asn1_find_end(const unsigned char **in, long len, char inf);
|
||||
|
||||
static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
|
||||
char inf, int tag, int aclass, int depth);
|
||||
|
||||
static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen);
|
||||
|
||||
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
char *inf, char *cst,
|
||||
const unsigned char **in, long len,
|
||||
char *cst, const unsigned char **in, long len,
|
||||
int exptag, int expclass, char opt, ASN1_TLC *ctx);
|
||||
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **pval,
|
||||
@@ -97,7 +89,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
const ASN1_TEMPLATE *tt, char opt,
|
||||
ASN1_TLC *ctx, int depth);
|
||||
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
||||
int utype, char *free_cont, const ASN1_ITEM *it);
|
||||
int utype, const ASN1_ITEM *it);
|
||||
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it,
|
||||
@@ -170,11 +162,9 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
{
|
||||
const ASN1_TEMPLATE *tt, *errtt = NULL;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb;
|
||||
const unsigned char *p = NULL, *q;
|
||||
unsigned char oclass;
|
||||
char seq_eoc, seq_nolen, cst, isopt;
|
||||
char cst, isopt;
|
||||
int i;
|
||||
int otag;
|
||||
int ret = 0;
|
||||
@@ -183,10 +173,6 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
aclass &= ~ASN1_TFLG_COMBINE;
|
||||
if (!pval)
|
||||
return 0;
|
||||
if (aux && aux->asn1_cb)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
else
|
||||
asn1_cb = 0;
|
||||
|
||||
/*
|
||||
* Bound |len| to comfortably fit in an int. Lengths in this module often
|
||||
@@ -234,7 +220,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
|
||||
p = *in;
|
||||
/* Just read in tag and class */
|
||||
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
|
||||
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL,
|
||||
&p, len, -1, 0, 1, ctx);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
@@ -264,7 +250,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
ef = it->funcs;
|
||||
return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit tagging, so if
|
||||
* tag != -1, then this looks like an error in the template.
|
||||
@@ -274,6 +260,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto err;
|
||||
}
|
||||
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
|
||||
goto auxerr;
|
||||
|
||||
@@ -327,8 +315,9 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto auxerr;
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
p = *in;
|
||||
|
||||
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
|
||||
@@ -337,15 +326,13 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
/* Get SEQUENCE length and update len, p */
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, &cst,
|
||||
&p, len, tag, aclass, opt, ctx);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
} else if (ret == -1)
|
||||
return -1;
|
||||
/* If indefinite we don't do a length check */
|
||||
seq_nolen = seq_eoc;
|
||||
if (!cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
|
||||
goto err;
|
||||
@@ -356,6 +343,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto err;
|
||||
}
|
||||
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
|
||||
goto auxerr;
|
||||
|
||||
@@ -384,15 +373,12 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
if (!len)
|
||||
break;
|
||||
q = p;
|
||||
/* TODO(https://crbug.com/boringssl/455): Although we've removed
|
||||
* indefinite-length support, this check is not quite a no-op.
|
||||
* Reject [UNIVERSAL 0] in the tag parsers themselves. */
|
||||
if (asn1_check_eoc(&p, len)) {
|
||||
if (!seq_eoc) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
|
||||
goto err;
|
||||
}
|
||||
len -= p - q;
|
||||
seq_eoc = 0;
|
||||
q = p;
|
||||
break;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
* This determines the OPTIONAL flag value. The field cannot be
|
||||
@@ -424,13 +410,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
len -= p - q;
|
||||
}
|
||||
|
||||
/* Check for EOC if expecting one */
|
||||
if (seq_eoc && !asn1_check_eoc(&p, len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
|
||||
goto err;
|
||||
}
|
||||
/* Check all data read */
|
||||
if (!seq_nolen && len) {
|
||||
if (len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
@@ -462,6 +443,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto auxerr;
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
@@ -500,7 +482,6 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
int ret;
|
||||
long len;
|
||||
const unsigned char *p, *q;
|
||||
char exp_eoc;
|
||||
if (!val)
|
||||
return 0;
|
||||
flags = tt->flags;
|
||||
@@ -515,7 +496,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
* Need to work out amount of data available to the inner content and
|
||||
* where it starts: so read in EXPLICIT header to get the info.
|
||||
*/
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, &cst,
|
||||
&p, inlen, tt->tag, aclass, opt, ctx);
|
||||
q = p;
|
||||
if (!ret) {
|
||||
@@ -535,20 +516,10 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
|
||||
}
|
||||
/* We read the field in OK so update length */
|
||||
len -= p - q;
|
||||
if (exp_eoc) {
|
||||
/* If NDEF we must have an EOC here */
|
||||
if (!asn1_check_eoc(&p, len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Otherwise we must hit the EXPLICIT tag end or its an error
|
||||
*/
|
||||
if (len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
/* Check for trailing data. */
|
||||
if (len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
} else
|
||||
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx, depth);
|
||||
@@ -579,7 +550,6 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
if (flags & ASN1_TFLG_SK_MASK) {
|
||||
/* SET OF, SEQUENCE OF */
|
||||
int sktag, skaclass;
|
||||
char sk_eoc;
|
||||
/* First work out expected inner tag value */
|
||||
if (flags & ASN1_TFLG_IMPTAG) {
|
||||
sktag = tt->tag;
|
||||
@@ -592,7 +562,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
sktag = V_ASN1_SEQUENCE;
|
||||
}
|
||||
/* Get the tag */
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, NULL,
|
||||
&p, len, sktag, skaclass, opt, ctx);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
@@ -622,15 +592,12 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
while (len > 0) {
|
||||
ASN1_VALUE *skfield;
|
||||
const unsigned char *q = p;
|
||||
/* See if EOC found */
|
||||
/* TODO(https://crbug.com/boringssl/455): Although we've removed
|
||||
* indefinite-length support, this check is not quite a no-op.
|
||||
* Reject [UNIVERSAL 0] in the tag parsers themselves. */
|
||||
if (asn1_check_eoc(&p, len)) {
|
||||
if (!sk_eoc) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
|
||||
goto err;
|
||||
}
|
||||
len -= p - q;
|
||||
sk_eoc = 0;
|
||||
break;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
|
||||
goto err;
|
||||
}
|
||||
skfield = NULL;
|
||||
if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item),
|
||||
@@ -645,10 +612,6 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (sk_eoc) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
|
||||
goto err;
|
||||
}
|
||||
} else if (flags & ASN1_TFLG_IMPTAG) {
|
||||
/* IMPLICIT tagging */
|
||||
ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag,
|
||||
@@ -685,9 +648,8 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
{
|
||||
int ret = 0, utype;
|
||||
long plen;
|
||||
char cst, inf, free_cont = 0;
|
||||
char cst;
|
||||
const unsigned char *p;
|
||||
BUF_MEM buf = {0, NULL, 0 };
|
||||
const unsigned char *cont = NULL;
|
||||
long len;
|
||||
if (!pval) {
|
||||
@@ -713,7 +675,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
return 0;
|
||||
}
|
||||
p = *in;
|
||||
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
|
||||
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL,
|
||||
&p, inlen, -1, 0, 0, ctx);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
@@ -728,7 +690,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
}
|
||||
p = *in;
|
||||
/* Check header */
|
||||
ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
|
||||
ret = asn1_check_tlen(&plen, NULL, NULL, &cst,
|
||||
&p, inlen, tag, aclass, opt, ctx);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
@@ -753,43 +715,14 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
}
|
||||
|
||||
cont = *in;
|
||||
/* If indefinite length constructed find the real end */
|
||||
if (inf) {
|
||||
if (!asn1_find_end(&p, plen, inf))
|
||||
goto err;
|
||||
len = p - cont;
|
||||
} else {
|
||||
len = p - cont + plen;
|
||||
p += plen;
|
||||
}
|
||||
len = p - cont + plen;
|
||||
p += plen;
|
||||
} else if (cst) {
|
||||
if (utype == V_ASN1_NULL || utype == V_ASN1_BOOLEAN
|
||||
|| utype == V_ASN1_OBJECT || utype == V_ASN1_INTEGER
|
||||
|| utype == V_ASN1_ENUMERATED) {
|
||||
/* These types only have primitive encodings. */
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Free any returned 'buf' content */
|
||||
free_cont = 1;
|
||||
/*
|
||||
* Should really check the internal tags are correct but some things
|
||||
* may get this wrong. The relevant specs say that constructed string
|
||||
* types should be OCTET STRINGs internally irrespective of the type.
|
||||
* So instead just check for UNIVERSAL class and ignore the tag.
|
||||
*/
|
||||
if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) {
|
||||
goto err;
|
||||
}
|
||||
len = buf.length;
|
||||
/* Append a final null to string */
|
||||
if (!BUF_MEM_grow_clean(&buf, len + 1)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
buf.data[len] = 0;
|
||||
cont = (const unsigned char *)buf.data;
|
||||
/* This parser historically supported BER constructed strings. We no
|
||||
* longer do and will gradually tighten this parser into a DER
|
||||
* parser. BER types should use |CBS_asn1_ber_to_der|. */
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
} else {
|
||||
cont = p;
|
||||
len = plen;
|
||||
@@ -797,22 +730,19 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
}
|
||||
|
||||
/* We now have content length and type: translate into a structure */
|
||||
/* asn1_ex_c2i may reuse allocated buffer, and so sets free_cont to 0 */
|
||||
if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it))
|
||||
if (!asn1_ex_c2i(pval, cont, len, utype, it))
|
||||
goto err;
|
||||
|
||||
*in = p;
|
||||
ret = 1;
|
||||
err:
|
||||
if (free_cont && buf.data)
|
||||
OPENSSL_free(buf.data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Translate ASN1 content octets into a structure */
|
||||
|
||||
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
||||
int utype, char *free_cont, const ASN1_ITEM *it)
|
||||
int utype, const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_VALUE **opval = NULL;
|
||||
ASN1_STRING *stmp;
|
||||
@@ -916,20 +846,11 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
||||
stmp = (ASN1_STRING *)*pval;
|
||||
stmp->type = utype;
|
||||
}
|
||||
/* If we've already allocated a buffer use it */
|
||||
if (*free_cont) {
|
||||
if (stmp->data)
|
||||
OPENSSL_free(stmp->data);
|
||||
stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
|
||||
stmp->length = len;
|
||||
*free_cont = 0;
|
||||
} else {
|
||||
if (!ASN1_STRING_set(stmp, cont, len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
ASN1_STRING_free(stmp);
|
||||
*pval = NULL;
|
||||
goto err;
|
||||
}
|
||||
if (!ASN1_STRING_set(stmp, cont, len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
ASN1_STRING_free(stmp);
|
||||
*pval = NULL;
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -947,145 +868,6 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function finds the end of an ASN1 structure when passed its maximum
|
||||
* length, whether it is indefinite length and a pointer to the content. This
|
||||
* is more efficient than calling asn1_collect because it does not recurse on
|
||||
* each indefinite length header.
|
||||
*/
|
||||
|
||||
static int asn1_find_end(const unsigned char **in, long len, char inf)
|
||||
{
|
||||
int expected_eoc;
|
||||
long plen;
|
||||
const unsigned char *p = *in, *q;
|
||||
/* If not indefinite length constructed just add length */
|
||||
if (inf == 0) {
|
||||
*in += len;
|
||||
return 1;
|
||||
}
|
||||
expected_eoc = 1;
|
||||
/*
|
||||
* Indefinite length constructed form. Find the end when enough EOCs are
|
||||
* found. If more indefinite length constructed headers are encountered
|
||||
* increment the expected eoc count otherwise just skip to the end of the
|
||||
* data.
|
||||
*/
|
||||
while (len > 0) {
|
||||
if (asn1_check_eoc(&p, len)) {
|
||||
expected_eoc--;
|
||||
if (expected_eoc == 0)
|
||||
break;
|
||||
len -= 2;
|
||||
continue;
|
||||
}
|
||||
q = p;
|
||||
/* Just read in a header: only care about the length */
|
||||
if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
|
||||
-1, 0, 0, NULL)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (inf)
|
||||
expected_eoc++;
|
||||
else
|
||||
p += plen;
|
||||
len -= p - q;
|
||||
}
|
||||
if (expected_eoc) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
|
||||
return 0;
|
||||
}
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function collects the asn1 data from a constructred string type into
|
||||
* a buffer. The values of 'in' and 'len' should refer to the contents of the
|
||||
* constructed type and 'inf' should be set if it is indefinite length.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This determines how many levels of recursion are permitted in ASN1 string
|
||||
* types. If it is not limited stack overflows can occur. If set to zero no
|
||||
* recursion is allowed at all. Although zero should be adequate examples
|
||||
* exist that require a value of 1. So 5 should be more than enough.
|
||||
*/
|
||||
#define ASN1_MAX_STRING_NEST 5
|
||||
|
||||
static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
|
||||
char inf, int tag, int aclass, int depth)
|
||||
{
|
||||
const unsigned char *p, *q;
|
||||
long plen;
|
||||
char cst, ininf;
|
||||
p = *in;
|
||||
inf &= 1;
|
||||
/*
|
||||
* If no buffer and not indefinite length constructed just pass over the
|
||||
* encoded data
|
||||
*/
|
||||
if (!buf && !inf) {
|
||||
*in += len;
|
||||
return 1;
|
||||
}
|
||||
while (len > 0) {
|
||||
q = p;
|
||||
/* Check for EOC */
|
||||
if (asn1_check_eoc(&p, len)) {
|
||||
/*
|
||||
* EOC is illegal outside indefinite length constructed form
|
||||
*/
|
||||
if (!inf) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
|
||||
return 0;
|
||||
}
|
||||
inf = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
|
||||
len, tag, aclass, 0, NULL)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If indefinite length constructed update max length */
|
||||
if (cst) {
|
||||
if (depth >= ASN1_MAX_STRING_NEST) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_STRING);
|
||||
return 0;
|
||||
}
|
||||
if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, depth + 1))
|
||||
return 0;
|
||||
} else if (plen && !collect_data(buf, &p, plen))
|
||||
return 0;
|
||||
len -= p - q;
|
||||
}
|
||||
if (inf) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
|
||||
return 0;
|
||||
}
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
|
||||
{
|
||||
int len;
|
||||
if (buf) {
|
||||
len = buf->length;
|
||||
if (!BUF_MEM_grow_clean(buf, len + plen)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(buf->data + len, *p, plen);
|
||||
}
|
||||
*p += plen;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check for ASN1 EOC and swallow it if found */
|
||||
|
||||
static int asn1_check_eoc(const unsigned char **in, long len)
|
||||
@@ -1102,15 +884,12 @@ static int asn1_check_eoc(const unsigned char **in, long len)
|
||||
}
|
||||
|
||||
/*
|
||||
* Check an ASN1 tag and length: a bit like ASN1_get_object but it sets the
|
||||
* length for indefinite length constructed form, we don't know the exact
|
||||
* length but we can set an upper bound to the amount of data available minus
|
||||
* the header length just read.
|
||||
* Check an ASN1 tag and length: a bit like ASN1_get_object but it handles
|
||||
* the ASN1_TLC cache and checks the expected tag.
|
||||
*/
|
||||
|
||||
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
char *inf, char *cst,
|
||||
const unsigned char **in, long len,
|
||||
char *cst, const unsigned char **in, long len,
|
||||
int exptag, int expclass, char opt, ASN1_TLC *ctx)
|
||||
{
|
||||
int i;
|
||||
@@ -1136,10 +915,13 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
ctx->hdrlen = p - q;
|
||||
ctx->valid = 1;
|
||||
/*
|
||||
* If definite length, and no error, length + header can't exceed
|
||||
* total amount of data available.
|
||||
* If no error, length + header can't exceed total amount of data
|
||||
* available.
|
||||
*
|
||||
* TODO(davidben): Is this check necessary? |ASN1_get_object|
|
||||
* should already guarantee this.
|
||||
*/
|
||||
if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
|
||||
if (!(i & 0x80) && ((plen + ctx->hdrlen) > len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
asn1_tlc_clear(ctx);
|
||||
return 0;
|
||||
@@ -1170,12 +952,6 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
asn1_tlc_clear(ctx);
|
||||
}
|
||||
|
||||
if (i & 1)
|
||||
plen = len - (p - q);
|
||||
|
||||
if (inf)
|
||||
*inf = i & 1;
|
||||
|
||||
if (cst)
|
||||
*cst = i & V_ASN1_CONSTRUCTED;
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -66,53 +67,47 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass,
|
||||
int optional);
|
||||
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass);
|
||||
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
|
||||
const ASN1_ITEM *it);
|
||||
const ASN1_ITEM *it, int tag, int aclass,
|
||||
int optional);
|
||||
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *out_omit,
|
||||
int *putype, const ASN1_ITEM *it);
|
||||
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
int skcontlen, const ASN1_ITEM *item,
|
||||
int do_sort, int iclass);
|
||||
int skcontlen, const ASN1_ITEM *item, int do_sort);
|
||||
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt, int tag, int aclass);
|
||||
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
|
||||
const ASN1_ITEM *it, int flags);
|
||||
|
||||
/*
|
||||
* Top level i2d equivalents
|
||||
*/
|
||||
|
||||
int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
|
||||
{
|
||||
return asn1_item_flags_i2d(val, out, it, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode an ASN1 item, this is use by the standard 'i2d' function. 'out'
|
||||
* points to a buffer to output the data to. The new i2d has one additional
|
||||
* feature. If the output buffer is NULL (i.e. *out == NULL) then a buffer is
|
||||
* allocated and populated with the encoding.
|
||||
*/
|
||||
|
||||
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
|
||||
const ASN1_ITEM *it, int flags)
|
||||
{
|
||||
if (out && !*out) {
|
||||
unsigned char *p, *buf;
|
||||
int len;
|
||||
len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
|
||||
if (len <= 0)
|
||||
int len = ASN1_item_ex_i2d(&val, NULL, it, /*tag=*/-1, /*aclass=*/0);
|
||||
if (len <= 0) {
|
||||
return len;
|
||||
}
|
||||
buf = OPENSSL_malloc(len);
|
||||
if (!buf)
|
||||
if (!buf) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
p = buf;
|
||||
ASN1_item_ex_i2d(&val, &p, it, -1, flags);
|
||||
int len2 = ASN1_item_ex_i2d(&val, &p, it, /*tag=*/-1, /*aclass=*/0);
|
||||
if (len2 <= 0) {
|
||||
return len2;
|
||||
}
|
||||
assert(len == len2);
|
||||
*out = buf;
|
||||
return len;
|
||||
}
|
||||
|
||||
return ASN1_item_ex_i2d(&val, out, it, -1, flags);
|
||||
return ASN1_item_ex_i2d(&val, out, it, /*tag=*/-1, /*aclass=*/0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -122,27 +117,48 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
|
||||
|
||||
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass)
|
||||
{
|
||||
int ret = asn1_item_ex_i2d_opt(pval, out, it, tag, aclass, /*optional=*/0);
|
||||
assert(ret != 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* asn1_item_ex_i2d_opt behaves like |ASN1_item_ex_i2d| but, if |optional| is
|
||||
* non-zero and |*pval| is omitted, it returns zero and writes no bytes. */
|
||||
int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass,
|
||||
int optional)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt = NULL;
|
||||
int i, seqcontlen, seqlen;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = 0;
|
||||
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
|
||||
return 0;
|
||||
/* Historically, |aclass| was repurposed to pass additional flags into the
|
||||
* encoding process. */
|
||||
assert((aclass & ASN1_TFLG_TAG_CLASS) == aclass);
|
||||
/* If not overridding the tag, |aclass| is ignored and should be zero. */
|
||||
assert(tag != -1 || aclass == 0);
|
||||
|
||||
if (aux && aux->asn1_cb)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
/* All fields are pointers, except for boolean |ASN1_ITYPE_PRIMITIVE|s.
|
||||
* Optional primitives are handled later. */
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) {
|
||||
if (optional) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates)
|
||||
return asn1_template_ex_i2d(pval, out, it->templates,
|
||||
tag, aclass);
|
||||
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
|
||||
break;
|
||||
if (it->templates) {
|
||||
if (it->templates->flags & ASN1_TFLG_OPTIONAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass, optional);
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
/*
|
||||
@@ -153,9 +169,9 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
|
||||
return asn1_i2d_ex_primitive(pval, out, it, -1, 0, optional);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit tagging, so if
|
||||
* tag != -1, then this looks like an error in the template.
|
||||
@@ -164,31 +180,39 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
|
||||
return 0;
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
ASN1_VALUE **pchval;
|
||||
const ASN1_TEMPLATE *chtt;
|
||||
chtt = it->templates + i;
|
||||
pchval = asn1_get_field_ptr(pval, chtt);
|
||||
return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);
|
||||
if (i < 0 || i >= it->tcount) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
|
||||
return -1;
|
||||
}
|
||||
/* Fixme: error condition if selector out of range */
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
|
||||
return 0;
|
||||
break;
|
||||
const ASN1_TEMPLATE *chtt = it->templates + i;
|
||||
if (chtt->flags & ASN1_TFLG_OPTIONAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
ASN1_VALUE **pchval = asn1_get_field_ptr(pval, chtt);
|
||||
return asn1_template_ex_i2d(pchval, out, chtt, -1, 0);
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
case ASN1_ITYPE_EXTERN: {
|
||||
/* If new style i2d it does all the work */
|
||||
ef = it->funcs;
|
||||
return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
|
||||
const ASN1_EXTERN_FUNCS *ef = it->funcs;
|
||||
int ret = ef->asn1_ex_i2d(pval, out, it, tag, aclass);
|
||||
if (ret == 0) {
|
||||
/* |asn1_ex_i2d| should never return zero. We have already checked
|
||||
* for optional values generically, and |ASN1_ITYPE_EXTERN| fields
|
||||
* must be pointers. */
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
i = asn1_enc_restore(&seqcontlen, out, pval, it);
|
||||
/* An error occurred */
|
||||
if (i < 0)
|
||||
return 0;
|
||||
return -1;
|
||||
/* We have a valid cached encoding... */
|
||||
if (i > 0)
|
||||
return seqcontlen;
|
||||
@@ -197,12 +221,8 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
|
||||
if (tag == -1) {
|
||||
tag = V_ASN1_SEQUENCE;
|
||||
/* Retain any other flags in aclass */
|
||||
aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
|
||||
| V_ASN1_UNIVERSAL;
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
|
||||
return 0;
|
||||
/* First work out sequence content length */
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
@@ -210,9 +230,9 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
int tmplen;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (!seqtt)
|
||||
return 0;
|
||||
return -1;
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, aclass);
|
||||
tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, 0);
|
||||
if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen))
|
||||
return -1;
|
||||
seqcontlen += tmplen;
|
||||
@@ -228,40 +248,49 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (!seqtt)
|
||||
return 0;
|
||||
return -1;
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
/* FIXME: check for errors in enhanced version */
|
||||
asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);
|
||||
if (asn1_template_ex_i2d(pseqval, out, seqtt, -1, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
|
||||
return 0;
|
||||
return seqlen;
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* asn1_template_ex_i2d behaves like |asn1_item_ex_i2d_opt| but uses an
|
||||
* |ASN1_TEMPLATE| instead of an |ASN1_ITEM|. An |ASN1_TEMPLATE| wraps an
|
||||
* |ASN1_ITEM| with modifiers such as tagging, SEQUENCE or SET, etc. Instead of
|
||||
* taking an |optional| parameter, it uses the |ASN1_TFLG_OPTIONAL| flag. */
|
||||
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt, int tag, int iclass)
|
||||
{
|
||||
int i, ret, flags, ttag, tclass;
|
||||
size_t j;
|
||||
flags = tt->flags;
|
||||
|
||||
/* Historically, |iclass| was repurposed to pass additional flags into the
|
||||
* encoding process. */
|
||||
assert((iclass & ASN1_TFLG_TAG_CLASS) == iclass);
|
||||
/* If not overridding the tag, |iclass| is ignored and should be zero. */
|
||||
assert(tag != -1 || iclass == 0);
|
||||
|
||||
/*
|
||||
* Work out tag and class to use: tagging may come either from the
|
||||
* template or the arguments, not both because this would create
|
||||
* ambiguity. Additionally the iclass argument may contain some
|
||||
* additional flags which should be noted and passed down to other
|
||||
* levels.
|
||||
* ambiguity.
|
||||
*/
|
||||
if (flags & ASN1_TFLG_TAG_MASK) {
|
||||
/* Error if argument and template tagging */
|
||||
if (tag != -1)
|
||||
/* FIXME: error code here */
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
/* Get tagging from template */
|
||||
ttag = tt->tag;
|
||||
tclass = flags & ASN1_TFLG_TAG_CLASS;
|
||||
@@ -273,14 +302,12 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
ttag = -1;
|
||||
tclass = 0;
|
||||
}
|
||||
/*
|
||||
* Remove any class mask from iflag.
|
||||
*/
|
||||
iclass &= ~ASN1_TFLG_TAG_CLASS;
|
||||
|
||||
const int optional = (flags & ASN1_TFLG_OPTIONAL) != 0;
|
||||
|
||||
/*
|
||||
* At this point 'ttag' contains the outer tag to use, 'tclass' is the
|
||||
* class and iclass is any flags passed to this function.
|
||||
* At this point 'ttag' contains the outer tag to use, and 'tclass' is the
|
||||
* class.
|
||||
*/
|
||||
|
||||
if (flags & ASN1_TFLG_SK_MASK) {
|
||||
@@ -290,8 +317,13 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
int skcontlen, sklen;
|
||||
ASN1_VALUE *skitem;
|
||||
|
||||
if (!*pval)
|
||||
return 0;
|
||||
if (!*pval) {
|
||||
if (optional) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & ASN1_TFLG_SET_OF) {
|
||||
isset = 1;
|
||||
@@ -323,7 +355,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
int tmplen;
|
||||
skitem = sk_ASN1_VALUE_value(sk, j);
|
||||
tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item),
|
||||
-1, iclass);
|
||||
-1, 0);
|
||||
if (tmplen == -1 || (skcontlen > INT_MAX - tmplen))
|
||||
return -1;
|
||||
skcontlen += tmplen;
|
||||
@@ -347,30 +379,36 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
/* SET or SEQUENCE and IMPLICIT tag */
|
||||
ASN1_put_object(out, /*constructed=*/1, skcontlen, sktag, skaclass);
|
||||
/* And the stuff itself */
|
||||
asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
|
||||
isset, iclass);
|
||||
if (!asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
|
||||
isset)) {
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (flags & ASN1_TFLG_EXPTAG) {
|
||||
/* EXPLICIT tagging */
|
||||
/* Find length of tagged item */
|
||||
i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, iclass);
|
||||
if (!i)
|
||||
return 0;
|
||||
i = asn1_item_ex_i2d_opt(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0,
|
||||
optional);
|
||||
if (i <= 0)
|
||||
return i;
|
||||
/* Find length of EXPLICIT tag */
|
||||
ret = ASN1_object_size(/*constructed=*/1, i, ttag);
|
||||
if (out && ret != -1) {
|
||||
/* Output tag and item */
|
||||
ASN1_put_object(out, /*constructed=*/1, i, ttag, tclass);
|
||||
ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, iclass);
|
||||
if (ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1,
|
||||
0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Either normal or IMPLICIT tagging: combine class and flags */
|
||||
return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
|
||||
ttag, tclass | iclass);
|
||||
/* Either normal or IMPLICIT tagging */
|
||||
return asn1_item_ex_i2d_opt(pval, out, ASN1_ITEM_ptr(tt->item),
|
||||
ttag, tclass, optional);
|
||||
|
||||
}
|
||||
|
||||
@@ -392,93 +430,96 @@ static int der_cmp(const void *a, const void *b)
|
||||
return d1->length - d2->length;
|
||||
}
|
||||
|
||||
/* Output the content octets of SET OF or SEQUENCE OF */
|
||||
|
||||
/* asn1_set_seq_out writes |sk| to |out| under the i2d output convention,
|
||||
* excluding the tag and length. It returns one on success and zero on error.
|
||||
* |skcontlen| must be the total encoded size. If |do_sort| is non-zero, the
|
||||
* elements are sorted for a SET OF type. Each element of |sk| has type
|
||||
* |item|. */
|
||||
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
int skcontlen, const ASN1_ITEM *item,
|
||||
int do_sort, int iclass)
|
||||
int skcontlen, const ASN1_ITEM *item, int do_sort)
|
||||
{
|
||||
size_t i;
|
||||
ASN1_VALUE *skitem;
|
||||
unsigned char *tmpdat = NULL, *p = NULL;
|
||||
DER_ENC *derlst = NULL, *tder;
|
||||
if (do_sort) {
|
||||
/* Don't need to sort less than 2 items */
|
||||
if (sk_ASN1_VALUE_num(sk) < 2)
|
||||
do_sort = 0;
|
||||
else {
|
||||
derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)
|
||||
* sizeof(*derlst));
|
||||
if (!derlst)
|
||||
return 0;
|
||||
tmpdat = OPENSSL_malloc(skcontlen);
|
||||
if (!tmpdat) {
|
||||
OPENSSL_free(derlst);
|
||||
/* No need to sort if there are fewer than two items. */
|
||||
if (!do_sort || sk_ASN1_VALUE_num(sk) < 2) {
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
if (ASN1_item_ex_i2d(&skitem, out, item, -1, 0) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If not sorting just output each item */
|
||||
if (!do_sort) {
|
||||
for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
p = tmpdat;
|
||||
|
||||
/* Doing sort: build up a list of each member's DER encoding */
|
||||
for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
|
||||
skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
tder->data = p;
|
||||
tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);
|
||||
if (sk_ASN1_VALUE_num(sk) > ((size_t)-1) / sizeof(DER_ENC)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Now sort them */
|
||||
qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
|
||||
/* Output sorted DER encoding */
|
||||
int ret = 0;
|
||||
unsigned char *const buf = OPENSSL_malloc(skcontlen);
|
||||
DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded));
|
||||
if (encoded == NULL || buf == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Encode all the elements into |buf| and populate |encoded|. */
|
||||
unsigned char *p = buf;
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
encoded[i].data = p;
|
||||
encoded[i].length = ASN1_item_ex_i2d(&skitem, &p, item, -1, 0);
|
||||
if (encoded[i].length < 0) {
|
||||
goto err;
|
||||
}
|
||||
assert(p - buf <= skcontlen);
|
||||
}
|
||||
|
||||
qsort(encoded, sk_ASN1_VALUE_num(sk), sizeof(*encoded), der_cmp);
|
||||
|
||||
/* Output the elements in sorted order. */
|
||||
p = *out;
|
||||
for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
|
||||
OPENSSL_memcpy(p, tder->data, tder->length);
|
||||
p += tder->length;
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
OPENSSL_memcpy(p, encoded[i].data, encoded[i].length);
|
||||
p += encoded[i].length;
|
||||
}
|
||||
*out = p;
|
||||
OPENSSL_free(derlst);
|
||||
OPENSSL_free(tmpdat);
|
||||
return 1;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(encoded);
|
||||
OPENSSL_free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* asn1_i2d_ex_primitive behaves like |ASN1_item_ex_i2d| but |item| must be a
|
||||
* a PRIMITIVE or MSTRING type that is not an |ASN1_ITEM_TEMPLATE|. */
|
||||
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass)
|
||||
const ASN1_ITEM *it, int tag, int aclass,
|
||||
int optional)
|
||||
{
|
||||
int len;
|
||||
int utype;
|
||||
int usetag;
|
||||
|
||||
utype = it->utype;
|
||||
|
||||
/*
|
||||
* Get length of content octets and maybe find out the underlying type.
|
||||
*/
|
||||
|
||||
len = asn1_ex_i2c(pval, NULL, &utype, it);
|
||||
/* Get length of content octets and maybe find out the underlying type. */
|
||||
int omit;
|
||||
int utype = it->utype;
|
||||
int len = asn1_ex_i2c(pval, NULL, &omit, &utype, it);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (omit) {
|
||||
if (optional) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If SEQUENCE, SET or OTHER then header is included in pseudo content
|
||||
* octets so don't include tag+length. We need to check here because the
|
||||
* call to asn1_ex_i2c() could change utype.
|
||||
*/
|
||||
if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
|
||||
(utype == V_ASN1_OTHER))
|
||||
usetag = 0;
|
||||
else
|
||||
usetag = 1;
|
||||
|
||||
/* -1 means omit type */
|
||||
|
||||
if (len == -1)
|
||||
return 0;
|
||||
int usetag = utype != V_ASN1_SEQUENCE && utype != V_ASN1_SET &&
|
||||
utype != V_ASN1_OTHER;
|
||||
|
||||
/* If not implicitly tagged get tag from underlying type */
|
||||
if (tag == -1)
|
||||
@@ -486,21 +527,42 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
|
||||
|
||||
/* Output tag+length followed by content octets */
|
||||
if (out) {
|
||||
if (usetag)
|
||||
if (usetag) {
|
||||
ASN1_put_object(out, /*constructed=*/0, len, tag, aclass);
|
||||
asn1_ex_i2c(pval, *out, &utype, it);
|
||||
}
|
||||
int len2 = asn1_ex_i2c(pval, *out, &omit, &utype, it);
|
||||
if (len2 < 0) {
|
||||
return -1;
|
||||
}
|
||||
assert(len == len2);
|
||||
assert(!omit);
|
||||
*out += len;
|
||||
}
|
||||
|
||||
if (usetag)
|
||||
if (usetag) {
|
||||
return ASN1_object_size(/*constructed=*/0, len, tag);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Produce content octets from a structure */
|
||||
|
||||
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
const ASN1_ITEM *it)
|
||||
/* asn1_ex_i2c writes the |*pval| to |cout| under the i2d output convention,
|
||||
* excluding the tag and length. It returns the number of bytes written,
|
||||
* possibly zero, on success or -1 on error. If |*pval| should be omitted, it
|
||||
* returns zero and sets |*out_omit| to true.
|
||||
*
|
||||
* If |it| is an MSTRING or ANY type, it gets the underlying type from |*pval|,
|
||||
* which must be an |ASN1_STRING| or |ASN1_TYPE|, respectively. It then updates
|
||||
* |*putype| with the tag number of type used, or |V_ASN1_OTHER| if it was not a
|
||||
* universal type. If |*putype| is set to |V_ASN1_SEQUENCE|, |V_ASN1_SET|, or
|
||||
* |V_ASN1_OTHER|, it additionally outputs the tag and length, so the caller
|
||||
* must not do so.
|
||||
*
|
||||
* Otherwise, |*putype| must contain |it->utype|.
|
||||
*
|
||||
* WARNING: Unlike most functions in this file, |asn1_ex_i2c| can return zero
|
||||
* without omitting the element. ASN.1 values may have empty contents. */
|
||||
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit,
|
||||
int *putype, const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_BOOLEAN *tbool = NULL;
|
||||
ASN1_STRING *strtmp;
|
||||
@@ -514,17 +576,26 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
* |ASN1_PRIMITIVE_FUNCS| table of callbacks. */
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
*out_omit = 0;
|
||||
|
||||
/* Should type be omitted? */
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE)
|
||||
|| (it->utype != V_ASN1_BOOLEAN)) {
|
||||
if (!*pval)
|
||||
return -1;
|
||||
if (!*pval) {
|
||||
*out_omit = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
/* If MSTRING type set the underlying type */
|
||||
strtmp = (ASN1_STRING *)*pval;
|
||||
utype = strtmp->type;
|
||||
if (utype < 0 && utype != V_ASN1_OTHER) {
|
||||
/* MSTRINGs can have type -1 when default-constructed. */
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
||||
return -1;
|
||||
}
|
||||
/* Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values
|
||||
* that do not match their corresponding utype values. INTEGERs cannot
|
||||
* participate in MSTRING types, but ENUMERATEDs can.
|
||||
@@ -545,6 +616,11 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
ASN1_TYPE *typ;
|
||||
typ = (ASN1_TYPE *)*pval;
|
||||
utype = typ->type;
|
||||
if (utype < 0 && utype != V_ASN1_OTHER) {
|
||||
/* |ASN1_TYPE|s can have type -1 when default-constructed. */
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
||||
return -1;
|
||||
}
|
||||
*putype = utype;
|
||||
pval = &typ->value.asn1_value;
|
||||
} else
|
||||
@@ -555,8 +631,11 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
otmp = (ASN1_OBJECT *)*pval;
|
||||
cont = otmp->data;
|
||||
len = otmp->length;
|
||||
if (cont == NULL || len == 0)
|
||||
if (len == 0) {
|
||||
/* Some |ASN1_OBJECT|s do not have OIDs and cannot be serialized. */
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
@@ -566,34 +645,39 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
tbool = (ASN1_BOOLEAN *)pval;
|
||||
if (*tbool == -1)
|
||||
return -1;
|
||||
if (*tbool == -1) {
|
||||
*out_omit = 1;
|
||||
return 0;
|
||||
}
|
||||
if (it->utype != V_ASN1_ANY) {
|
||||
/*
|
||||
* Default handling if value == size field then omit
|
||||
*/
|
||||
if (*tbool && (it->size > 0))
|
||||
return -1;
|
||||
if (!*tbool && !it->size)
|
||||
return -1;
|
||||
if ((*tbool && (it->size > 0)) ||
|
||||
(!*tbool && !it->size)) {
|
||||
*out_omit = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
c = *tbool ? 0xff : 0x00;
|
||||
cont = &c;
|
||||
len = 1;
|
||||
break;
|
||||
|
||||
case V_ASN1_BIT_STRING:
|
||||
return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
|
||||
cout ? &cout : NULL);
|
||||
break;
|
||||
case V_ASN1_BIT_STRING: {
|
||||
int ret = i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
|
||||
cout ? &cout : NULL);
|
||||
/* |i2c_ASN1_BIT_STRING| returns zero on error instead of -1. */
|
||||
return ret <= 0 ? -1 : ret;
|
||||
}
|
||||
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
/*
|
||||
* These are all have the same content format as ASN1_INTEGER
|
||||
*/
|
||||
return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
|
||||
break;
|
||||
case V_ASN1_ENUMERATED: {
|
||||
/* |i2c_ASN1_INTEGER| also handles ENUMERATED. */
|
||||
int ret = i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
|
||||
/* |i2c_ASN1_INTEGER| returns zero on error instead of -1. */
|
||||
return ret <= 0 ? -1 : ret;
|
||||
}
|
||||
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
|
||||
@@ -79,17 +79,11 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt = NULL, *seqtt;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb;
|
||||
int i;
|
||||
if (!pval)
|
||||
return;
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
|
||||
return;
|
||||
if (aux && aux->asn1_cb)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
else
|
||||
asn1_cb = 0;
|
||||
|
||||
switch (it->itype) {
|
||||
|
||||
@@ -104,7 +98,9 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
ASN1_primitive_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
|
||||
if (i == 2)
|
||||
@@ -124,6 +120,7 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
*pval = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
@@ -131,9 +128,11 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
ef->asn1_ex_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
if (!asn1_refcount_dec_and_test_zero(pval, it))
|
||||
return;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
|
||||
if (i == 2)
|
||||
@@ -162,6 +161,7 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||
|
||||
@@ -95,14 +95,8 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
{
|
||||
const ASN1_TEMPLATE *tt = NULL;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb;
|
||||
ASN1_VALUE **pseqval;
|
||||
int i;
|
||||
if (aux && aux->asn1_cb)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
else
|
||||
asn1_cb = 0;
|
||||
|
||||
switch (it->itype) {
|
||||
|
||||
@@ -127,7 +121,9 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
goto memerr;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
|
||||
if (!i)
|
||||
@@ -146,8 +142,11 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
|
||||
goto auxerr2;
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
|
||||
if (!i)
|
||||
@@ -173,6 +172,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
goto auxerr2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
memerr2:
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
|
||||
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
|
||||
IMPLEMENT_ASN1_TYPE(sname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(sname, sname, sname) \
|
||||
sname *sname##_new(void) \
|
||||
{ \
|
||||
return ASN1_STRING_type_new(V_##sname); \
|
||||
@@ -88,7 +88,7 @@ IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_NULL)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_NULL)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
|
||||
|
||||
@@ -97,18 +97,20 @@ IMPLEMENT_ASN1_TYPE(ASN1_ANY)
|
||||
/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
|
||||
/* Multistring types */
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, ASN1_PRINTABLE,
|
||||
ASN1_PRINTABLE)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DISPLAYTEXT, DISPLAYTEXT)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DIRECTORYSTRING,
|
||||
DIRECTORYSTRING)
|
||||
|
||||
/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
|
||||
|
||||
@@ -118,6 +118,7 @@ int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
}
|
||||
|
||||
static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
assert(it->itype == ASN1_ITYPE_SEQUENCE);
|
||||
const ASN1_AUX *aux;
|
||||
if (!pval || !*pval) {
|
||||
return NULL;
|
||||
|
||||
@@ -265,14 +265,17 @@ static uint8_t base64_ascii_to_bin(uint8_t a) {
|
||||
const uint8_t is_slash = constant_time_eq_8(a, '/');
|
||||
const uint8_t is_equals = constant_time_eq_8(a, '=');
|
||||
|
||||
uint8_t ret = 0xff; // 0xff signals invalid.
|
||||
ret = constant_time_select_8(is_upper, a - 'A', ret); // [0,26)
|
||||
ret = constant_time_select_8(is_lower, a - 'a' + 26, ret); // [26,52)
|
||||
ret = constant_time_select_8(is_digit, a - '0' + 52, ret); // [52,62)
|
||||
ret = constant_time_select_8(is_plus, 62, ret);
|
||||
ret = constant_time_select_8(is_slash, 63, ret);
|
||||
// Padding maps to zero, to be further handled by the caller.
|
||||
ret = constant_time_select_8(is_equals, 0, ret);
|
||||
uint8_t ret = 0;
|
||||
ret |= is_upper & (a - 'A'); // [0,26)
|
||||
ret |= is_lower & (a - 'a' + 26); // [26,52)
|
||||
ret |= is_digit & (a - '0' + 52); // [52,62)
|
||||
ret |= is_plus & 62;
|
||||
ret |= is_slash & 63;
|
||||
// Invalid inputs, 'A', and '=' have all been mapped to zero. Map invalid
|
||||
// inputs to 0xff. Note '=' is padding and handled separately by the caller.
|
||||
const uint8_t is_valid =
|
||||
is_upper | is_lower | is_digit | is_plus | is_slash | is_equals;
|
||||
ret |= ~is_valid;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,19 +42,17 @@ static const uint8_t kSigma[10 * 16] = {
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
#define RIGHT_ROTATE(v, n) (((v) >> (n)) | ((v) << (64 - (n))))
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.1
|
||||
static void blake2b_mix(uint64_t v[16], int a, int b, int c, int d, uint64_t x,
|
||||
uint64_t y) {
|
||||
v[a] = v[a] + v[b] + x;
|
||||
v[d] = RIGHT_ROTATE(v[d] ^ v[a], 32);
|
||||
v[d] = CRYPTO_rotr_u64(v[d] ^ v[a], 32);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = RIGHT_ROTATE(v[b] ^ v[c], 24);
|
||||
v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 24);
|
||||
v[a] = v[a] + v[b] + y;
|
||||
v[d] = RIGHT_ROTATE(v[d] ^ v[a], 16);
|
||||
v[d] = CRYPTO_rotr_u64(v[d] ^ v[a], 16);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = RIGHT_ROTATE(v[b] ^ v[c], 63);
|
||||
v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 63);
|
||||
}
|
||||
|
||||
static void blake2b_transform(
|
||||
|
||||
@@ -29,8 +29,10 @@ static const unsigned kMaxDepth = 2048;
|
||||
// is_string_type returns one if |tag| is a string type and zero otherwise. It
|
||||
// ignores the constructed bit.
|
||||
static int is_string_type(unsigned tag) {
|
||||
// While BER supports constructed BIT STRINGS, OpenSSL misparses them. To
|
||||
// avoid acting on an ambiguous input, we do not support constructed BIT
|
||||
// STRINGS. See https://github.com/openssl/openssl/issues/12810.
|
||||
switch (tag & ~CBS_ASN1_CONSTRUCTED) {
|
||||
case CBS_ASN1_BITSTRING:
|
||||
case CBS_ASN1_OCTETSTRING:
|
||||
case CBS_ASN1_UTF8STRING:
|
||||
case CBS_ASN1_NUMERICSTRING:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -25,22 +25,20 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#define U8TO32_LITTLE(p) \
|
||||
(((uint32_t)((p)[0])) | ((uint32_t)((p)[1]) << 8) | \
|
||||
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24))
|
||||
|
||||
// sigma contains the ChaCha constants, which happen to be an ASCII string.
|
||||
static const uint8_t sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3',
|
||||
'2', '-', 'b', 'y', 't', 'e', ' ', 'k' };
|
||||
|
||||
#define ROTATE(v, n) (((v) << (n)) | ((v) >> (32 - (n))))
|
||||
|
||||
// QUARTERROUND updates a, b, c, d with a ChaCha "quarter" round.
|
||||
#define QUARTERROUND(a, b, c, d) \
|
||||
x[a] += x[b]; x[d] = ROTATE(x[d] ^ x[a], 16); \
|
||||
x[c] += x[d]; x[b] = ROTATE(x[b] ^ x[c], 12); \
|
||||
x[a] += x[b]; x[d] = ROTATE(x[d] ^ x[a], 8); \
|
||||
x[c] += x[d]; x[b] = ROTATE(x[b] ^ x[c], 7);
|
||||
#define QUARTERROUND(a, b, c, d) \
|
||||
x[a] += x[b]; \
|
||||
x[d] = CRYPTO_rotl_u32(x[d] ^ x[a], 16); \
|
||||
x[c] += x[d]; \
|
||||
x[b] = CRYPTO_rotl_u32(x[b] ^ x[c], 12); \
|
||||
x[a] += x[b]; \
|
||||
x[d] = CRYPTO_rotl_u32(x[d] ^ x[a], 8); \
|
||||
x[c] += x[d]; \
|
||||
x[b] = CRYPTO_rotl_u32(x[b] ^ x[c], 7);
|
||||
|
||||
void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
|
||||
const uint8_t nonce[16]) {
|
||||
@@ -71,24 +69,25 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
uint32_t counter) {
|
||||
assert(!buffers_alias(out, in_len, in, in_len) || in == out);
|
||||
|
||||
uint32_t counter_nonce[4]; counter_nonce[0] = counter;
|
||||
counter_nonce[1] = U8TO32_LITTLE(nonce + 0);
|
||||
counter_nonce[2] = U8TO32_LITTLE(nonce + 4);
|
||||
counter_nonce[3] = U8TO32_LITTLE(nonce + 8);
|
||||
uint32_t counter_nonce[4];
|
||||
counter_nonce[0] = counter;
|
||||
counter_nonce[1] = CRYPTO_load_u32_le(nonce + 0);
|
||||
counter_nonce[2] = CRYPTO_load_u32_le(nonce + 4);
|
||||
counter_nonce[3] = CRYPTO_load_u32_le(nonce + 8);
|
||||
|
||||
const uint32_t *key_ptr = (const uint32_t *)key;
|
||||
#if !defined(OPENSSL_X86) && !defined(OPENSSL_X86_64)
|
||||
// The assembly expects the key to be four-byte aligned.
|
||||
uint32_t key_u32[8];
|
||||
if ((((uintptr_t)key) & 3) != 0) {
|
||||
key_u32[0] = U8TO32_LITTLE(key + 0);
|
||||
key_u32[1] = U8TO32_LITTLE(key + 4);
|
||||
key_u32[2] = U8TO32_LITTLE(key + 8);
|
||||
key_u32[3] = U8TO32_LITTLE(key + 12);
|
||||
key_u32[4] = U8TO32_LITTLE(key + 16);
|
||||
key_u32[5] = U8TO32_LITTLE(key + 20);
|
||||
key_u32[6] = U8TO32_LITTLE(key + 24);
|
||||
key_u32[7] = U8TO32_LITTLE(key + 28);
|
||||
key_u32[0] = CRYPTO_load_u32_le(key + 0);
|
||||
key_u32[1] = CRYPTO_load_u32_le(key + 4);
|
||||
key_u32[2] = CRYPTO_load_u32_le(key + 8);
|
||||
key_u32[3] = CRYPTO_load_u32_le(key + 12);
|
||||
key_u32[4] = CRYPTO_load_u32_le(key + 16);
|
||||
key_u32[5] = CRYPTO_load_u32_le(key + 20);
|
||||
key_u32[6] = CRYPTO_load_u32_le(key + 24);
|
||||
key_u32[7] = CRYPTO_load_u32_le(key + 28);
|
||||
|
||||
key_ptr = key_u32;
|
||||
}
|
||||
@@ -99,14 +98,6 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
|
||||
#else
|
||||
|
||||
#define U32TO8_LITTLE(p, v) \
|
||||
{ \
|
||||
(p)[0] = (v >> 0) & 0xff; \
|
||||
(p)[1] = (v >> 8) & 0xff; \
|
||||
(p)[2] = (v >> 16) & 0xff; \
|
||||
(p)[3] = (v >> 24) & 0xff; \
|
||||
}
|
||||
|
||||
// chacha_core performs 20 rounds of ChaCha on the input words in
|
||||
// |input| and writes the 64 output bytes to |output|.
|
||||
static void chacha_core(uint8_t output[64], const uint32_t input[16]) {
|
||||
@@ -129,7 +120,7 @@ static void chacha_core(uint8_t output[64], const uint32_t input[16]) {
|
||||
x[i] += input[i];
|
||||
}
|
||||
for (i = 0; i < 16; ++i) {
|
||||
U32TO8_LITTLE(output + 4 * i, x[i]);
|
||||
CRYPTO_store_u32_le(output + 4 * i, x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,25 +133,25 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
uint8_t buf[64];
|
||||
size_t todo, i;
|
||||
|
||||
input[0] = U8TO32_LITTLE(sigma + 0);
|
||||
input[1] = U8TO32_LITTLE(sigma + 4);
|
||||
input[2] = U8TO32_LITTLE(sigma + 8);
|
||||
input[3] = U8TO32_LITTLE(sigma + 12);
|
||||
input[0] = CRYPTO_load_u32_le(sigma + 0);
|
||||
input[1] = CRYPTO_load_u32_le(sigma + 4);
|
||||
input[2] = CRYPTO_load_u32_le(sigma + 8);
|
||||
input[3] = CRYPTO_load_u32_le(sigma + 12);
|
||||
|
||||
input[4] = U8TO32_LITTLE(key + 0);
|
||||
input[5] = U8TO32_LITTLE(key + 4);
|
||||
input[6] = U8TO32_LITTLE(key + 8);
|
||||
input[7] = U8TO32_LITTLE(key + 12);
|
||||
input[4] = CRYPTO_load_u32_le(key + 0);
|
||||
input[5] = CRYPTO_load_u32_le(key + 4);
|
||||
input[6] = CRYPTO_load_u32_le(key + 8);
|
||||
input[7] = CRYPTO_load_u32_le(key + 12);
|
||||
|
||||
input[8] = U8TO32_LITTLE(key + 16);
|
||||
input[9] = U8TO32_LITTLE(key + 20);
|
||||
input[10] = U8TO32_LITTLE(key + 24);
|
||||
input[11] = U8TO32_LITTLE(key + 28);
|
||||
input[8] = CRYPTO_load_u32_le(key + 16);
|
||||
input[9] = CRYPTO_load_u32_le(key + 20);
|
||||
input[10] = CRYPTO_load_u32_le(key + 24);
|
||||
input[11] = CRYPTO_load_u32_le(key + 28);
|
||||
|
||||
input[12] = counter;
|
||||
input[13] = U8TO32_LITTLE(nonce + 0);
|
||||
input[14] = U8TO32_LITTLE(nonce + 4);
|
||||
input[15] = U8TO32_LITTLE(nonce + 8);
|
||||
input[13] = CRYPTO_load_u32_le(nonce + 0);
|
||||
input[14] = CRYPTO_load_u32_le(nonce + 4);
|
||||
input[15] = CRYPTO_load_u32_le(nonce + 8);
|
||||
|
||||
while (in_len > 0) {
|
||||
todo = sizeof(buf);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -67,25 +67,42 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static const struct {
|
||||
int nid;
|
||||
const char *name;
|
||||
const EVP_CIPHER *(*func)(void);
|
||||
} kCiphers[] = {
|
||||
{NID_aes_128_cbc, "aes-128-cbc", EVP_aes_128_cbc},
|
||||
{NID_aes_128_ctr, "aes-128-ctr", EVP_aes_128_ctr},
|
||||
{NID_aes_128_ecb, "aes-128-ecb", EVP_aes_128_ecb},
|
||||
{NID_aes_128_gcm, "aes-128-gcm", EVP_aes_128_gcm},
|
||||
{NID_aes_128_ofb128, "aes-128-ofb", EVP_aes_128_ofb},
|
||||
{NID_aes_192_cbc, "aes-192-cbc", EVP_aes_192_cbc},
|
||||
{NID_aes_192_ctr, "aes-192-ctr", EVP_aes_192_ctr},
|
||||
{NID_aes_192_ecb, "aes-192-ecb", EVP_aes_192_ecb},
|
||||
{NID_aes_192_gcm, "aes-192-gcm", EVP_aes_192_gcm},
|
||||
{NID_aes_192_ofb128, "aes-192-ofb", EVP_aes_192_ofb},
|
||||
{NID_aes_256_cbc, "aes-256-cbc", EVP_aes_256_cbc},
|
||||
{NID_aes_256_ctr, "aes-256-ctr", EVP_aes_256_ctr},
|
||||
{NID_aes_256_ecb, "aes-256-ecb", EVP_aes_256_ecb},
|
||||
{NID_aes_256_gcm, "aes-256-gcm", EVP_aes_256_gcm},
|
||||
{NID_aes_256_ofb128, "aes-256-ofb", EVP_aes_256_ofb},
|
||||
{NID_des_cbc, "des-cbc", EVP_des_cbc},
|
||||
{NID_des_ecb, "des-ecb", EVP_des_ecb},
|
||||
{NID_des_ede_cbc, "des-ede-cbc", EVP_des_ede_cbc},
|
||||
{NID_des_ede_ecb, "des-ede", EVP_des_ede},
|
||||
{NID_des_ede3_cbc, "des-ede3-cbc", EVP_des_ede3_cbc},
|
||||
{NID_rc2_cbc, "rc2-cbc", EVP_rc2_cbc},
|
||||
{NID_rc4, "rc4", EVP_rc4},
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbynid(int nid) {
|
||||
switch (nid) {
|
||||
case NID_rc2_cbc:
|
||||
return EVP_rc2_cbc();
|
||||
case NID_rc2_40_cbc:
|
||||
return EVP_rc2_40_cbc();
|
||||
case NID_des_ede3_cbc:
|
||||
return EVP_des_ede3_cbc();
|
||||
case NID_des_ede_cbc:
|
||||
return EVP_des_cbc();
|
||||
case NID_aes_128_cbc:
|
||||
return EVP_aes_128_cbc();
|
||||
case NID_aes_192_cbc:
|
||||
return EVP_aes_192_cbc();
|
||||
case NID_aes_256_cbc:
|
||||
return EVP_aes_256_cbc();
|
||||
default:
|
||||
return NULL;
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) {
|
||||
if (kCiphers[i].nid == nid) {
|
||||
return kCiphers[i].func();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
|
||||
@@ -93,54 +110,17 @@ const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (OPENSSL_strcasecmp(name, "rc4") == 0) {
|
||||
return EVP_rc4();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-cbc") == 0) {
|
||||
return EVP_des_cbc();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-ede3-cbc") == 0 ||
|
||||
// This is not a name used by OpenSSL, but tcpdump registers it
|
||||
// with |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a
|
||||
// no-op, so we support the name here.
|
||||
OPENSSL_strcasecmp(name, "3des") == 0) {
|
||||
return EVP_des_ede3_cbc();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-128-cbc") == 0) {
|
||||
return EVP_aes_128_cbc();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-192-cbc") == 0) {
|
||||
return EVP_aes_192_cbc();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-256-cbc") == 0) {
|
||||
return EVP_aes_256_cbc();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-128-ctr") == 0) {
|
||||
return EVP_aes_128_ctr();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-192-ctr") == 0) {
|
||||
return EVP_aes_192_ctr();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-256-ctr") == 0) {
|
||||
return EVP_aes_256_ctr();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-128-ecb") == 0) {
|
||||
return EVP_aes_128_ecb();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-192-ecb") == 0) {
|
||||
return EVP_aes_192_ecb();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-256-ecb") == 0) {
|
||||
return EVP_aes_256_ecb();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-128-gcm") == 0) {
|
||||
return EVP_aes_128_gcm();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-192-gcm") == 0) {
|
||||
return EVP_aes_192_gcm();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-256-gcm") == 0) {
|
||||
return EVP_aes_256_gcm();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-128-ofb") == 0) {
|
||||
return EVP_aes_128_ofb();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-192-ofb") == 0) {
|
||||
return EVP_aes_192_ofb();
|
||||
} else if (OPENSSL_strcasecmp(name, "aes-256-ofb") == 0) {
|
||||
return EVP_aes_256_ofb();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-ecb") == 0) {
|
||||
return EVP_des_ecb();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-ede") == 0) {
|
||||
return EVP_des_ede();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-ede-cbc") == 0) {
|
||||
return EVP_des_ede_cbc();
|
||||
} else if (OPENSSL_strcasecmp(name, "rc2-cbc") == 0) {
|
||||
return EVP_rc2_cbc();
|
||||
// This is not a name used by OpenSSL, but tcpdump registers it with
|
||||
// |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a no-op, so we
|
||||
// support the name here.
|
||||
if (OPENSSL_strcasecmp(name, "3des") == 0) {
|
||||
name = "des-ede3-cbc";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) {
|
||||
if (OPENSSL_strcasecmp(kCiphers[i].name, name) == 0) {
|
||||
return kCiphers[i].func();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -369,8 +369,8 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **out, const uint8_t **inp,
|
||||
// Unlike OpenSSL, we do not support EC keys with this API. The raw EC
|
||||
// public key serialization requires knowing the group. In OpenSSL, calling
|
||||
// this function with |EVP_PKEY_EC| and setting |out| to NULL does not work.
|
||||
// It requires |*out| to include a partially-initiazed |EVP_PKEY| to extract
|
||||
// the group.
|
||||
// It requires |*out| to include a partially-initialized |EVP_PKEY| to
|
||||
// extract the group.
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
|
||||
goto err;
|
||||
|
||||
@@ -32,8 +32,6 @@ typedef struct { uint32_t words[16]; } block_t;
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(block_t) == 64, "block_t has padding");
|
||||
|
||||
#define R(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
|
||||
// salsa208_word_specification implements the Salsa20/8 core function, also
|
||||
// described in RFC 7914, section 3. It modifies the block at |inout|
|
||||
// in-place.
|
||||
@@ -42,38 +40,38 @@ static void salsa208_word_specification(block_t *inout) {
|
||||
OPENSSL_memcpy(&x, inout, sizeof(x));
|
||||
|
||||
for (int i = 8; i > 0; i -= 2) {
|
||||
x.words[4] ^= R(x.words[0] + x.words[12], 7);
|
||||
x.words[8] ^= R(x.words[4] + x.words[0], 9);
|
||||
x.words[12] ^= R(x.words[8] + x.words[4], 13);
|
||||
x.words[0] ^= R(x.words[12] + x.words[8], 18);
|
||||
x.words[9] ^= R(x.words[5] + x.words[1], 7);
|
||||
x.words[13] ^= R(x.words[9] + x.words[5], 9);
|
||||
x.words[1] ^= R(x.words[13] + x.words[9], 13);
|
||||
x.words[5] ^= R(x.words[1] + x.words[13], 18);
|
||||
x.words[14] ^= R(x.words[10] + x.words[6], 7);
|
||||
x.words[2] ^= R(x.words[14] + x.words[10], 9);
|
||||
x.words[6] ^= R(x.words[2] + x.words[14], 13);
|
||||
x.words[10] ^= R(x.words[6] + x.words[2], 18);
|
||||
x.words[3] ^= R(x.words[15] + x.words[11], 7);
|
||||
x.words[7] ^= R(x.words[3] + x.words[15], 9);
|
||||
x.words[11] ^= R(x.words[7] + x.words[3], 13);
|
||||
x.words[15] ^= R(x.words[11] + x.words[7], 18);
|
||||
x.words[1] ^= R(x.words[0] + x.words[3], 7);
|
||||
x.words[2] ^= R(x.words[1] + x.words[0], 9);
|
||||
x.words[3] ^= R(x.words[2] + x.words[1], 13);
|
||||
x.words[0] ^= R(x.words[3] + x.words[2], 18);
|
||||
x.words[6] ^= R(x.words[5] + x.words[4], 7);
|
||||
x.words[7] ^= R(x.words[6] + x.words[5], 9);
|
||||
x.words[4] ^= R(x.words[7] + x.words[6], 13);
|
||||
x.words[5] ^= R(x.words[4] + x.words[7], 18);
|
||||
x.words[11] ^= R(x.words[10] + x.words[9], 7);
|
||||
x.words[8] ^= R(x.words[11] + x.words[10], 9);
|
||||
x.words[9] ^= R(x.words[8] + x.words[11], 13);
|
||||
x.words[10] ^= R(x.words[9] + x.words[8], 18);
|
||||
x.words[12] ^= R(x.words[15] + x.words[14], 7);
|
||||
x.words[13] ^= R(x.words[12] + x.words[15], 9);
|
||||
x.words[14] ^= R(x.words[13] + x.words[12], 13);
|
||||
x.words[15] ^= R(x.words[14] + x.words[13], 18);
|
||||
x.words[4] ^= CRYPTO_rotl_u32(x.words[0] + x.words[12], 7);
|
||||
x.words[8] ^= CRYPTO_rotl_u32(x.words[4] + x.words[0], 9);
|
||||
x.words[12] ^= CRYPTO_rotl_u32(x.words[8] + x.words[4], 13);
|
||||
x.words[0] ^= CRYPTO_rotl_u32(x.words[12] + x.words[8], 18);
|
||||
x.words[9] ^= CRYPTO_rotl_u32(x.words[5] + x.words[1], 7);
|
||||
x.words[13] ^= CRYPTO_rotl_u32(x.words[9] + x.words[5], 9);
|
||||
x.words[1] ^= CRYPTO_rotl_u32(x.words[13] + x.words[9], 13);
|
||||
x.words[5] ^= CRYPTO_rotl_u32(x.words[1] + x.words[13], 18);
|
||||
x.words[14] ^= CRYPTO_rotl_u32(x.words[10] + x.words[6], 7);
|
||||
x.words[2] ^= CRYPTO_rotl_u32(x.words[14] + x.words[10], 9);
|
||||
x.words[6] ^= CRYPTO_rotl_u32(x.words[2] + x.words[14], 13);
|
||||
x.words[10] ^= CRYPTO_rotl_u32(x.words[6] + x.words[2], 18);
|
||||
x.words[3] ^= CRYPTO_rotl_u32(x.words[15] + x.words[11], 7);
|
||||
x.words[7] ^= CRYPTO_rotl_u32(x.words[3] + x.words[15], 9);
|
||||
x.words[11] ^= CRYPTO_rotl_u32(x.words[7] + x.words[3], 13);
|
||||
x.words[15] ^= CRYPTO_rotl_u32(x.words[11] + x.words[7], 18);
|
||||
x.words[1] ^= CRYPTO_rotl_u32(x.words[0] + x.words[3], 7);
|
||||
x.words[2] ^= CRYPTO_rotl_u32(x.words[1] + x.words[0], 9);
|
||||
x.words[3] ^= CRYPTO_rotl_u32(x.words[2] + x.words[1], 13);
|
||||
x.words[0] ^= CRYPTO_rotl_u32(x.words[3] + x.words[2], 18);
|
||||
x.words[6] ^= CRYPTO_rotl_u32(x.words[5] + x.words[4], 7);
|
||||
x.words[7] ^= CRYPTO_rotl_u32(x.words[6] + x.words[5], 9);
|
||||
x.words[4] ^= CRYPTO_rotl_u32(x.words[7] + x.words[6], 13);
|
||||
x.words[5] ^= CRYPTO_rotl_u32(x.words[4] + x.words[7], 18);
|
||||
x.words[11] ^= CRYPTO_rotl_u32(x.words[10] + x.words[9], 7);
|
||||
x.words[8] ^= CRYPTO_rotl_u32(x.words[11] + x.words[10], 9);
|
||||
x.words[9] ^= CRYPTO_rotl_u32(x.words[8] + x.words[11], 13);
|
||||
x.words[10] ^= CRYPTO_rotl_u32(x.words[9] + x.words[8], 18);
|
||||
x.words[12] ^= CRYPTO_rotl_u32(x.words[15] + x.words[14], 7);
|
||||
x.words[13] ^= CRYPTO_rotl_u32(x.words[12] + x.words[15], 9);
|
||||
x.words[14] ^= CRYPTO_rotl_u32(x.words[13] + x.words[12], 13);
|
||||
x.words[15] ^= CRYPTO_rotl_u32(x.words[14] + x.words[13], 18);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -75,10 +75,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
if (ret == NULL) {
|
||||
ret = BN_new();
|
||||
}
|
||||
if (ret == NULL) {
|
||||
goto end;
|
||||
}
|
||||
if (!BN_set_word(ret, BN_is_bit_set(a, 0))) {
|
||||
if (ret == NULL ||
|
||||
!BN_set_word(ret, BN_is_bit_set(a, 0))) {
|
||||
if (ret != in) {
|
||||
BN_free(ret);
|
||||
}
|
||||
@@ -88,17 +86,15 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
}
|
||||
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_P_IS_NOT_PRIME);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (BN_is_zero(a) || BN_is_one(a)) {
|
||||
if (ret == NULL) {
|
||||
ret = BN_new();
|
||||
}
|
||||
if (ret == NULL) {
|
||||
goto end;
|
||||
}
|
||||
if (!BN_set_word(ret, BN_is_one(a))) {
|
||||
if (ret == NULL ||
|
||||
!BN_set_word(ret, BN_is_one(a))) {
|
||||
if (ret != in) {
|
||||
BN_free(ret);
|
||||
}
|
||||
|
||||
@@ -911,6 +911,16 @@ static int aead_aes_gcm_init_impl(struct aead_aes_gcm_ctx *gcm_ctx,
|
||||
size_t key_len, size_t tag_len) {
|
||||
const size_t key_bits = key_len * 8;
|
||||
|
||||
switch (key_bits) {
|
||||
case 128:
|
||||
boringssl_fips_inc_counter(fips_counter_evp_aes_128_gcm);
|
||||
break;
|
||||
|
||||
case 256:
|
||||
boringssl_fips_inc_counter(fips_counter_evp_aes_256_gcm);
|
||||
break;
|
||||
}
|
||||
|
||||
if (key_bits != 128 && key_bits != 192 && key_bits != 256) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH);
|
||||
return 0; // EVP_AEAD_CTX_init should catch this.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -342,10 +342,10 @@ void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
|
||||
// table contained 0213 4657
|
||||
t2 = ((t << 16L) | (s & 0x0000ffffL)) & 0xffffffffL;
|
||||
schedule->subkeys[i][0] = ROTATE(t2, 30) & 0xffffffffL;
|
||||
schedule->subkeys[i][0] = CRYPTO_rotr_u32(t2, 30);
|
||||
|
||||
t2 = ((s >> 16L) | (t & 0xffff0000L));
|
||||
schedule->subkeys[i][1] = ROTATE(t2, 26) & 0xffffffffL;
|
||||
schedule->subkeys[i][1] = CRYPTO_rotr_u32(t2, 26);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,8 +392,8 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
// <71755.204@CompuServe.COM> for pointing this out.
|
||||
// clear the top bits on machines with 8byte longs
|
||||
// shift left by 2
|
||||
r = ROTATE(r, 29) & 0xffffffffL;
|
||||
l = ROTATE(l, 29) & 0xffffffffL;
|
||||
r = CRYPTO_rotr_u32(r, 29);
|
||||
l = CRYPTO_rotr_u32(l, 29);
|
||||
|
||||
// I don't know if it is worth the effort of loop unrolling the
|
||||
// inner loop
|
||||
@@ -434,8 +434,8 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
}
|
||||
|
||||
// rotate and clear the top bits on machines with 8byte longs
|
||||
l = ROTATE(l, 3) & 0xffffffffL;
|
||||
r = ROTATE(r, 3) & 0xffffffffL;
|
||||
l = CRYPTO_rotr_u32(l, 3);
|
||||
r = CRYPTO_rotr_u32(r, 3);
|
||||
|
||||
FP(r, l);
|
||||
data[0] = l;
|
||||
@@ -454,8 +454,8 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
// sparc2. Thanks to Richard Outerbridge <71755.204@CompuServe.COM> for
|
||||
// pointing this out.
|
||||
// clear the top bits on machines with 8byte longs
|
||||
r = ROTATE(r, 29) & 0xffffffffL;
|
||||
l = ROTATE(l, 29) & 0xffffffffL;
|
||||
r = CRYPTO_rotr_u32(r, 29);
|
||||
l = CRYPTO_rotr_u32(l, 29);
|
||||
|
||||
// I don't know if it is worth the effort of loop unrolling the
|
||||
// inner loop
|
||||
@@ -495,8 +495,8 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
D_ENCRYPT(ks, r, l, 0);
|
||||
}
|
||||
// rotate and clear the top bits on machines with 8byte longs
|
||||
data[0] = ROTATE(l, 3) & 0xffffffffL;
|
||||
data[1] = ROTATE(r, 3) & 0xffffffffL;
|
||||
data[0] = CRYPTO_rotr_u32(l, 3);
|
||||
data[1] = CRYPTO_rotr_u32(r, 3);
|
||||
}
|
||||
|
||||
void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
@@ -782,4 +782,3 @@ void DES_set_key_unchecked(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
#undef D_ENCRYPT
|
||||
#undef ITERATIONS
|
||||
#undef HALF_ITERATIONS
|
||||
#undef ROTATE
|
||||
@@ -218,7 +218,7 @@ how to use xors :-) I got it to its final state.
|
||||
#define D_ENCRYPT(ks, LL, R, S) \
|
||||
do { \
|
||||
LOAD_DATA(ks, R, S, u, t, E0, E1); \
|
||||
t = ROTATE(t, 4); \
|
||||
t = CRYPTO_rotr_u32(t, 4); \
|
||||
(LL) ^= \
|
||||
DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \
|
||||
@@ -230,8 +230,6 @@ how to use xors :-) I got it to its final state.
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
|
||||
#define ROTATE(a, n) (((a) >> (n)) + ((a) << (32 - (n))))
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
@@ -68,8 +68,7 @@
|
||||
|
||||
|
||||
// digest_to_scalar interprets |digest_len| bytes from |digest| as a scalar for
|
||||
// ECDSA. Note this value is not fully reduced modulo the order, only the
|
||||
// correct number of bits.
|
||||
// ECDSA.
|
||||
static void digest_to_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const uint8_t *digest, size_t digest_len) {
|
||||
const BIGNUM *order = &group->order;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -113,24 +113,22 @@ int MD4_Final(uint8_t out[MD4_DIGEST_LENGTH], MD4_CTX *c) {
|
||||
#define G(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
|
||||
#define H(b, c, d) ((b) ^ (c) ^ (d))
|
||||
|
||||
#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
|
||||
|
||||
#define R0(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + F((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
} while (0)
|
||||
|
||||
#define R1(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + G((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
} while (0)
|
||||
|
||||
#define R2(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + H((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
} while (0)
|
||||
|
||||
void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num) {
|
||||
@@ -237,7 +235,6 @@ void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num) {
|
||||
#undef F
|
||||
#undef G
|
||||
#undef H
|
||||
#undef ROTATE
|
||||
#undef R0
|
||||
#undef R1
|
||||
#undef R2
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -119,33 +119,31 @@ int MD5_Final(uint8_t out[MD5_DIGEST_LENGTH], MD5_CTX *c) {
|
||||
#define H(b, c, d) ((b) ^ (c) ^ (d))
|
||||
#define I(b, c, d) (((~(d)) | (b)) ^ (c))
|
||||
|
||||
#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
|
||||
|
||||
#define R0(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + F((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
(a) += (b); \
|
||||
} while (0)
|
||||
|
||||
#define R1(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + G((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
(a) += (b); \
|
||||
} while (0)
|
||||
|
||||
#define R2(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + H((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
(a) += (b); \
|
||||
} while (0)
|
||||
|
||||
#define R3(a, b, c, d, k, s, t) \
|
||||
do { \
|
||||
(a) += ((k) + (t) + I((b), (c), (d))); \
|
||||
(a) = ROTATE(a, s); \
|
||||
(a) = CRYPTO_rotl_u32(a, s); \
|
||||
(a) += (b); \
|
||||
} while (0)
|
||||
|
||||
@@ -280,7 +278,6 @@ static void md5_block_data_order(uint32_t *state, const uint8_t *data,
|
||||
#undef G
|
||||
#undef H
|
||||
#undef I
|
||||
#undef ROTATE
|
||||
#undef R0
|
||||
#undef R1
|
||||
#undef R2
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -206,6 +206,12 @@ void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p,
|
||||
}
|
||||
}
|
||||
|
||||
const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *rsa) {
|
||||
// We do not support the id-RSASSA-PSS key encoding. If we add support later,
|
||||
// the |maskHash| field should be filled in for OpenSSL compatibility.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1,
|
||||
const BIGNUM **out_dmq1, const BIGNUM **out_iqmp) {
|
||||
if (out_dmp1 != NULL) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -290,27 +290,27 @@ err:
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_ANDROID)
|
||||
static const size_t kModuleDigestSize = SHA256_DIGEST_LENGTH;
|
||||
#define MODULE_DIGEST_SIZE SHA256_DIGEST_LENGTH
|
||||
#else
|
||||
static const size_t kModuleDigestSize = SHA512_DIGEST_LENGTH;
|
||||
#define MODULE_DIGEST_SIZE SHA512_DIGEST_LENGTH
|
||||
#endif
|
||||
|
||||
int boringssl_fips_self_test(
|
||||
const uint8_t *module_hash, size_t module_hash_len) {
|
||||
#if defined(BORINGSSL_FIPS_SELF_TEST_FLAG_FILE)
|
||||
char flag_path[sizeof(kFlagPrefix) + 2*kModuleDigestSize];
|
||||
char flag_path[sizeof(kFlagPrefix) + 2 * MODULE_DIGEST_SIZE];
|
||||
if (module_hash_len != 0) {
|
||||
if (module_hash_len != kModuleDigestSize) {
|
||||
if (module_hash_len != MODULE_DIGEST_SIZE) {
|
||||
fprintf(stderr,
|
||||
"module hash of length %zu does not match expected length %zu\n",
|
||||
module_hash_len, kModuleDigestSize);
|
||||
"module hash of length %zu does not match expected length %d\n",
|
||||
module_hash_len, MODULE_DIGEST_SIZE);
|
||||
BORINGSSL_FIPS_abort();
|
||||
}
|
||||
|
||||
// Test whether the flag file exists.
|
||||
memcpy(flag_path, kFlagPrefix, sizeof(kFlagPrefix) - 1);
|
||||
static const char kHexTable[17] = "0123456789abcdef";
|
||||
for (size_t i = 0; i < kModuleDigestSize; i++) {
|
||||
for (size_t i = 0; i < MODULE_DIGEST_SIZE; i++) {
|
||||
flag_path[sizeof(kFlagPrefix) - 1 + 2 * i] =
|
||||
kHexTable[module_hash[i] >> 4];
|
||||
flag_path[sizeof(kFlagPrefix) - 1 + 2 * i + 1] =
|
||||
|
||||
@@ -111,11 +111,10 @@ int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *c) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
|
||||
#define Xupdate(a, ix, ia, ib, ic, id) \
|
||||
do { \
|
||||
(a) = ((ia) ^ (ib) ^ (ic) ^ (id)); \
|
||||
(ix) = (a) = ROTATE((a), 1); \
|
||||
#define Xupdate(a, ix, ia, ib, ic, id) \
|
||||
do { \
|
||||
(a) = ((ia) ^ (ib) ^ (ic) ^ (id)); \
|
||||
(ix) = (a) = CRYPTO_rotl_u32((a), 1); \
|
||||
} while (0)
|
||||
|
||||
#define K_00_19 0x5a827999UL
|
||||
@@ -133,45 +132,47 @@ int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *c) {
|
||||
#define F_40_59(b, c, d) (((b) & (c)) | (((b) | (c)) & (d)))
|
||||
#define F_60_79(b, c, d) F_20_39(b, c, d)
|
||||
|
||||
#define BODY_00_15(i, a, b, c, d, e, f, xi) \
|
||||
do { \
|
||||
(f) = (xi) + (e) + K_00_19 + ROTATE((a), 5) + F_00_19((b), (c), (d)); \
|
||||
(b) = ROTATE((b), 30); \
|
||||
#define BODY_00_15(i, a, b, c, d, e, f, xi) \
|
||||
do { \
|
||||
(f) = (xi) + (e) + K_00_19 + CRYPTO_rotl_u32((a), 5) + \
|
||||
F_00_19((b), (c), (d)); \
|
||||
(b) = CRYPTO_rotl_u32((b), 30); \
|
||||
} while (0)
|
||||
|
||||
#define BODY_16_19(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xi, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_00_19 + ROTATE((a), 5) + F_00_19((b), (c), (d)); \
|
||||
(b) = ROTATE((b), 30); \
|
||||
#define BODY_16_19(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xi, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_00_19 + CRYPTO_rotl_u32((a), 5) + F_00_19((b), (c), (d)); \
|
||||
(b) = CRYPTO_rotl_u32((b), 30); \
|
||||
} while (0)
|
||||
|
||||
#define BODY_20_31(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xi, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_20_39 + ROTATE((a), 5) + F_20_39((b), (c), (d)); \
|
||||
(b) = ROTATE((b), 30); \
|
||||
#define BODY_20_31(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xi, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_20_39 + CRYPTO_rotl_u32((a), 5) + F_20_39((b), (c), (d)); \
|
||||
(b) = CRYPTO_rotl_u32((b), 30); \
|
||||
} while (0)
|
||||
|
||||
#define BODY_32_39(i, a, b, c, d, e, f, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xa, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_20_39 + ROTATE((a), 5) + F_20_39((b), (c), (d)); \
|
||||
(b) = ROTATE((b), 30); \
|
||||
#define BODY_32_39(i, a, b, c, d, e, f, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xa, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_20_39 + CRYPTO_rotl_u32((a), 5) + F_20_39((b), (c), (d)); \
|
||||
(b) = CRYPTO_rotl_u32((b), 30); \
|
||||
} while (0)
|
||||
|
||||
#define BODY_40_59(i, a, b, c, d, e, f, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xa, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_40_59 + ROTATE((a), 5) + F_40_59((b), (c), (d)); \
|
||||
(b) = ROTATE((b), 30); \
|
||||
#define BODY_40_59(i, a, b, c, d, e, f, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xa, xa, xb, xc, xd); \
|
||||
(f) += (e) + K_40_59 + CRYPTO_rotl_u32((a), 5) + F_40_59((b), (c), (d)); \
|
||||
(b) = CRYPTO_rotl_u32((b), 30); \
|
||||
} while (0)
|
||||
|
||||
#define BODY_60_79(i, a, b, c, d, e, f, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xa, xa, xb, xc, xd); \
|
||||
(f) = (xa) + (e) + K_60_79 + ROTATE((a), 5) + F_60_79((b), (c), (d)); \
|
||||
(b) = ROTATE((b), 30); \
|
||||
#define BODY_60_79(i, a, b, c, d, e, f, xa, xb, xc, xd) \
|
||||
do { \
|
||||
Xupdate(f, xa, xa, xb, xc, xd); \
|
||||
(f) = (xa) + (e) + K_60_79 + CRYPTO_rotl_u32((a), 5) + \
|
||||
F_60_79((b), (c), (d)); \
|
||||
(b) = CRYPTO_rotl_u32((b), 30); \
|
||||
} while (0)
|
||||
|
||||
#ifdef X
|
||||
@@ -338,7 +339,6 @@ static void sha1_block_data_order(uint32_t *state, const uint8_t *data,
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef ROTATE
|
||||
#undef Xupdate
|
||||
#undef K_00_19
|
||||
#undef K_20_39
|
||||
|
||||
@@ -184,15 +184,17 @@ static const uint32_t K256[64] = {
|
||||
0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
|
||||
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL};
|
||||
|
||||
#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
|
||||
|
||||
// FIPS specification refers to right rotations, while our ROTATE macro
|
||||
// is left one. This is why you might notice that rotation coefficients
|
||||
// differ from those observed in FIPS document by 32-N...
|
||||
#define Sigma0(x) (ROTATE((x), 30) ^ ROTATE((x), 19) ^ ROTATE((x), 10))
|
||||
#define Sigma1(x) (ROTATE((x), 26) ^ ROTATE((x), 21) ^ ROTATE((x), 7))
|
||||
#define sigma0(x) (ROTATE((x), 25) ^ ROTATE((x), 14) ^ ((x) >> 3))
|
||||
#define sigma1(x) (ROTATE((x), 15) ^ ROTATE((x), 13) ^ ((x) >> 10))
|
||||
// See FIPS 180-4, section 4.1.2.
|
||||
#define Sigma0(x) \
|
||||
(CRYPTO_rotr_u32((x), 2) ^ CRYPTO_rotr_u32((x), 13) ^ \
|
||||
CRYPTO_rotr_u32((x), 22))
|
||||
#define Sigma1(x) \
|
||||
(CRYPTO_rotr_u32((x), 6) ^ CRYPTO_rotr_u32((x), 11) ^ \
|
||||
CRYPTO_rotr_u32((x), 25))
|
||||
#define sigma0(x) \
|
||||
(CRYPTO_rotr_u32((x), 7) ^ CRYPTO_rotr_u32((x), 18) ^ ((x) >> 3))
|
||||
#define sigma1(x) \
|
||||
(CRYPTO_rotr_u32((x), 17) ^ CRYPTO_rotr_u32((x), 19) ^ ((x) >> 10))
|
||||
|
||||
#define Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
#define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
|
||||
@@ -309,7 +311,6 @@ void SHA256_TransformBlocks(uint32_t state[8], const uint8_t *data,
|
||||
sha256_block_data_order(state, data, num_blocks);
|
||||
}
|
||||
|
||||
#undef ROTATE
|
||||
#undef Sigma0
|
||||
#undef Sigma1
|
||||
#undef sigma0
|
||||
|
||||
@@ -321,42 +321,16 @@ static const uint64_t K512[80] = {
|
||||
UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817),
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(OPENSSL_NO_ASM)
|
||||
#if defined(__x86_64) || defined(__x86_64__)
|
||||
#define ROTR(a, n) \
|
||||
({ \
|
||||
uint64_t ret; \
|
||||
__asm__("rorq %1, %0" : "=r"(ret) : "J"(n), "0"(a) : "cc"); \
|
||||
ret; \
|
||||
})
|
||||
#elif(defined(_ARCH_PPC) && defined(__64BIT__)) || defined(_ARCH_PPC64)
|
||||
#define ROTR(a, n) \
|
||||
({ \
|
||||
uint64_t ret; \
|
||||
__asm__("rotrdi %0, %1, %2" : "=r"(ret) : "r"(a), "K"(n)); \
|
||||
ret; \
|
||||
})
|
||||
#elif defined(__aarch64__)
|
||||
#define ROTR(a, n) \
|
||||
({ \
|
||||
uint64_t ret; \
|
||||
__asm__("ror %0, %1, %2" : "=r"(ret) : "r"(a), "I"(n)); \
|
||||
ret; \
|
||||
})
|
||||
#endif
|
||||
#elif defined(_MSC_VER) && defined(_WIN64)
|
||||
#pragma intrinsic(_rotr64)
|
||||
#define ROTR(a, n) _rotr64((a), n)
|
||||
#endif
|
||||
|
||||
#ifndef ROTR
|
||||
#define ROTR(x, s) (((x) >> s) | (x) << (64 - s))
|
||||
#endif
|
||||
|
||||
#define Sigma0(x) (ROTR((x), 28) ^ ROTR((x), 34) ^ ROTR((x), 39))
|
||||
#define Sigma1(x) (ROTR((x), 14) ^ ROTR((x), 18) ^ ROTR((x), 41))
|
||||
#define sigma0(x) (ROTR((x), 1) ^ ROTR((x), 8) ^ ((x) >> 7))
|
||||
#define sigma1(x) (ROTR((x), 19) ^ ROTR((x), 61) ^ ((x) >> 6))
|
||||
#define Sigma0(x) \
|
||||
(CRYPTO_rotr_u64((x), 28) ^ CRYPTO_rotr_u64((x), 34) ^ \
|
||||
CRYPTO_rotr_u64((x), 39))
|
||||
#define Sigma1(x) \
|
||||
(CRYPTO_rotr_u64((x), 14) ^ CRYPTO_rotr_u64((x), 18) ^ \
|
||||
CRYPTO_rotr_u64((x), 41))
|
||||
#define sigma0(x) \
|
||||
(CRYPTO_rotr_u64((x), 1) ^ CRYPTO_rotr_u64((x), 8) ^ ((x) >> 7))
|
||||
#define sigma1(x) \
|
||||
(CRYPTO_rotr_u64((x), 19) ^ CRYPTO_rotr_u64((x), 61) ^ ((x) >> 6))
|
||||
|
||||
#define Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
#define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
|
||||
@@ -524,7 +498,6 @@ static void sha512_block_data_order(uint64_t *state, const uint8_t *in,
|
||||
|
||||
#endif // !SHA512_ASM
|
||||
|
||||
#undef ROTR
|
||||
#undef Sigma0
|
||||
#undef Sigma1
|
||||
#undef sigma0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1101,8 +1101,8 @@ Lcbc_enc_loop:
|
||||
st1 {v0.16b}, [x4] // write ivec
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
Lcbc_abort:
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -1102,8 +1102,8 @@ vpaes_cbc_encrypt:
|
||||
st1 {v0.16b}, [x4] // write ivec
|
||||
|
||||
ldp x29,x30,[sp],#16
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
.Lcbc_abort:
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size vpaes_cbc_encrypt,.-vpaes_cbc_encrypt
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__i386__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
# This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
# source tree. Do not edit by hand.
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
Loaded 100 of 149 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user