grpc
third_party
boringssl-with-bazel
src
crypto
bn_extra
bn_asn1.c
Go to the documentation of this file.
1
/* Copyright (c) 2015, Google Inc.
2
*
3
* Permission to use, copy, modify, and/or distribute this software for any
4
* purpose with or without fee is hereby granted, provided that the above
5
* copyright notice and this permission notice appear in all copies.
6
*
7
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15
#include <
openssl/bn.h
>
16
17
#include <
openssl/bytestring.h
>
18
#include <
openssl/err.h
>
19
20
21
int
BN_parse_asn1_unsigned
(
CBS
*
cbs
,
BIGNUM
*
ret
) {
22
CBS
child
;
23
int
is_negative;
24
if
(!
CBS_get_asn1
(
cbs
, &
child
,
CBS_ASN1_INTEGER
) ||
25
!
CBS_is_valid_asn1_integer
(&
child
, &is_negative)) {
26
OPENSSL_PUT_ERROR
(BN,
BN_R_BAD_ENCODING
);
27
return
0;
28
}
29
30
if
(is_negative) {
31
OPENSSL_PUT_ERROR
(BN,
BN_R_NEGATIVE_NUMBER
);
32
return
0;
33
}
34
35
return
BN_bin2bn
(
CBS_data
(&
child
),
CBS_len
(&
child
),
ret
) != NULL;
36
}
37
38
int
BN_marshal_asn1
(
CBB
*cbb,
const
BIGNUM
*bn) {
39
// Negative numbers are unsupported.
40
if
(
BN_is_negative
(bn)) {
41
OPENSSL_PUT_ERROR
(BN,
BN_R_NEGATIVE_NUMBER
);
42
return
0;
43
}
44
45
CBB
child
;
46
if
(!
CBB_add_asn1
(cbb, &
child
,
CBS_ASN1_INTEGER
) ||
47
// The number must be padded with a leading zero if the high bit would
48
// otherwise be set or if |bn| is zero.
49
(
BN_num_bits
(bn) % 8 == 0 && !
CBB_add_u8
(&
child
, 0x00)) ||
50
!
BN_bn2cbb_padded
(&
child
,
BN_num_bytes
(bn), bn) ||
51
!
CBB_flush
(cbb)) {
52
OPENSSL_PUT_ERROR
(BN,
BN_R_ENCODE_ERROR
);
53
return
0;
54
}
55
56
return
1;
57
}
CBS_ASN1_INTEGER
#define CBS_ASN1_INTEGER
Definition:
bytestring.h:207
bn.h
CBB_flush
#define CBB_flush
Definition:
boringssl_prefix_symbols.h:1045
cbs_st
Definition:
bytestring.h:39
CBS_data
#define CBS_data
Definition:
boringssl_prefix_symbols.h:1057
BN_bin2bn
#define BN_bin2bn
Definition:
boringssl_prefix_symbols.h:900
OPENSSL_PUT_ERROR
#define OPENSSL_PUT_ERROR(library, reason)
Definition:
err.h:423
CBB_add_u8
#define CBB_add_u8
Definition:
boringssl_prefix_symbols.h:1036
BN_R_ENCODE_ERROR
#define BN_R_ENCODE_ERROR
Definition:
bn.h:1054
CBS_len
#define CBS_len
Definition:
boringssl_prefix_symbols.h:1089
CBS_get_asn1
#define CBS_get_asn1
Definition:
boringssl_prefix_symbols.h:1061
BN_R_NEGATIVE_NUMBER
#define BN_R_NEGATIVE_NUMBER
Definition:
bn.h:1045
cbs
const CBS * cbs
Definition:
third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h:107
BN_num_bytes
#define BN_num_bytes
Definition:
boringssl_prefix_symbols.h:976
CBS_is_valid_asn1_integer
#define CBS_is_valid_asn1_integer
Definition:
boringssl_prefix_symbols.h:1088
BN_parse_asn1_unsigned
int BN_parse_asn1_unsigned(CBS *cbs, BIGNUM *ret)
Definition:
bn_asn1.c:21
bytestring.h
BN_bn2cbb_padded
#define BN_bn2cbb_padded
Definition:
boringssl_prefix_symbols.h:904
CBB_add_asn1
#define CBB_add_asn1
Definition:
boringssl_prefix_symbols.h:1019
err.h
googletest-filter-unittest.child
child
Definition:
bloaty/third_party/googletest/googletest/test/googletest-filter-unittest.py:62
BN_num_bits
#define BN_num_bits
Definition:
boringssl_prefix_symbols.h:974
bignum_st
Definition:
bn.h:957
ret
UniquePtr< SSL_SESSION > ret
Definition:
ssl_x509.cc:1029
BN_is_negative
#define BN_is_negative
Definition:
boringssl_prefix_symbols.h:933
BN_marshal_asn1
int BN_marshal_asn1(CBB *cbb, const BIGNUM *bn)
Definition:
bn_asn1.c:38
BN_R_BAD_ENCODING
#define BN_R_BAD_ENCODING
Definition:
bn.h:1053
cbb_st
Definition:
bytestring.h:375
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:49