mirror of
https://github.com/openeuler-riscv/boringssl.git
synced 2026-04-28 08:23:03 +00:00
Deprecate the master-with-bazel branch
After some infrastructure changes, this branch has not been updated since April. Instead, use the `main` branch, which now itself has Bazel build. Change-Id: I26d1caa249e2a1d82b4f2c610b837467a517ba47 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80068 Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
37
BUILD
37
BUILD
@@ -1,37 +0,0 @@
|
||||
# Copyright 2016 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This BUILD file is used as part of the synthesized "-with-bazel" branches. We
|
||||
# are in the process of transitioning to keeping all builds at tip-of-tree
|
||||
# directly, see https://crbug.com/boringssl/542. This means, in the synthesized
|
||||
# branch, "src" now reads as a separate Bazel package. Rather than suppress
|
||||
# those build files, alias the targets.
|
||||
|
||||
alias(
|
||||
name = "crypto",
|
||||
actual = "//src:crypto",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "ssl",
|
||||
actual = "//src:ssl",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "bssl",
|
||||
actual = "//src:bssl",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@@ -1,861 +0,0 @@
|
||||
# This file is created by generate_build_files.py. Do not edit manually.
|
||||
|
||||
ssl_headers = [
|
||||
"src/include/openssl/dtls1.h",
|
||||
"src/include/openssl/srtp.h",
|
||||
"src/include/openssl/ssl.h",
|
||||
"src/include/openssl/ssl3.h",
|
||||
"src/include/openssl/tls1.h",
|
||||
]
|
||||
|
||||
fips_fragments = [
|
||||
"src/crypto/fipsmodule/aes/aes.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/aes_nohw.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/cbc.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/cfb.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/ctr.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/gcm.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/gcm_nohw.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/key_wrap.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/mode_wrappers.cc.inc",
|
||||
"src/crypto/fipsmodule/aes/ofb.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/add.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/asm/x86_64-gcc.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/bn.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/bytes.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/cmp.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/ctx.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/div.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/div_extra.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/exponentiation.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/gcd.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/gcd_extra.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/generic.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/jacobi.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/montgomery.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/montgomery_inv.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/mul.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/prime.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/random.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/rsaz_exp.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/shift.cc.inc",
|
||||
"src/crypto/fipsmodule/bn/sqrt.cc.inc",
|
||||
"src/crypto/fipsmodule/cipher/aead.cc.inc",
|
||||
"src/crypto/fipsmodule/cipher/cipher.cc.inc",
|
||||
"src/crypto/fipsmodule/cipher/e_aes.cc.inc",
|
||||
"src/crypto/fipsmodule/cipher/e_aesccm.cc.inc",
|
||||
"src/crypto/fipsmodule/cmac/cmac.cc.inc",
|
||||
"src/crypto/fipsmodule/dh/check.cc.inc",
|
||||
"src/crypto/fipsmodule/dh/dh.cc.inc",
|
||||
"src/crypto/fipsmodule/digest/digest.cc.inc",
|
||||
"src/crypto/fipsmodule/digest/digests.cc.inc",
|
||||
"src/crypto/fipsmodule/digestsign/digestsign.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/ec.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/ec_key.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/ec_montgomery.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/felem.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/oct.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/p224-64.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/p256-nistz.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/p256.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/scalar.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/simple.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/simple_mul.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/util.cc.inc",
|
||||
"src/crypto/fipsmodule/ec/wnaf.cc.inc",
|
||||
"src/crypto/fipsmodule/ecdh/ecdh.cc.inc",
|
||||
"src/crypto/fipsmodule/ecdsa/ecdsa.cc.inc",
|
||||
"src/crypto/fipsmodule/hkdf/hkdf.cc.inc",
|
||||
"src/crypto/fipsmodule/hmac/hmac.cc.inc",
|
||||
"src/crypto/fipsmodule/keccak/keccak.cc.inc",
|
||||
"src/crypto/fipsmodule/mldsa/fips_known_values.inc",
|
||||
"src/crypto/fipsmodule/mldsa/mldsa.cc.inc",
|
||||
"src/crypto/fipsmodule/mlkem/fips_known_values.inc",
|
||||
"src/crypto/fipsmodule/mlkem/mlkem.cc.inc",
|
||||
"src/crypto/fipsmodule/rand/ctrdrbg.cc.inc",
|
||||
"src/crypto/fipsmodule/rand/rand.cc.inc",
|
||||
"src/crypto/fipsmodule/rsa/blinding.cc.inc",
|
||||
"src/crypto/fipsmodule/rsa/padding.cc.inc",
|
||||
"src/crypto/fipsmodule/rsa/rsa.cc.inc",
|
||||
"src/crypto/fipsmodule/rsa/rsa_impl.cc.inc",
|
||||
"src/crypto/fipsmodule/self_check/fips.cc.inc",
|
||||
"src/crypto/fipsmodule/self_check/self_check.cc.inc",
|
||||
"src/crypto/fipsmodule/service_indicator/service_indicator.cc.inc",
|
||||
"src/crypto/fipsmodule/sha/sha1.cc.inc",
|
||||
"src/crypto/fipsmodule/sha/sha256.cc.inc",
|
||||
"src/crypto/fipsmodule/sha/sha512.cc.inc",
|
||||
"src/crypto/fipsmodule/slhdsa/fips_known_values.inc",
|
||||
"src/crypto/fipsmodule/slhdsa/fors.cc.inc",
|
||||
"src/crypto/fipsmodule/slhdsa/merkle.cc.inc",
|
||||
"src/crypto/fipsmodule/slhdsa/slhdsa.cc.inc",
|
||||
"src/crypto/fipsmodule/slhdsa/thash.cc.inc",
|
||||
"src/crypto/fipsmodule/slhdsa/wots.cc.inc",
|
||||
"src/crypto/fipsmodule/tls/kdf.cc.inc",
|
||||
]
|
||||
|
||||
ssl_internal_headers = [
|
||||
"src/ssl/internal.h",
|
||||
]
|
||||
|
||||
ssl_sources = [
|
||||
"src/ssl/bio_ssl.cc",
|
||||
"src/ssl/d1_both.cc",
|
||||
"src/ssl/d1_lib.cc",
|
||||
"src/ssl/d1_pkt.cc",
|
||||
"src/ssl/d1_srtp.cc",
|
||||
"src/ssl/dtls_method.cc",
|
||||
"src/ssl/dtls_record.cc",
|
||||
"src/ssl/encrypted_client_hello.cc",
|
||||
"src/ssl/extensions.cc",
|
||||
"src/ssl/handoff.cc",
|
||||
"src/ssl/handshake.cc",
|
||||
"src/ssl/handshake_client.cc",
|
||||
"src/ssl/handshake_server.cc",
|
||||
"src/ssl/s3_both.cc",
|
||||
"src/ssl/s3_lib.cc",
|
||||
"src/ssl/s3_pkt.cc",
|
||||
"src/ssl/ssl_aead_ctx.cc",
|
||||
"src/ssl/ssl_asn1.cc",
|
||||
"src/ssl/ssl_buffer.cc",
|
||||
"src/ssl/ssl_cert.cc",
|
||||
"src/ssl/ssl_cipher.cc",
|
||||
"src/ssl/ssl_credential.cc",
|
||||
"src/ssl/ssl_file.cc",
|
||||
"src/ssl/ssl_key_share.cc",
|
||||
"src/ssl/ssl_lib.cc",
|
||||
"src/ssl/ssl_privkey.cc",
|
||||
"src/ssl/ssl_session.cc",
|
||||
"src/ssl/ssl_stat.cc",
|
||||
"src/ssl/ssl_transcript.cc",
|
||||
"src/ssl/ssl_versions.cc",
|
||||
"src/ssl/ssl_x509.cc",
|
||||
"src/ssl/t1_enc.cc",
|
||||
"src/ssl/tls13_both.cc",
|
||||
"src/ssl/tls13_client.cc",
|
||||
"src/ssl/tls13_enc.cc",
|
||||
"src/ssl/tls13_server.cc",
|
||||
"src/ssl/tls_method.cc",
|
||||
"src/ssl/tls_record.cc",
|
||||
]
|
||||
|
||||
crypto_headers = [
|
||||
"src/include/openssl/aead.h",
|
||||
"src/include/openssl/aes.h",
|
||||
"src/include/openssl/arm_arch.h",
|
||||
"src/include/openssl/asm_base.h",
|
||||
"src/include/openssl/asn1.h",
|
||||
"src/include/openssl/asn1_mac.h",
|
||||
"src/include/openssl/asn1t.h",
|
||||
"src/include/openssl/base.h",
|
||||
"src/include/openssl/base64.h",
|
||||
"src/include/openssl/bcm_public.h",
|
||||
"src/include/openssl/bio.h",
|
||||
"src/include/openssl/blake2.h",
|
||||
"src/include/openssl/blowfish.h",
|
||||
"src/include/openssl/bn.h",
|
||||
"src/include/openssl/buf.h",
|
||||
"src/include/openssl/buffer.h",
|
||||
"src/include/openssl/bytestring.h",
|
||||
"src/include/openssl/cast.h",
|
||||
"src/include/openssl/chacha.h",
|
||||
"src/include/openssl/cipher.h",
|
||||
"src/include/openssl/cmac.h",
|
||||
"src/include/openssl/cms.h",
|
||||
"src/include/openssl/conf.h",
|
||||
"src/include/openssl/cpu.h",
|
||||
"src/include/openssl/crypto.h",
|
||||
"src/include/openssl/ctrdrbg.h",
|
||||
"src/include/openssl/curve25519.h",
|
||||
"src/include/openssl/des.h",
|
||||
"src/include/openssl/dh.h",
|
||||
"src/include/openssl/digest.h",
|
||||
"src/include/openssl/dsa.h",
|
||||
"src/include/openssl/e_os2.h",
|
||||
"src/include/openssl/ec.h",
|
||||
"src/include/openssl/ec_key.h",
|
||||
"src/include/openssl/ecdh.h",
|
||||
"src/include/openssl/ecdsa.h",
|
||||
"src/include/openssl/engine.h",
|
||||
"src/include/openssl/err.h",
|
||||
"src/include/openssl/evp.h",
|
||||
"src/include/openssl/evp_errors.h",
|
||||
"src/include/openssl/ex_data.h",
|
||||
"src/include/openssl/experimental/kyber.h",
|
||||
"src/include/openssl/hkdf.h",
|
||||
"src/include/openssl/hmac.h",
|
||||
"src/include/openssl/hpke.h",
|
||||
"src/include/openssl/hrss.h",
|
||||
"src/include/openssl/is_boringssl.h",
|
||||
"src/include/openssl/kdf.h",
|
||||
"src/include/openssl/lhash.h",
|
||||
"src/include/openssl/md4.h",
|
||||
"src/include/openssl/md5.h",
|
||||
"src/include/openssl/mem.h",
|
||||
"src/include/openssl/mldsa.h",
|
||||
"src/include/openssl/mlkem.h",
|
||||
"src/include/openssl/nid.h",
|
||||
"src/include/openssl/obj.h",
|
||||
"src/include/openssl/obj_mac.h",
|
||||
"src/include/openssl/objects.h",
|
||||
"src/include/openssl/opensslconf.h",
|
||||
"src/include/openssl/opensslv.h",
|
||||
"src/include/openssl/ossl_typ.h",
|
||||
"src/include/openssl/pem.h",
|
||||
"src/include/openssl/pkcs12.h",
|
||||
"src/include/openssl/pkcs7.h",
|
||||
"src/include/openssl/pkcs8.h",
|
||||
"src/include/openssl/poly1305.h",
|
||||
"src/include/openssl/pool.h",
|
||||
"src/include/openssl/posix_time.h",
|
||||
"src/include/openssl/rand.h",
|
||||
"src/include/openssl/rc4.h",
|
||||
"src/include/openssl/ripemd.h",
|
||||
"src/include/openssl/rsa.h",
|
||||
"src/include/openssl/safestack.h",
|
||||
"src/include/openssl/service_indicator.h",
|
||||
"src/include/openssl/sha.h",
|
||||
"src/include/openssl/siphash.h",
|
||||
"src/include/openssl/slhdsa.h",
|
||||
"src/include/openssl/span.h",
|
||||
"src/include/openssl/stack.h",
|
||||
"src/include/openssl/target.h",
|
||||
"src/include/openssl/thread.h",
|
||||
"src/include/openssl/time.h",
|
||||
"src/include/openssl/trust_token.h",
|
||||
"src/include/openssl/type_check.h",
|
||||
"src/include/openssl/x509.h",
|
||||
"src/include/openssl/x509_vfy.h",
|
||||
"src/include/openssl/x509v3.h",
|
||||
"src/include/openssl/x509v3_errors.h",
|
||||
]
|
||||
|
||||
crypto_internal_headers = [
|
||||
"src/crypto/asn1/internal.h",
|
||||
"src/crypto/bcm_support.h",
|
||||
"src/crypto/bio/internal.h",
|
||||
"src/crypto/bytestring/internal.h",
|
||||
"src/crypto/chacha/internal.h",
|
||||
"src/crypto/cipher/internal.h",
|
||||
"src/crypto/conf/internal.h",
|
||||
"src/crypto/cpu_arm_linux.h",
|
||||
"src/crypto/curve25519/curve25519_tables.h",
|
||||
"src/crypto/curve25519/internal.h",
|
||||
"src/crypto/des/internal.h",
|
||||
"src/crypto/dsa/internal.h",
|
||||
"src/crypto/ec/internal.h",
|
||||
"src/crypto/err/internal.h",
|
||||
"src/crypto/evp/internal.h",
|
||||
"src/crypto/fipsmodule/aes/internal.h",
|
||||
"src/crypto/fipsmodule/bcm_interface.h",
|
||||
"src/crypto/fipsmodule/bn/internal.h",
|
||||
"src/crypto/fipsmodule/bn/rsaz_exp.h",
|
||||
"src/crypto/fipsmodule/cipher/internal.h",
|
||||
"src/crypto/fipsmodule/delocate.h",
|
||||
"src/crypto/fipsmodule/dh/internal.h",
|
||||
"src/crypto/fipsmodule/digest/internal.h",
|
||||
"src/crypto/fipsmodule/digest/md32_common.h",
|
||||
"src/crypto/fipsmodule/ec/builtin_curves.h",
|
||||
"src/crypto/fipsmodule/ec/internal.h",
|
||||
"src/crypto/fipsmodule/ec/p256-nistz-table.h",
|
||||
"src/crypto/fipsmodule/ec/p256-nistz.h",
|
||||
"src/crypto/fipsmodule/ec/p256_table.h",
|
||||
"src/crypto/fipsmodule/ecdsa/internal.h",
|
||||
"src/crypto/fipsmodule/keccak/internal.h",
|
||||
"src/crypto/fipsmodule/rand/internal.h",
|
||||
"src/crypto/fipsmodule/rsa/internal.h",
|
||||
"src/crypto/fipsmodule/service_indicator/internal.h",
|
||||
"src/crypto/fipsmodule/sha/internal.h",
|
||||
"src/crypto/fipsmodule/slhdsa/address.h",
|
||||
"src/crypto/fipsmodule/slhdsa/fors.h",
|
||||
"src/crypto/fipsmodule/slhdsa/merkle.h",
|
||||
"src/crypto/fipsmodule/slhdsa/params.h",
|
||||
"src/crypto/fipsmodule/slhdsa/thash.h",
|
||||
"src/crypto/fipsmodule/slhdsa/wots.h",
|
||||
"src/crypto/fipsmodule/tls/internal.h",
|
||||
"src/crypto/hrss/internal.h",
|
||||
"src/crypto/internal.h",
|
||||
"src/crypto/kyber/internal.h",
|
||||
"src/crypto/lhash/internal.h",
|
||||
"src/crypto/md5/internal.h",
|
||||
"src/crypto/obj/obj_dat.h",
|
||||
"src/crypto/pem/internal.h",
|
||||
"src/crypto/pkcs7/internal.h",
|
||||
"src/crypto/pkcs8/internal.h",
|
||||
"src/crypto/poly1305/internal.h",
|
||||
"src/crypto/pool/internal.h",
|
||||
"src/crypto/rand/getrandom_fillin.h",
|
||||
"src/crypto/rand/internal.h",
|
||||
"src/crypto/rsa/internal.h",
|
||||
"src/crypto/spake2plus/internal.h",
|
||||
"src/crypto/trust_token/internal.h",
|
||||
"src/crypto/x509/ext_dat.h",
|
||||
"src/crypto/x509/internal.h",
|
||||
"src/third_party/fiat/curve25519_32.h",
|
||||
"src/third_party/fiat/curve25519_64.h",
|
||||
"src/third_party/fiat/curve25519_64_adx.h",
|
||||
"src/third_party/fiat/curve25519_64_msvc.h",
|
||||
"src/third_party/fiat/p256_32.h",
|
||||
"src/third_party/fiat/p256_64.h",
|
||||
"src/third_party/fiat/p256_64_msvc.h",
|
||||
]
|
||||
|
||||
crypto_sources = [
|
||||
"src/crypto/aes/aes.cc",
|
||||
"src/crypto/asn1/a_bitstr.cc",
|
||||
"src/crypto/asn1/a_bool.cc",
|
||||
"src/crypto/asn1/a_d2i_fp.cc",
|
||||
"src/crypto/asn1/a_dup.cc",
|
||||
"src/crypto/asn1/a_gentm.cc",
|
||||
"src/crypto/asn1/a_i2d_fp.cc",
|
||||
"src/crypto/asn1/a_int.cc",
|
||||
"src/crypto/asn1/a_mbstr.cc",
|
||||
"src/crypto/asn1/a_object.cc",
|
||||
"src/crypto/asn1/a_octet.cc",
|
||||
"src/crypto/asn1/a_strex.cc",
|
||||
"src/crypto/asn1/a_strnid.cc",
|
||||
"src/crypto/asn1/a_time.cc",
|
||||
"src/crypto/asn1/a_type.cc",
|
||||
"src/crypto/asn1/a_utctm.cc",
|
||||
"src/crypto/asn1/asn1_lib.cc",
|
||||
"src/crypto/asn1/asn1_par.cc",
|
||||
"src/crypto/asn1/asn_pack.cc",
|
||||
"src/crypto/asn1/f_int.cc",
|
||||
"src/crypto/asn1/f_string.cc",
|
||||
"src/crypto/asn1/posix_time.cc",
|
||||
"src/crypto/asn1/tasn_dec.cc",
|
||||
"src/crypto/asn1/tasn_enc.cc",
|
||||
"src/crypto/asn1/tasn_fre.cc",
|
||||
"src/crypto/asn1/tasn_new.cc",
|
||||
"src/crypto/asn1/tasn_typ.cc",
|
||||
"src/crypto/asn1/tasn_utl.cc",
|
||||
"src/crypto/base64/base64.cc",
|
||||
"src/crypto/bio/bio.cc",
|
||||
"src/crypto/bio/bio_mem.cc",
|
||||
"src/crypto/bio/connect.cc",
|
||||
"src/crypto/bio/errno.cc",
|
||||
"src/crypto/bio/fd.cc",
|
||||
"src/crypto/bio/file.cc",
|
||||
"src/crypto/bio/hexdump.cc",
|
||||
"src/crypto/bio/pair.cc",
|
||||
"src/crypto/bio/printf.cc",
|
||||
"src/crypto/bio/socket.cc",
|
||||
"src/crypto/bio/socket_helper.cc",
|
||||
"src/crypto/blake2/blake2.cc",
|
||||
"src/crypto/bn/bn_asn1.cc",
|
||||
"src/crypto/bn/convert.cc",
|
||||
"src/crypto/bn/div.cc",
|
||||
"src/crypto/bn/exponentiation.cc",
|
||||
"src/crypto/bn/sqrt.cc",
|
||||
"src/crypto/buf/buf.cc",
|
||||
"src/crypto/bytestring/asn1_compat.cc",
|
||||
"src/crypto/bytestring/ber.cc",
|
||||
"src/crypto/bytestring/cbb.cc",
|
||||
"src/crypto/bytestring/cbs.cc",
|
||||
"src/crypto/bytestring/unicode.cc",
|
||||
"src/crypto/chacha/chacha.cc",
|
||||
"src/crypto/cipher/derive_key.cc",
|
||||
"src/crypto/cipher/e_aesctrhmac.cc",
|
||||
"src/crypto/cipher/e_aeseax.cc",
|
||||
"src/crypto/cipher/e_aesgcmsiv.cc",
|
||||
"src/crypto/cipher/e_chacha20poly1305.cc",
|
||||
"src/crypto/cipher/e_des.cc",
|
||||
"src/crypto/cipher/e_null.cc",
|
||||
"src/crypto/cipher/e_rc2.cc",
|
||||
"src/crypto/cipher/e_rc4.cc",
|
||||
"src/crypto/cipher/e_tls.cc",
|
||||
"src/crypto/cipher/get_cipher.cc",
|
||||
"src/crypto/cipher/tls_cbc.cc",
|
||||
"src/crypto/cms/cms.cc",
|
||||
"src/crypto/conf/conf.cc",
|
||||
"src/crypto/cpu_aarch64_apple.cc",
|
||||
"src/crypto/cpu_aarch64_fuchsia.cc",
|
||||
"src/crypto/cpu_aarch64_linux.cc",
|
||||
"src/crypto/cpu_aarch64_openbsd.cc",
|
||||
"src/crypto/cpu_aarch64_sysreg.cc",
|
||||
"src/crypto/cpu_aarch64_win.cc",
|
||||
"src/crypto/cpu_arm_freebsd.cc",
|
||||
"src/crypto/cpu_arm_linux.cc",
|
||||
"src/crypto/cpu_intel.cc",
|
||||
"src/crypto/crypto.cc",
|
||||
"src/crypto/curve25519/curve25519.cc",
|
||||
"src/crypto/curve25519/curve25519_64_adx.cc",
|
||||
"src/crypto/curve25519/spake25519.cc",
|
||||
"src/crypto/des/des.cc",
|
||||
"src/crypto/dh/dh_asn1.cc",
|
||||
"src/crypto/dh/params.cc",
|
||||
"src/crypto/digest/digest_extra.cc",
|
||||
"src/crypto/dsa/dsa.cc",
|
||||
"src/crypto/dsa/dsa_asn1.cc",
|
||||
"src/crypto/ec/ec_asn1.cc",
|
||||
"src/crypto/ec/ec_derive.cc",
|
||||
"src/crypto/ec/hash_to_curve.cc",
|
||||
"src/crypto/ecdh/ecdh.cc",
|
||||
"src/crypto/ecdsa/ecdsa_asn1.cc",
|
||||
"src/crypto/engine/engine.cc",
|
||||
"src/crypto/err/err.cc",
|
||||
"src/crypto/evp/evp.cc",
|
||||
"src/crypto/evp/evp_asn1.cc",
|
||||
"src/crypto/evp/evp_ctx.cc",
|
||||
"src/crypto/evp/p_dh.cc",
|
||||
"src/crypto/evp/p_dh_asn1.cc",
|
||||
"src/crypto/evp/p_dsa_asn1.cc",
|
||||
"src/crypto/evp/p_ec.cc",
|
||||
"src/crypto/evp/p_ec_asn1.cc",
|
||||
"src/crypto/evp/p_ed25519.cc",
|
||||
"src/crypto/evp/p_ed25519_asn1.cc",
|
||||
"src/crypto/evp/p_hkdf.cc",
|
||||
"src/crypto/evp/p_rsa.cc",
|
||||
"src/crypto/evp/p_rsa_asn1.cc",
|
||||
"src/crypto/evp/p_x25519.cc",
|
||||
"src/crypto/evp/p_x25519_asn1.cc",
|
||||
"src/crypto/evp/pbkdf.cc",
|
||||
"src/crypto/evp/print.cc",
|
||||
"src/crypto/evp/scrypt.cc",
|
||||
"src/crypto/evp/sign.cc",
|
||||
"src/crypto/ex_data.cc",
|
||||
"src/crypto/fipsmodule/bcm.cc",
|
||||
"src/crypto/fipsmodule/fips_shared_support.cc",
|
||||
"src/crypto/fuzzer_mode.cc",
|
||||
"src/crypto/hpke/hpke.cc",
|
||||
"src/crypto/hrss/hrss.cc",
|
||||
"src/crypto/kyber/kyber.cc",
|
||||
"src/crypto/lhash/lhash.cc",
|
||||
"src/crypto/md4/md4.cc",
|
||||
"src/crypto/md5/md5.cc",
|
||||
"src/crypto/mem.cc",
|
||||
"src/crypto/mldsa/mldsa.cc",
|
||||
"src/crypto/mlkem/mlkem.cc",
|
||||
"src/crypto/obj/obj.cc",
|
||||
"src/crypto/obj/obj_xref.cc",
|
||||
"src/crypto/pem/pem_all.cc",
|
||||
"src/crypto/pem/pem_info.cc",
|
||||
"src/crypto/pem/pem_lib.cc",
|
||||
"src/crypto/pem/pem_oth.cc",
|
||||
"src/crypto/pem/pem_pk8.cc",
|
||||
"src/crypto/pem/pem_pkey.cc",
|
||||
"src/crypto/pem/pem_x509.cc",
|
||||
"src/crypto/pem/pem_xaux.cc",
|
||||
"src/crypto/pkcs7/pkcs7.cc",
|
||||
"src/crypto/pkcs7/pkcs7_x509.cc",
|
||||
"src/crypto/pkcs8/p5_pbev2.cc",
|
||||
"src/crypto/pkcs8/pkcs8.cc",
|
||||
"src/crypto/pkcs8/pkcs8_x509.cc",
|
||||
"src/crypto/poly1305/poly1305.cc",
|
||||
"src/crypto/poly1305/poly1305_arm.cc",
|
||||
"src/crypto/poly1305/poly1305_vec.cc",
|
||||
"src/crypto/pool/pool.cc",
|
||||
"src/crypto/rand/deterministic.cc",
|
||||
"src/crypto/rand/fork_detect.cc",
|
||||
"src/crypto/rand/forkunsafe.cc",
|
||||
"src/crypto/rand/getentropy.cc",
|
||||
"src/crypto/rand/ios.cc",
|
||||
"src/crypto/rand/passive.cc",
|
||||
"src/crypto/rand/rand.cc",
|
||||
"src/crypto/rand/trusty.cc",
|
||||
"src/crypto/rand/urandom.cc",
|
||||
"src/crypto/rand/windows.cc",
|
||||
"src/crypto/rc4/rc4.cc",
|
||||
"src/crypto/refcount.cc",
|
||||
"src/crypto/rsa/rsa_asn1.cc",
|
||||
"src/crypto/rsa/rsa_crypt.cc",
|
||||
"src/crypto/rsa/rsa_extra.cc",
|
||||
"src/crypto/rsa/rsa_print.cc",
|
||||
"src/crypto/sha/sha1.cc",
|
||||
"src/crypto/sha/sha256.cc",
|
||||
"src/crypto/sha/sha512.cc",
|
||||
"src/crypto/siphash/siphash.cc",
|
||||
"src/crypto/slhdsa/slhdsa.cc",
|
||||
"src/crypto/spake2plus/spake2plus.cc",
|
||||
"src/crypto/stack/stack.cc",
|
||||
"src/crypto/thread.cc",
|
||||
"src/crypto/thread_none.cc",
|
||||
"src/crypto/thread_pthread.cc",
|
||||
"src/crypto/thread_win.cc",
|
||||
"src/crypto/trust_token/pmbtoken.cc",
|
||||
"src/crypto/trust_token/trust_token.cc",
|
||||
"src/crypto/trust_token/voprf.cc",
|
||||
"src/crypto/x509/a_digest.cc",
|
||||
"src/crypto/x509/a_sign.cc",
|
||||
"src/crypto/x509/a_verify.cc",
|
||||
"src/crypto/x509/algorithm.cc",
|
||||
"src/crypto/x509/asn1_gen.cc",
|
||||
"src/crypto/x509/by_dir.cc",
|
||||
"src/crypto/x509/by_file.cc",
|
||||
"src/crypto/x509/i2d_pr.cc",
|
||||
"src/crypto/x509/name_print.cc",
|
||||
"src/crypto/x509/policy.cc",
|
||||
"src/crypto/x509/rsa_pss.cc",
|
||||
"src/crypto/x509/t_crl.cc",
|
||||
"src/crypto/x509/t_req.cc",
|
||||
"src/crypto/x509/t_x509.cc",
|
||||
"src/crypto/x509/t_x509a.cc",
|
||||
"src/crypto/x509/v3_akey.cc",
|
||||
"src/crypto/x509/v3_akeya.cc",
|
||||
"src/crypto/x509/v3_alt.cc",
|
||||
"src/crypto/x509/v3_bcons.cc",
|
||||
"src/crypto/x509/v3_bitst.cc",
|
||||
"src/crypto/x509/v3_conf.cc",
|
||||
"src/crypto/x509/v3_cpols.cc",
|
||||
"src/crypto/x509/v3_crld.cc",
|
||||
"src/crypto/x509/v3_enum.cc",
|
||||
"src/crypto/x509/v3_extku.cc",
|
||||
"src/crypto/x509/v3_genn.cc",
|
||||
"src/crypto/x509/v3_ia5.cc",
|
||||
"src/crypto/x509/v3_info.cc",
|
||||
"src/crypto/x509/v3_int.cc",
|
||||
"src/crypto/x509/v3_lib.cc",
|
||||
"src/crypto/x509/v3_ncons.cc",
|
||||
"src/crypto/x509/v3_ocsp.cc",
|
||||
"src/crypto/x509/v3_pcons.cc",
|
||||
"src/crypto/x509/v3_pmaps.cc",
|
||||
"src/crypto/x509/v3_prn.cc",
|
||||
"src/crypto/x509/v3_purp.cc",
|
||||
"src/crypto/x509/v3_skey.cc",
|
||||
"src/crypto/x509/v3_utl.cc",
|
||||
"src/crypto/x509/x509.cc",
|
||||
"src/crypto/x509/x509_att.cc",
|
||||
"src/crypto/x509/x509_cmp.cc",
|
||||
"src/crypto/x509/x509_d2.cc",
|
||||
"src/crypto/x509/x509_def.cc",
|
||||
"src/crypto/x509/x509_ext.cc",
|
||||
"src/crypto/x509/x509_lu.cc",
|
||||
"src/crypto/x509/x509_obj.cc",
|
||||
"src/crypto/x509/x509_req.cc",
|
||||
"src/crypto/x509/x509_set.cc",
|
||||
"src/crypto/x509/x509_trs.cc",
|
||||
"src/crypto/x509/x509_txt.cc",
|
||||
"src/crypto/x509/x509_v3.cc",
|
||||
"src/crypto/x509/x509_vfy.cc",
|
||||
"src/crypto/x509/x509_vpm.cc",
|
||||
"src/crypto/x509/x509cset.cc",
|
||||
"src/crypto/x509/x509name.cc",
|
||||
"src/crypto/x509/x509rset.cc",
|
||||
"src/crypto/x509/x509spki.cc",
|
||||
"src/crypto/x509/x_algor.cc",
|
||||
"src/crypto/x509/x_all.cc",
|
||||
"src/crypto/x509/x_attrib.cc",
|
||||
"src/crypto/x509/x_crl.cc",
|
||||
"src/crypto/x509/x_exten.cc",
|
||||
"src/crypto/x509/x_name.cc",
|
||||
"src/crypto/x509/x_pubkey.cc",
|
||||
"src/crypto/x509/x_req.cc",
|
||||
"src/crypto/x509/x_sig.cc",
|
||||
"src/crypto/x509/x_spki.cc",
|
||||
"src/crypto/x509/x_val.cc",
|
||||
"src/crypto/x509/x_x509.cc",
|
||||
"src/crypto/x509/x_x509a.cc",
|
||||
"src/gen/crypto/err_data.cc",
|
||||
]
|
||||
|
||||
crypto_sources_asm = [
|
||||
"src/crypto/curve25519/asm/x25519-asm-arm.S",
|
||||
"src/crypto/hrss/asm/poly_rq_mul.S",
|
||||
"src/crypto/poly1305/poly1305_arm_asm.S",
|
||||
"src/gen/bcm/aes-gcm-avx2-x86_64-apple.S",
|
||||
"src/gen/bcm/aes-gcm-avx2-x86_64-linux.S",
|
||||
"src/gen/bcm/aes-gcm-avx512-x86_64-apple.S",
|
||||
"src/gen/bcm/aes-gcm-avx512-x86_64-linux.S",
|
||||
"src/gen/bcm/aesni-gcm-x86_64-apple.S",
|
||||
"src/gen/bcm/aesni-gcm-x86_64-linux.S",
|
||||
"src/gen/bcm/aesni-x86-apple.S",
|
||||
"src/gen/bcm/aesni-x86-linux.S",
|
||||
"src/gen/bcm/aesni-x86_64-apple.S",
|
||||
"src/gen/bcm/aesni-x86_64-linux.S",
|
||||
"src/gen/bcm/aesv8-armv7-linux.S",
|
||||
"src/gen/bcm/aesv8-armv8-apple.S",
|
||||
"src/gen/bcm/aesv8-armv8-linux.S",
|
||||
"src/gen/bcm/aesv8-armv8-win.S",
|
||||
"src/gen/bcm/aesv8-gcm-armv8-apple.S",
|
||||
"src/gen/bcm/aesv8-gcm-armv8-linux.S",
|
||||
"src/gen/bcm/aesv8-gcm-armv8-win.S",
|
||||
"src/gen/bcm/armv4-mont-linux.S",
|
||||
"src/gen/bcm/armv8-mont-apple.S",
|
||||
"src/gen/bcm/armv8-mont-linux.S",
|
||||
"src/gen/bcm/armv8-mont-win.S",
|
||||
"src/gen/bcm/bn-586-apple.S",
|
||||
"src/gen/bcm/bn-586-linux.S",
|
||||
"src/gen/bcm/bn-armv8-apple.S",
|
||||
"src/gen/bcm/bn-armv8-linux.S",
|
||||
"src/gen/bcm/bn-armv8-win.S",
|
||||
"src/gen/bcm/bsaes-armv7-linux.S",
|
||||
"src/gen/bcm/co-586-apple.S",
|
||||
"src/gen/bcm/co-586-linux.S",
|
||||
"src/gen/bcm/ghash-armv4-linux.S",
|
||||
"src/gen/bcm/ghash-neon-armv8-apple.S",
|
||||
"src/gen/bcm/ghash-neon-armv8-linux.S",
|
||||
"src/gen/bcm/ghash-neon-armv8-win.S",
|
||||
"src/gen/bcm/ghash-ssse3-x86-apple.S",
|
||||
"src/gen/bcm/ghash-ssse3-x86-linux.S",
|
||||
"src/gen/bcm/ghash-ssse3-x86_64-apple.S",
|
||||
"src/gen/bcm/ghash-ssse3-x86_64-linux.S",
|
||||
"src/gen/bcm/ghash-x86-apple.S",
|
||||
"src/gen/bcm/ghash-x86-linux.S",
|
||||
"src/gen/bcm/ghash-x86_64-apple.S",
|
||||
"src/gen/bcm/ghash-x86_64-linux.S",
|
||||
"src/gen/bcm/ghashv8-armv7-linux.S",
|
||||
"src/gen/bcm/ghashv8-armv8-apple.S",
|
||||
"src/gen/bcm/ghashv8-armv8-linux.S",
|
||||
"src/gen/bcm/ghashv8-armv8-win.S",
|
||||
"src/gen/bcm/p256-armv8-asm-apple.S",
|
||||
"src/gen/bcm/p256-armv8-asm-linux.S",
|
||||
"src/gen/bcm/p256-armv8-asm-win.S",
|
||||
"src/gen/bcm/p256-x86_64-asm-apple.S",
|
||||
"src/gen/bcm/p256-x86_64-asm-linux.S",
|
||||
"src/gen/bcm/p256_beeu-armv8-asm-apple.S",
|
||||
"src/gen/bcm/p256_beeu-armv8-asm-linux.S",
|
||||
"src/gen/bcm/p256_beeu-armv8-asm-win.S",
|
||||
"src/gen/bcm/p256_beeu-x86_64-asm-apple.S",
|
||||
"src/gen/bcm/p256_beeu-x86_64-asm-linux.S",
|
||||
"src/gen/bcm/rdrand-x86_64-apple.S",
|
||||
"src/gen/bcm/rdrand-x86_64-linux.S",
|
||||
"src/gen/bcm/rsaz-avx2-apple.S",
|
||||
"src/gen/bcm/rsaz-avx2-linux.S",
|
||||
"src/gen/bcm/sha1-586-apple.S",
|
||||
"src/gen/bcm/sha1-586-linux.S",
|
||||
"src/gen/bcm/sha1-armv4-large-linux.S",
|
||||
"src/gen/bcm/sha1-armv8-apple.S",
|
||||
"src/gen/bcm/sha1-armv8-linux.S",
|
||||
"src/gen/bcm/sha1-armv8-win.S",
|
||||
"src/gen/bcm/sha1-x86_64-apple.S",
|
||||
"src/gen/bcm/sha1-x86_64-linux.S",
|
||||
"src/gen/bcm/sha256-586-apple.S",
|
||||
"src/gen/bcm/sha256-586-linux.S",
|
||||
"src/gen/bcm/sha256-armv4-linux.S",
|
||||
"src/gen/bcm/sha256-armv8-apple.S",
|
||||
"src/gen/bcm/sha256-armv8-linux.S",
|
||||
"src/gen/bcm/sha256-armv8-win.S",
|
||||
"src/gen/bcm/sha256-x86_64-apple.S",
|
||||
"src/gen/bcm/sha256-x86_64-linux.S",
|
||||
"src/gen/bcm/sha512-586-apple.S",
|
||||
"src/gen/bcm/sha512-586-linux.S",
|
||||
"src/gen/bcm/sha512-armv4-linux.S",
|
||||
"src/gen/bcm/sha512-armv8-apple.S",
|
||||
"src/gen/bcm/sha512-armv8-linux.S",
|
||||
"src/gen/bcm/sha512-armv8-win.S",
|
||||
"src/gen/bcm/sha512-x86_64-apple.S",
|
||||
"src/gen/bcm/sha512-x86_64-linux.S",
|
||||
"src/gen/bcm/vpaes-armv7-linux.S",
|
||||
"src/gen/bcm/vpaes-armv8-apple.S",
|
||||
"src/gen/bcm/vpaes-armv8-linux.S",
|
||||
"src/gen/bcm/vpaes-armv8-win.S",
|
||||
"src/gen/bcm/vpaes-x86-apple.S",
|
||||
"src/gen/bcm/vpaes-x86-linux.S",
|
||||
"src/gen/bcm/vpaes-x86_64-apple.S",
|
||||
"src/gen/bcm/vpaes-x86_64-linux.S",
|
||||
"src/gen/bcm/x86-mont-apple.S",
|
||||
"src/gen/bcm/x86-mont-linux.S",
|
||||
"src/gen/bcm/x86_64-mont-apple.S",
|
||||
"src/gen/bcm/x86_64-mont-linux.S",
|
||||
"src/gen/bcm/x86_64-mont5-apple.S",
|
||||
"src/gen/bcm/x86_64-mont5-linux.S",
|
||||
"src/gen/crypto/aes128gcmsiv-x86_64-apple.S",
|
||||
"src/gen/crypto/aes128gcmsiv-x86_64-linux.S",
|
||||
"src/gen/crypto/chacha-armv4-linux.S",
|
||||
"src/gen/crypto/chacha-armv8-apple.S",
|
||||
"src/gen/crypto/chacha-armv8-linux.S",
|
||||
"src/gen/crypto/chacha-armv8-win.S",
|
||||
"src/gen/crypto/chacha-x86-apple.S",
|
||||
"src/gen/crypto/chacha-x86-linux.S",
|
||||
"src/gen/crypto/chacha-x86_64-apple.S",
|
||||
"src/gen/crypto/chacha-x86_64-linux.S",
|
||||
"src/gen/crypto/chacha20_poly1305_armv8-apple.S",
|
||||
"src/gen/crypto/chacha20_poly1305_armv8-linux.S",
|
||||
"src/gen/crypto/chacha20_poly1305_armv8-win.S",
|
||||
"src/gen/crypto/chacha20_poly1305_x86_64-apple.S",
|
||||
"src/gen/crypto/chacha20_poly1305_x86_64-linux.S",
|
||||
"src/gen/crypto/md5-586-apple.S",
|
||||
"src/gen/crypto/md5-586-linux.S",
|
||||
"src/gen/crypto/md5-x86_64-apple.S",
|
||||
"src/gen/crypto/md5-x86_64-linux.S",
|
||||
"src/gen/test_support/trampoline-armv4-linux.S",
|
||||
"src/gen/test_support/trampoline-armv8-apple.S",
|
||||
"src/gen/test_support/trampoline-armv8-linux.S",
|
||||
"src/gen/test_support/trampoline-armv8-win.S",
|
||||
"src/gen/test_support/trampoline-x86-apple.S",
|
||||
"src/gen/test_support/trampoline-x86-linux.S",
|
||||
"src/gen/test_support/trampoline-x86_64-apple.S",
|
||||
"src/gen/test_support/trampoline-x86_64-linux.S",
|
||||
"src/third_party/fiat/asm/fiat_curve25519_adx_mul.S",
|
||||
"src/third_party/fiat/asm/fiat_curve25519_adx_square.S",
|
||||
"src/third_party/fiat/asm/fiat_p256_adx_mul.S",
|
||||
"src/third_party/fiat/asm/fiat_p256_adx_sqr.S",
|
||||
]
|
||||
|
||||
crypto_sources_nasm = [
|
||||
"src/gen/bcm/aes-gcm-avx2-x86_64-win.asm",
|
||||
"src/gen/bcm/aes-gcm-avx512-x86_64-win.asm",
|
||||
"src/gen/bcm/aesni-gcm-x86_64-win.asm",
|
||||
"src/gen/bcm/aesni-x86-win.asm",
|
||||
"src/gen/bcm/aesni-x86_64-win.asm",
|
||||
"src/gen/bcm/bn-586-win.asm",
|
||||
"src/gen/bcm/co-586-win.asm",
|
||||
"src/gen/bcm/ghash-ssse3-x86-win.asm",
|
||||
"src/gen/bcm/ghash-ssse3-x86_64-win.asm",
|
||||
"src/gen/bcm/ghash-x86-win.asm",
|
||||
"src/gen/bcm/ghash-x86_64-win.asm",
|
||||
"src/gen/bcm/p256-x86_64-asm-win.asm",
|
||||
"src/gen/bcm/p256_beeu-x86_64-asm-win.asm",
|
||||
"src/gen/bcm/rdrand-x86_64-win.asm",
|
||||
"src/gen/bcm/rsaz-avx2-win.asm",
|
||||
"src/gen/bcm/sha1-586-win.asm",
|
||||
"src/gen/bcm/sha1-x86_64-win.asm",
|
||||
"src/gen/bcm/sha256-586-win.asm",
|
||||
"src/gen/bcm/sha256-x86_64-win.asm",
|
||||
"src/gen/bcm/sha512-586-win.asm",
|
||||
"src/gen/bcm/sha512-x86_64-win.asm",
|
||||
"src/gen/bcm/vpaes-x86-win.asm",
|
||||
"src/gen/bcm/vpaes-x86_64-win.asm",
|
||||
"src/gen/bcm/x86-mont-win.asm",
|
||||
"src/gen/bcm/x86_64-mont-win.asm",
|
||||
"src/gen/bcm/x86_64-mont5-win.asm",
|
||||
"src/gen/crypto/aes128gcmsiv-x86_64-win.asm",
|
||||
"src/gen/crypto/chacha-x86-win.asm",
|
||||
"src/gen/crypto/chacha-x86_64-win.asm",
|
||||
"src/gen/crypto/chacha20_poly1305_x86_64-win.asm",
|
||||
"src/gen/crypto/md5-586-win.asm",
|
||||
"src/gen/crypto/md5-x86_64-win.asm",
|
||||
"src/gen/test_support/trampoline-x86-win.asm",
|
||||
"src/gen/test_support/trampoline-x86_64-win.asm",
|
||||
]
|
||||
|
||||
pki_headers = [
|
||||
"src/include/openssl/pki/certificate.h",
|
||||
"src/include/openssl/pki/ocsp.h",
|
||||
"src/include/openssl/pki/signature_verify_cache.h",
|
||||
"src/include/openssl/pki/verify.h",
|
||||
"src/include/openssl/pki/verify_error.h",
|
||||
]
|
||||
|
||||
pki_internal_headers = [
|
||||
"src/pki/cert_error_id.h",
|
||||
"src/pki/cert_error_params.h",
|
||||
"src/pki/cert_errors.h",
|
||||
"src/pki/cert_issuer_source.h",
|
||||
"src/pki/cert_issuer_source_static.h",
|
||||
"src/pki/cert_issuer_source_sync_unittest.h",
|
||||
"src/pki/certificate_policies.h",
|
||||
"src/pki/common_cert_errors.h",
|
||||
"src/pki/crl.h",
|
||||
"src/pki/encode_values.h",
|
||||
"src/pki/extended_key_usage.h",
|
||||
"src/pki/general_names.h",
|
||||
"src/pki/input.h",
|
||||
"src/pki/ip_util.h",
|
||||
"src/pki/mock_signature_verify_cache.h",
|
||||
"src/pki/name_constraints.h",
|
||||
"src/pki/nist_pkits_unittest.h",
|
||||
"src/pki/ocsp.h",
|
||||
"src/pki/parse_certificate.h",
|
||||
"src/pki/parse_name.h",
|
||||
"src/pki/parse_values.h",
|
||||
"src/pki/parsed_certificate.h",
|
||||
"src/pki/parser.h",
|
||||
"src/pki/path_builder.h",
|
||||
"src/pki/pem.h",
|
||||
"src/pki/revocation_util.h",
|
||||
"src/pki/signature_algorithm.h",
|
||||
"src/pki/simple_path_builder_delegate.h",
|
||||
"src/pki/string_util.h",
|
||||
"src/pki/test_helpers.h",
|
||||
"src/pki/testdata/nist-pkits/pkits_testcases-inl.h",
|
||||
"src/pki/trust_store.h",
|
||||
"src/pki/trust_store_collection.h",
|
||||
"src/pki/trust_store_in_memory.h",
|
||||
"src/pki/verify_certificate_chain.h",
|
||||
"src/pki/verify_certificate_chain_typed_unittest.h",
|
||||
"src/pki/verify_name_match.h",
|
||||
"src/pki/verify_signed_data.h",
|
||||
]
|
||||
|
||||
pki_sources = [
|
||||
"src/pki/cert_error_id.cc",
|
||||
"src/pki/cert_error_params.cc",
|
||||
"src/pki/cert_errors.cc",
|
||||
"src/pki/cert_issuer_source_static.cc",
|
||||
"src/pki/certificate.cc",
|
||||
"src/pki/certificate_policies.cc",
|
||||
"src/pki/common_cert_errors.cc",
|
||||
"src/pki/crl.cc",
|
||||
"src/pki/encode_values.cc",
|
||||
"src/pki/extended_key_usage.cc",
|
||||
"src/pki/general_names.cc",
|
||||
"src/pki/input.cc",
|
||||
"src/pki/ip_util.cc",
|
||||
"src/pki/name_constraints.cc",
|
||||
"src/pki/ocsp.cc",
|
||||
"src/pki/parse_certificate.cc",
|
||||
"src/pki/parse_name.cc",
|
||||
"src/pki/parse_values.cc",
|
||||
"src/pki/parsed_certificate.cc",
|
||||
"src/pki/parser.cc",
|
||||
"src/pki/path_builder.cc",
|
||||
"src/pki/pem.cc",
|
||||
"src/pki/revocation_util.cc",
|
||||
"src/pki/signature_algorithm.cc",
|
||||
"src/pki/simple_path_builder_delegate.cc",
|
||||
"src/pki/string_util.cc",
|
||||
"src/pki/trust_store.cc",
|
||||
"src/pki/trust_store_collection.cc",
|
||||
"src/pki/trust_store_in_memory.cc",
|
||||
"src/pki/verify.cc",
|
||||
"src/pki/verify_certificate_chain.cc",
|
||||
"src/pki/verify_error.cc",
|
||||
"src/pki/verify_name_match.cc",
|
||||
"src/pki/verify_signed_data.cc",
|
||||
]
|
||||
|
||||
rust_bssl_sys = [
|
||||
"src/rust/bssl-sys/src/lib.rs",
|
||||
]
|
||||
|
||||
rust_bssl_crypto = [
|
||||
"src/rust/bssl-crypto/src/aead.rs",
|
||||
"src/rust/bssl-crypto/src/aes.rs",
|
||||
"src/rust/bssl-crypto/src/cipher/aes_cbc.rs",
|
||||
"src/rust/bssl-crypto/src/cipher/aes_ctr.rs",
|
||||
"src/rust/bssl-crypto/src/cipher/mod.rs",
|
||||
"src/rust/bssl-crypto/src/digest.rs",
|
||||
"src/rust/bssl-crypto/src/ec.rs",
|
||||
"src/rust/bssl-crypto/src/ecdh.rs",
|
||||
"src/rust/bssl-crypto/src/ecdsa.rs",
|
||||
"src/rust/bssl-crypto/src/ed25519.rs",
|
||||
"src/rust/bssl-crypto/src/hkdf.rs",
|
||||
"src/rust/bssl-crypto/src/hmac.rs",
|
||||
"src/rust/bssl-crypto/src/hpke.rs",
|
||||
"src/rust/bssl-crypto/src/lib.rs",
|
||||
"src/rust/bssl-crypto/src/macros.rs",
|
||||
"src/rust/bssl-crypto/src/mem.rs",
|
||||
"src/rust/bssl-crypto/src/mldsa.rs",
|
||||
"src/rust/bssl-crypto/src/mlkem.rs",
|
||||
"src/rust/bssl-crypto/src/rand.rs",
|
||||
"src/rust/bssl-crypto/src/rsa.rs",
|
||||
"src/rust/bssl-crypto/src/scoped.rs",
|
||||
"src/rust/bssl-crypto/src/slhdsa.rs",
|
||||
"src/rust/bssl-crypto/src/test_helpers.rs",
|
||||
"src/rust/bssl-crypto/src/x25519.rs",
|
||||
]
|
||||
|
||||
tool_sources = [
|
||||
"src/tool/args.cc",
|
||||
"src/tool/ciphers.cc",
|
||||
"src/tool/client.cc",
|
||||
"src/tool/const.cc",
|
||||
"src/tool/digest.cc",
|
||||
"src/tool/fd.cc",
|
||||
"src/tool/file.cc",
|
||||
"src/tool/generate_ech.cc",
|
||||
"src/tool/generate_ed25519.cc",
|
||||
"src/tool/genrsa.cc",
|
||||
"src/tool/pkcs12.cc",
|
||||
"src/tool/rand.cc",
|
||||
"src/tool/server.cc",
|
||||
"src/tool/sign.cc",
|
||||
"src/tool/speed.cc",
|
||||
"src/tool/tool.cc",
|
||||
"src/tool/transport_common.cc",
|
||||
]
|
||||
|
||||
tool_headers = [
|
||||
"src/tool/internal.h",
|
||||
"src/tool/transport_common.h",
|
||||
]
|
||||
File diff suppressed because it is too large
Load Diff
595
CMakeLists.txt
595
CMakeLists.txt
@@ -1,595 +0,0 @@
|
||||
# Copyright 2015 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This file is created by generate_build_files.py. Do not edit manually.
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(BoringSSL LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common")
|
||||
endif()
|
||||
|
||||
# pthread_rwlock_t requires a feature flag on glibc.
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DNOMINMAX)
|
||||
# Allow use of fopen.
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
add_definitions(-DBORINGSSL_IMPLEMENTATION)
|
||||
|
||||
if(OPENSSL_NO_ASM)
|
||||
add_definitions(-DOPENSSL_NO_ASM)
|
||||
else()
|
||||
# On x86 and x86_64 Windows, we use the NASM output.
|
||||
if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
|
||||
enable_language(ASM_NASM)
|
||||
set(OPENSSL_NASM TRUE)
|
||||
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
|
||||
else()
|
||||
enable_language(ASM)
|
||||
set(OPENSSL_ASM TRUE)
|
||||
# Work around https://gitlab.kitware.com/cmake/cmake/-/issues/20771 in older
|
||||
# CMake versions.
|
||||
if(APPLE AND CMAKE_VERSION VERSION_LESS 3.19)
|
||||
if(CMAKE_OSX_SYSROOT)
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
|
||||
endif()
|
||||
foreach(arch ${CMAKE_OSX_ARCHITECTURES})
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
|
||||
endforeach()
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
|
||||
endif()
|
||||
# Clang's integerated assembler does not support debug symbols.
|
||||
if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-DBORINGSSL_SHARED_LIBRARY)
|
||||
# Enable position-independent code globally. This is needed because
|
||||
# some library targets are OBJECT libraries.
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||
endif()
|
||||
|
||||
set(
|
||||
CRYPTO_SOURCES_ASM
|
||||
|
||||
src/crypto/curve25519/asm/x25519-asm-arm.S
|
||||
src/crypto/hrss/asm/poly_rq_mul.S
|
||||
src/crypto/poly1305/poly1305_arm_asm.S
|
||||
src/gen/bcm/aes-gcm-avx2-x86_64-apple.S
|
||||
src/gen/bcm/aes-gcm-avx2-x86_64-linux.S
|
||||
src/gen/bcm/aes-gcm-avx512-x86_64-apple.S
|
||||
src/gen/bcm/aes-gcm-avx512-x86_64-linux.S
|
||||
src/gen/bcm/aesni-gcm-x86_64-apple.S
|
||||
src/gen/bcm/aesni-gcm-x86_64-linux.S
|
||||
src/gen/bcm/aesni-x86-apple.S
|
||||
src/gen/bcm/aesni-x86-linux.S
|
||||
src/gen/bcm/aesni-x86_64-apple.S
|
||||
src/gen/bcm/aesni-x86_64-linux.S
|
||||
src/gen/bcm/aesv8-armv7-linux.S
|
||||
src/gen/bcm/aesv8-armv8-apple.S
|
||||
src/gen/bcm/aesv8-armv8-linux.S
|
||||
src/gen/bcm/aesv8-armv8-win.S
|
||||
src/gen/bcm/aesv8-gcm-armv8-apple.S
|
||||
src/gen/bcm/aesv8-gcm-armv8-linux.S
|
||||
src/gen/bcm/aesv8-gcm-armv8-win.S
|
||||
src/gen/bcm/armv4-mont-linux.S
|
||||
src/gen/bcm/armv8-mont-apple.S
|
||||
src/gen/bcm/armv8-mont-linux.S
|
||||
src/gen/bcm/armv8-mont-win.S
|
||||
src/gen/bcm/bn-586-apple.S
|
||||
src/gen/bcm/bn-586-linux.S
|
||||
src/gen/bcm/bn-armv8-apple.S
|
||||
src/gen/bcm/bn-armv8-linux.S
|
||||
src/gen/bcm/bn-armv8-win.S
|
||||
src/gen/bcm/bsaes-armv7-linux.S
|
||||
src/gen/bcm/co-586-apple.S
|
||||
src/gen/bcm/co-586-linux.S
|
||||
src/gen/bcm/ghash-armv4-linux.S
|
||||
src/gen/bcm/ghash-neon-armv8-apple.S
|
||||
src/gen/bcm/ghash-neon-armv8-linux.S
|
||||
src/gen/bcm/ghash-neon-armv8-win.S
|
||||
src/gen/bcm/ghash-ssse3-x86-apple.S
|
||||
src/gen/bcm/ghash-ssse3-x86-linux.S
|
||||
src/gen/bcm/ghash-ssse3-x86_64-apple.S
|
||||
src/gen/bcm/ghash-ssse3-x86_64-linux.S
|
||||
src/gen/bcm/ghash-x86-apple.S
|
||||
src/gen/bcm/ghash-x86-linux.S
|
||||
src/gen/bcm/ghash-x86_64-apple.S
|
||||
src/gen/bcm/ghash-x86_64-linux.S
|
||||
src/gen/bcm/ghashv8-armv7-linux.S
|
||||
src/gen/bcm/ghashv8-armv8-apple.S
|
||||
src/gen/bcm/ghashv8-armv8-linux.S
|
||||
src/gen/bcm/ghashv8-armv8-win.S
|
||||
src/gen/bcm/p256-armv8-asm-apple.S
|
||||
src/gen/bcm/p256-armv8-asm-linux.S
|
||||
src/gen/bcm/p256-armv8-asm-win.S
|
||||
src/gen/bcm/p256-x86_64-asm-apple.S
|
||||
src/gen/bcm/p256-x86_64-asm-linux.S
|
||||
src/gen/bcm/p256_beeu-armv8-asm-apple.S
|
||||
src/gen/bcm/p256_beeu-armv8-asm-linux.S
|
||||
src/gen/bcm/p256_beeu-armv8-asm-win.S
|
||||
src/gen/bcm/p256_beeu-x86_64-asm-apple.S
|
||||
src/gen/bcm/p256_beeu-x86_64-asm-linux.S
|
||||
src/gen/bcm/rdrand-x86_64-apple.S
|
||||
src/gen/bcm/rdrand-x86_64-linux.S
|
||||
src/gen/bcm/rsaz-avx2-apple.S
|
||||
src/gen/bcm/rsaz-avx2-linux.S
|
||||
src/gen/bcm/sha1-586-apple.S
|
||||
src/gen/bcm/sha1-586-linux.S
|
||||
src/gen/bcm/sha1-armv4-large-linux.S
|
||||
src/gen/bcm/sha1-armv8-apple.S
|
||||
src/gen/bcm/sha1-armv8-linux.S
|
||||
src/gen/bcm/sha1-armv8-win.S
|
||||
src/gen/bcm/sha1-x86_64-apple.S
|
||||
src/gen/bcm/sha1-x86_64-linux.S
|
||||
src/gen/bcm/sha256-586-apple.S
|
||||
src/gen/bcm/sha256-586-linux.S
|
||||
src/gen/bcm/sha256-armv4-linux.S
|
||||
src/gen/bcm/sha256-armv8-apple.S
|
||||
src/gen/bcm/sha256-armv8-linux.S
|
||||
src/gen/bcm/sha256-armv8-win.S
|
||||
src/gen/bcm/sha256-x86_64-apple.S
|
||||
src/gen/bcm/sha256-x86_64-linux.S
|
||||
src/gen/bcm/sha512-586-apple.S
|
||||
src/gen/bcm/sha512-586-linux.S
|
||||
src/gen/bcm/sha512-armv4-linux.S
|
||||
src/gen/bcm/sha512-armv8-apple.S
|
||||
src/gen/bcm/sha512-armv8-linux.S
|
||||
src/gen/bcm/sha512-armv8-win.S
|
||||
src/gen/bcm/sha512-x86_64-apple.S
|
||||
src/gen/bcm/sha512-x86_64-linux.S
|
||||
src/gen/bcm/vpaes-armv7-linux.S
|
||||
src/gen/bcm/vpaes-armv8-apple.S
|
||||
src/gen/bcm/vpaes-armv8-linux.S
|
||||
src/gen/bcm/vpaes-armv8-win.S
|
||||
src/gen/bcm/vpaes-x86-apple.S
|
||||
src/gen/bcm/vpaes-x86-linux.S
|
||||
src/gen/bcm/vpaes-x86_64-apple.S
|
||||
src/gen/bcm/vpaes-x86_64-linux.S
|
||||
src/gen/bcm/x86-mont-apple.S
|
||||
src/gen/bcm/x86-mont-linux.S
|
||||
src/gen/bcm/x86_64-mont-apple.S
|
||||
src/gen/bcm/x86_64-mont-linux.S
|
||||
src/gen/bcm/x86_64-mont5-apple.S
|
||||
src/gen/bcm/x86_64-mont5-linux.S
|
||||
src/gen/crypto/aes128gcmsiv-x86_64-apple.S
|
||||
src/gen/crypto/aes128gcmsiv-x86_64-linux.S
|
||||
src/gen/crypto/chacha-armv4-linux.S
|
||||
src/gen/crypto/chacha-armv8-apple.S
|
||||
src/gen/crypto/chacha-armv8-linux.S
|
||||
src/gen/crypto/chacha-armv8-win.S
|
||||
src/gen/crypto/chacha-x86-apple.S
|
||||
src/gen/crypto/chacha-x86-linux.S
|
||||
src/gen/crypto/chacha-x86_64-apple.S
|
||||
src/gen/crypto/chacha-x86_64-linux.S
|
||||
src/gen/crypto/chacha20_poly1305_armv8-apple.S
|
||||
src/gen/crypto/chacha20_poly1305_armv8-linux.S
|
||||
src/gen/crypto/chacha20_poly1305_armv8-win.S
|
||||
src/gen/crypto/chacha20_poly1305_x86_64-apple.S
|
||||
src/gen/crypto/chacha20_poly1305_x86_64-linux.S
|
||||
src/gen/crypto/md5-586-apple.S
|
||||
src/gen/crypto/md5-586-linux.S
|
||||
src/gen/crypto/md5-x86_64-apple.S
|
||||
src/gen/crypto/md5-x86_64-linux.S
|
||||
src/gen/test_support/trampoline-armv4-linux.S
|
||||
src/gen/test_support/trampoline-armv8-apple.S
|
||||
src/gen/test_support/trampoline-armv8-linux.S
|
||||
src/gen/test_support/trampoline-armv8-win.S
|
||||
src/gen/test_support/trampoline-x86-apple.S
|
||||
src/gen/test_support/trampoline-x86-linux.S
|
||||
src/gen/test_support/trampoline-x86_64-apple.S
|
||||
src/gen/test_support/trampoline-x86_64-linux.S
|
||||
src/third_party/fiat/asm/fiat_curve25519_adx_mul.S
|
||||
src/third_party/fiat/asm/fiat_curve25519_adx_square.S
|
||||
src/third_party/fiat/asm/fiat_p256_adx_mul.S
|
||||
src/third_party/fiat/asm/fiat_p256_adx_sqr.S
|
||||
)
|
||||
|
||||
set(
|
||||
CRYPTO_SOURCES_NASM
|
||||
|
||||
src/gen/bcm/aes-gcm-avx2-x86_64-win.asm
|
||||
src/gen/bcm/aes-gcm-avx512-x86_64-win.asm
|
||||
src/gen/bcm/aesni-gcm-x86_64-win.asm
|
||||
src/gen/bcm/aesni-x86-win.asm
|
||||
src/gen/bcm/aesni-x86_64-win.asm
|
||||
src/gen/bcm/bn-586-win.asm
|
||||
src/gen/bcm/co-586-win.asm
|
||||
src/gen/bcm/ghash-ssse3-x86-win.asm
|
||||
src/gen/bcm/ghash-ssse3-x86_64-win.asm
|
||||
src/gen/bcm/ghash-x86-win.asm
|
||||
src/gen/bcm/ghash-x86_64-win.asm
|
||||
src/gen/bcm/p256-x86_64-asm-win.asm
|
||||
src/gen/bcm/p256_beeu-x86_64-asm-win.asm
|
||||
src/gen/bcm/rdrand-x86_64-win.asm
|
||||
src/gen/bcm/rsaz-avx2-win.asm
|
||||
src/gen/bcm/sha1-586-win.asm
|
||||
src/gen/bcm/sha1-x86_64-win.asm
|
||||
src/gen/bcm/sha256-586-win.asm
|
||||
src/gen/bcm/sha256-x86_64-win.asm
|
||||
src/gen/bcm/sha512-586-win.asm
|
||||
src/gen/bcm/sha512-x86_64-win.asm
|
||||
src/gen/bcm/vpaes-x86-win.asm
|
||||
src/gen/bcm/vpaes-x86_64-win.asm
|
||||
src/gen/bcm/x86-mont-win.asm
|
||||
src/gen/bcm/x86_64-mont-win.asm
|
||||
src/gen/bcm/x86_64-mont5-win.asm
|
||||
src/gen/crypto/aes128gcmsiv-x86_64-win.asm
|
||||
src/gen/crypto/chacha-x86-win.asm
|
||||
src/gen/crypto/chacha-x86_64-win.asm
|
||||
src/gen/crypto/chacha20_poly1305_x86_64-win.asm
|
||||
src/gen/crypto/md5-586-win.asm
|
||||
src/gen/crypto/md5-x86_64-win.asm
|
||||
src/gen/test_support/trampoline-x86-win.asm
|
||||
src/gen/test_support/trampoline-x86_64-win.asm
|
||||
)
|
||||
|
||||
if(OPENSSL_ASM)
|
||||
list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
|
||||
endif()
|
||||
if(OPENSSL_NASM)
|
||||
list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
|
||||
endif()
|
||||
|
||||
add_library(
|
||||
crypto
|
||||
|
||||
${CRYPTO_SOURCES_ASM_USED}
|
||||
src/crypto/aes/aes.cc
|
||||
src/crypto/asn1/a_bitstr.cc
|
||||
src/crypto/asn1/a_bool.cc
|
||||
src/crypto/asn1/a_d2i_fp.cc
|
||||
src/crypto/asn1/a_dup.cc
|
||||
src/crypto/asn1/a_gentm.cc
|
||||
src/crypto/asn1/a_i2d_fp.cc
|
||||
src/crypto/asn1/a_int.cc
|
||||
src/crypto/asn1/a_mbstr.cc
|
||||
src/crypto/asn1/a_object.cc
|
||||
src/crypto/asn1/a_octet.cc
|
||||
src/crypto/asn1/a_strex.cc
|
||||
src/crypto/asn1/a_strnid.cc
|
||||
src/crypto/asn1/a_time.cc
|
||||
src/crypto/asn1/a_type.cc
|
||||
src/crypto/asn1/a_utctm.cc
|
||||
src/crypto/asn1/asn1_lib.cc
|
||||
src/crypto/asn1/asn1_par.cc
|
||||
src/crypto/asn1/asn_pack.cc
|
||||
src/crypto/asn1/f_int.cc
|
||||
src/crypto/asn1/f_string.cc
|
||||
src/crypto/asn1/posix_time.cc
|
||||
src/crypto/asn1/tasn_dec.cc
|
||||
src/crypto/asn1/tasn_enc.cc
|
||||
src/crypto/asn1/tasn_fre.cc
|
||||
src/crypto/asn1/tasn_new.cc
|
||||
src/crypto/asn1/tasn_typ.cc
|
||||
src/crypto/asn1/tasn_utl.cc
|
||||
src/crypto/base64/base64.cc
|
||||
src/crypto/bio/bio.cc
|
||||
src/crypto/bio/bio_mem.cc
|
||||
src/crypto/bio/connect.cc
|
||||
src/crypto/bio/errno.cc
|
||||
src/crypto/bio/fd.cc
|
||||
src/crypto/bio/file.cc
|
||||
src/crypto/bio/hexdump.cc
|
||||
src/crypto/bio/pair.cc
|
||||
src/crypto/bio/printf.cc
|
||||
src/crypto/bio/socket.cc
|
||||
src/crypto/bio/socket_helper.cc
|
||||
src/crypto/blake2/blake2.cc
|
||||
src/crypto/bn/bn_asn1.cc
|
||||
src/crypto/bn/convert.cc
|
||||
src/crypto/bn/div.cc
|
||||
src/crypto/bn/exponentiation.cc
|
||||
src/crypto/bn/sqrt.cc
|
||||
src/crypto/buf/buf.cc
|
||||
src/crypto/bytestring/asn1_compat.cc
|
||||
src/crypto/bytestring/ber.cc
|
||||
src/crypto/bytestring/cbb.cc
|
||||
src/crypto/bytestring/cbs.cc
|
||||
src/crypto/bytestring/unicode.cc
|
||||
src/crypto/chacha/chacha.cc
|
||||
src/crypto/cipher/derive_key.cc
|
||||
src/crypto/cipher/e_aesctrhmac.cc
|
||||
src/crypto/cipher/e_aeseax.cc
|
||||
src/crypto/cipher/e_aesgcmsiv.cc
|
||||
src/crypto/cipher/e_chacha20poly1305.cc
|
||||
src/crypto/cipher/e_des.cc
|
||||
src/crypto/cipher/e_null.cc
|
||||
src/crypto/cipher/e_rc2.cc
|
||||
src/crypto/cipher/e_rc4.cc
|
||||
src/crypto/cipher/e_tls.cc
|
||||
src/crypto/cipher/get_cipher.cc
|
||||
src/crypto/cipher/tls_cbc.cc
|
||||
src/crypto/cms/cms.cc
|
||||
src/crypto/conf/conf.cc
|
||||
src/crypto/cpu_aarch64_apple.cc
|
||||
src/crypto/cpu_aarch64_fuchsia.cc
|
||||
src/crypto/cpu_aarch64_linux.cc
|
||||
src/crypto/cpu_aarch64_openbsd.cc
|
||||
src/crypto/cpu_aarch64_sysreg.cc
|
||||
src/crypto/cpu_aarch64_win.cc
|
||||
src/crypto/cpu_arm_freebsd.cc
|
||||
src/crypto/cpu_arm_linux.cc
|
||||
src/crypto/cpu_intel.cc
|
||||
src/crypto/crypto.cc
|
||||
src/crypto/curve25519/curve25519.cc
|
||||
src/crypto/curve25519/curve25519_64_adx.cc
|
||||
src/crypto/curve25519/spake25519.cc
|
||||
src/crypto/des/des.cc
|
||||
src/crypto/dh/dh_asn1.cc
|
||||
src/crypto/dh/params.cc
|
||||
src/crypto/digest/digest_extra.cc
|
||||
src/crypto/dsa/dsa.cc
|
||||
src/crypto/dsa/dsa_asn1.cc
|
||||
src/crypto/ec/ec_asn1.cc
|
||||
src/crypto/ec/ec_derive.cc
|
||||
src/crypto/ec/hash_to_curve.cc
|
||||
src/crypto/ecdh/ecdh.cc
|
||||
src/crypto/ecdsa/ecdsa_asn1.cc
|
||||
src/crypto/engine/engine.cc
|
||||
src/crypto/err/err.cc
|
||||
src/crypto/evp/evp.cc
|
||||
src/crypto/evp/evp_asn1.cc
|
||||
src/crypto/evp/evp_ctx.cc
|
||||
src/crypto/evp/p_dh.cc
|
||||
src/crypto/evp/p_dh_asn1.cc
|
||||
src/crypto/evp/p_dsa_asn1.cc
|
||||
src/crypto/evp/p_ec.cc
|
||||
src/crypto/evp/p_ec_asn1.cc
|
||||
src/crypto/evp/p_ed25519.cc
|
||||
src/crypto/evp/p_ed25519_asn1.cc
|
||||
src/crypto/evp/p_hkdf.cc
|
||||
src/crypto/evp/p_rsa.cc
|
||||
src/crypto/evp/p_rsa_asn1.cc
|
||||
src/crypto/evp/p_x25519.cc
|
||||
src/crypto/evp/p_x25519_asn1.cc
|
||||
src/crypto/evp/pbkdf.cc
|
||||
src/crypto/evp/print.cc
|
||||
src/crypto/evp/scrypt.cc
|
||||
src/crypto/evp/sign.cc
|
||||
src/crypto/ex_data.cc
|
||||
src/crypto/fipsmodule/bcm.cc
|
||||
src/crypto/fipsmodule/fips_shared_support.cc
|
||||
src/crypto/fuzzer_mode.cc
|
||||
src/crypto/hpke/hpke.cc
|
||||
src/crypto/hrss/hrss.cc
|
||||
src/crypto/kyber/kyber.cc
|
||||
src/crypto/lhash/lhash.cc
|
||||
src/crypto/md4/md4.cc
|
||||
src/crypto/md5/md5.cc
|
||||
src/crypto/mem.cc
|
||||
src/crypto/mldsa/mldsa.cc
|
||||
src/crypto/mlkem/mlkem.cc
|
||||
src/crypto/obj/obj.cc
|
||||
src/crypto/obj/obj_xref.cc
|
||||
src/crypto/pem/pem_all.cc
|
||||
src/crypto/pem/pem_info.cc
|
||||
src/crypto/pem/pem_lib.cc
|
||||
src/crypto/pem/pem_oth.cc
|
||||
src/crypto/pem/pem_pk8.cc
|
||||
src/crypto/pem/pem_pkey.cc
|
||||
src/crypto/pem/pem_x509.cc
|
||||
src/crypto/pem/pem_xaux.cc
|
||||
src/crypto/pkcs7/pkcs7.cc
|
||||
src/crypto/pkcs7/pkcs7_x509.cc
|
||||
src/crypto/pkcs8/p5_pbev2.cc
|
||||
src/crypto/pkcs8/pkcs8.cc
|
||||
src/crypto/pkcs8/pkcs8_x509.cc
|
||||
src/crypto/poly1305/poly1305.cc
|
||||
src/crypto/poly1305/poly1305_arm.cc
|
||||
src/crypto/poly1305/poly1305_vec.cc
|
||||
src/crypto/pool/pool.cc
|
||||
src/crypto/rand/deterministic.cc
|
||||
src/crypto/rand/fork_detect.cc
|
||||
src/crypto/rand/forkunsafe.cc
|
||||
src/crypto/rand/getentropy.cc
|
||||
src/crypto/rand/ios.cc
|
||||
src/crypto/rand/passive.cc
|
||||
src/crypto/rand/rand.cc
|
||||
src/crypto/rand/trusty.cc
|
||||
src/crypto/rand/urandom.cc
|
||||
src/crypto/rand/windows.cc
|
||||
src/crypto/rc4/rc4.cc
|
||||
src/crypto/refcount.cc
|
||||
src/crypto/rsa/rsa_asn1.cc
|
||||
src/crypto/rsa/rsa_crypt.cc
|
||||
src/crypto/rsa/rsa_extra.cc
|
||||
src/crypto/rsa/rsa_print.cc
|
||||
src/crypto/sha/sha1.cc
|
||||
src/crypto/sha/sha256.cc
|
||||
src/crypto/sha/sha512.cc
|
||||
src/crypto/siphash/siphash.cc
|
||||
src/crypto/slhdsa/slhdsa.cc
|
||||
src/crypto/spake2plus/spake2plus.cc
|
||||
src/crypto/stack/stack.cc
|
||||
src/crypto/thread.cc
|
||||
src/crypto/thread_none.cc
|
||||
src/crypto/thread_pthread.cc
|
||||
src/crypto/thread_win.cc
|
||||
src/crypto/trust_token/pmbtoken.cc
|
||||
src/crypto/trust_token/trust_token.cc
|
||||
src/crypto/trust_token/voprf.cc
|
||||
src/crypto/x509/a_digest.cc
|
||||
src/crypto/x509/a_sign.cc
|
||||
src/crypto/x509/a_verify.cc
|
||||
src/crypto/x509/algorithm.cc
|
||||
src/crypto/x509/asn1_gen.cc
|
||||
src/crypto/x509/by_dir.cc
|
||||
src/crypto/x509/by_file.cc
|
||||
src/crypto/x509/i2d_pr.cc
|
||||
src/crypto/x509/name_print.cc
|
||||
src/crypto/x509/policy.cc
|
||||
src/crypto/x509/rsa_pss.cc
|
||||
src/crypto/x509/t_crl.cc
|
||||
src/crypto/x509/t_req.cc
|
||||
src/crypto/x509/t_x509.cc
|
||||
src/crypto/x509/t_x509a.cc
|
||||
src/crypto/x509/v3_akey.cc
|
||||
src/crypto/x509/v3_akeya.cc
|
||||
src/crypto/x509/v3_alt.cc
|
||||
src/crypto/x509/v3_bcons.cc
|
||||
src/crypto/x509/v3_bitst.cc
|
||||
src/crypto/x509/v3_conf.cc
|
||||
src/crypto/x509/v3_cpols.cc
|
||||
src/crypto/x509/v3_crld.cc
|
||||
src/crypto/x509/v3_enum.cc
|
||||
src/crypto/x509/v3_extku.cc
|
||||
src/crypto/x509/v3_genn.cc
|
||||
src/crypto/x509/v3_ia5.cc
|
||||
src/crypto/x509/v3_info.cc
|
||||
src/crypto/x509/v3_int.cc
|
||||
src/crypto/x509/v3_lib.cc
|
||||
src/crypto/x509/v3_ncons.cc
|
||||
src/crypto/x509/v3_ocsp.cc
|
||||
src/crypto/x509/v3_pcons.cc
|
||||
src/crypto/x509/v3_pmaps.cc
|
||||
src/crypto/x509/v3_prn.cc
|
||||
src/crypto/x509/v3_purp.cc
|
||||
src/crypto/x509/v3_skey.cc
|
||||
src/crypto/x509/v3_utl.cc
|
||||
src/crypto/x509/x509.cc
|
||||
src/crypto/x509/x509_att.cc
|
||||
src/crypto/x509/x509_cmp.cc
|
||||
src/crypto/x509/x509_d2.cc
|
||||
src/crypto/x509/x509_def.cc
|
||||
src/crypto/x509/x509_ext.cc
|
||||
src/crypto/x509/x509_lu.cc
|
||||
src/crypto/x509/x509_obj.cc
|
||||
src/crypto/x509/x509_req.cc
|
||||
src/crypto/x509/x509_set.cc
|
||||
src/crypto/x509/x509_trs.cc
|
||||
src/crypto/x509/x509_txt.cc
|
||||
src/crypto/x509/x509_v3.cc
|
||||
src/crypto/x509/x509_vfy.cc
|
||||
src/crypto/x509/x509_vpm.cc
|
||||
src/crypto/x509/x509cset.cc
|
||||
src/crypto/x509/x509name.cc
|
||||
src/crypto/x509/x509rset.cc
|
||||
src/crypto/x509/x509spki.cc
|
||||
src/crypto/x509/x_algor.cc
|
||||
src/crypto/x509/x_all.cc
|
||||
src/crypto/x509/x_attrib.cc
|
||||
src/crypto/x509/x_crl.cc
|
||||
src/crypto/x509/x_exten.cc
|
||||
src/crypto/x509/x_name.cc
|
||||
src/crypto/x509/x_pubkey.cc
|
||||
src/crypto/x509/x_req.cc
|
||||
src/crypto/x509/x_sig.cc
|
||||
src/crypto/x509/x_spki.cc
|
||||
src/crypto/x509/x_val.cc
|
||||
src/crypto/x509/x_x509.cc
|
||||
src/crypto/x509/x_x509a.cc
|
||||
src/gen/crypto/err_data.cc
|
||||
)
|
||||
|
||||
target_include_directories(crypto PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/include>)
|
||||
|
||||
add_library(
|
||||
ssl
|
||||
|
||||
src/ssl/bio_ssl.cc
|
||||
src/ssl/d1_both.cc
|
||||
src/ssl/d1_lib.cc
|
||||
src/ssl/d1_pkt.cc
|
||||
src/ssl/d1_srtp.cc
|
||||
src/ssl/dtls_method.cc
|
||||
src/ssl/dtls_record.cc
|
||||
src/ssl/encrypted_client_hello.cc
|
||||
src/ssl/extensions.cc
|
||||
src/ssl/handoff.cc
|
||||
src/ssl/handshake.cc
|
||||
src/ssl/handshake_client.cc
|
||||
src/ssl/handshake_server.cc
|
||||
src/ssl/s3_both.cc
|
||||
src/ssl/s3_lib.cc
|
||||
src/ssl/s3_pkt.cc
|
||||
src/ssl/ssl_aead_ctx.cc
|
||||
src/ssl/ssl_asn1.cc
|
||||
src/ssl/ssl_buffer.cc
|
||||
src/ssl/ssl_cert.cc
|
||||
src/ssl/ssl_cipher.cc
|
||||
src/ssl/ssl_credential.cc
|
||||
src/ssl/ssl_file.cc
|
||||
src/ssl/ssl_key_share.cc
|
||||
src/ssl/ssl_lib.cc
|
||||
src/ssl/ssl_privkey.cc
|
||||
src/ssl/ssl_session.cc
|
||||
src/ssl/ssl_stat.cc
|
||||
src/ssl/ssl_transcript.cc
|
||||
src/ssl/ssl_versions.cc
|
||||
src/ssl/ssl_x509.cc
|
||||
src/ssl/t1_enc.cc
|
||||
src/ssl/tls13_both.cc
|
||||
src/ssl/tls13_client.cc
|
||||
src/ssl/tls13_enc.cc
|
||||
src/ssl/tls13_server.cc
|
||||
src/ssl/tls_method.cc
|
||||
src/ssl/tls_record.cc
|
||||
)
|
||||
|
||||
target_link_libraries(ssl crypto)
|
||||
|
||||
add_executable(
|
||||
bssl
|
||||
|
||||
src/tool/args.cc
|
||||
src/tool/ciphers.cc
|
||||
src/tool/client.cc
|
||||
src/tool/const.cc
|
||||
src/tool/digest.cc
|
||||
src/tool/fd.cc
|
||||
src/tool/file.cc
|
||||
src/tool/generate_ech.cc
|
||||
src/tool/generate_ed25519.cc
|
||||
src/tool/genrsa.cc
|
||||
src/tool/pkcs12.cc
|
||||
src/tool/rand.cc
|
||||
src/tool/server.cc
|
||||
src/tool/sign.cc
|
||||
src/tool/speed.cc
|
||||
src/tool/tool.cc
|
||||
src/tool/transport_common.cc
|
||||
)
|
||||
|
||||
target_link_libraries(bssl ssl crypto)
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(crypto Threads::Threads)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(crypto ws2_32)
|
||||
endif()
|
||||
|
||||
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Deprecated Branch
|
||||
|
||||
The `master-with-bazel` branch is no longer being updated. Instead, use the
|
||||
`main` branch, which now itself has a Bazel build.
|
||||
25
WORKSPACE
25
WORKSPACE
@@ -1,25 +0,0 @@
|
||||
# Copyright 2023 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
workspace(name = "boringssl")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "rules_license",
|
||||
sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz",
|
||||
],
|
||||
)
|
||||
2746
sources.json
2746
sources.json
File diff suppressed because it is too large
Load Diff
@@ -1,2 +0,0 @@
|
||||
third_party/googletest
|
||||
util/bazel-example
|
||||
50
src/.bazelrc
50
src/.bazelrc
@@ -1,50 +0,0 @@
|
||||
# Copyright 2024 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This is a bazelrc file, documented in https://bazel.build/run/bazelrc and
|
||||
# specifies default flags when BoringSSL is the root project. It has no effect
|
||||
# on downstream projects, which define their own toolchains and configs.
|
||||
|
||||
# See https://bazel.build/run/bazelrc#enable_platform_specific_config.
|
||||
# This expands to --config=osname which, in turn, expands to the options
|
||||
# specified below.
|
||||
build --enable_platform_specific_config
|
||||
|
||||
# Enable additional checks.
|
||||
build --features=layering_check
|
||||
build --features=parse_headers
|
||||
|
||||
# Bazel has no abstractions for setting C++ versions and expects the root
|
||||
# project to use the compiler-specific options for their toolchains. (Bazel only
|
||||
# wants the root to set the C++ version for the sake of projects like Abseil
|
||||
# whose ABI depends on the C++ version.)
|
||||
build:linux --cxxopt=-std=c++17
|
||||
build:macos --cxxopt=-std=c++17
|
||||
build:windows --cxxopt=/std:c++17
|
||||
|
||||
# Our own builds should strictly build without warnings, but we don't add those
|
||||
# in targets like other flags because we can't assume all users will have clean
|
||||
# builds too.
|
||||
build:linux --cxxopt=-Werror
|
||||
build:macos --cxxopt=-Werror
|
||||
|
||||
# Without setting a minimum macOS version, std::optional does not work.
|
||||
build:macos --cxxopt=-mmacosx-version-min=10.15
|
||||
|
||||
# Without /Zc:__cplusplus, MSVC does not define the right value for
|
||||
# __cplusplus. See https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
build:windows --cxxopt=/Zc:__cplusplus
|
||||
|
||||
# https://bazel.build/configure/best-practices#bazelrc-file
|
||||
try-import %workspace%/user.bazelrc
|
||||
@@ -1 +0,0 @@
|
||||
7.5.0
|
||||
@@ -1,6 +0,0 @@
|
||||
# BCR Configuration
|
||||
|
||||
This directory contains configuration information for BCR. It is patterned after
|
||||
the [Publish to BCR app](https://github.com/bazel-contrib/publish-to-bcr/tree/main/templates),
|
||||
which we have [opted not to use](https://github.com/bazel-contrib/publish-to-bcr/issues/157).
|
||||
However, `presubmit.yml` is used by [our own BCR tooling](../docs/releasing.md).
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"homepage": "https://boringssl.googlesource.com/boringssl/",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "agl@google.com",
|
||||
"github": "agl",
|
||||
"name": "Adam Langley"
|
||||
},
|
||||
{
|
||||
"email": "davidben@google.com",
|
||||
"github": "davidben",
|
||||
"name": "David Benjamin"
|
||||
},
|
||||
{
|
||||
"email": "dadrian@google.com",
|
||||
"github": "dadrian",
|
||||
"name": "David Adrian"
|
||||
}
|
||||
],
|
||||
"repository": [
|
||||
"github:google/boringssl"
|
||||
],
|
||||
"versions": [],
|
||||
"yanked_versions": {}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
build_targets: &build_targets
|
||||
- "@boringssl//:crypto"
|
||||
- "@boringssl//:ssl"
|
||||
|
||||
matrix: &matrix
|
||||
linux_platforms:
|
||||
- debian11
|
||||
- ubuntu2204
|
||||
bazel: [7.x]
|
||||
tasks:
|
||||
verify_targets_on_linux:
|
||||
name: Verify build targets on Linux
|
||||
platform: ${{ linux_platforms }}
|
||||
bazel: ${{ bazel }}
|
||||
build_targets: *build_targets
|
||||
build_flags:
|
||||
- '--cxxopt=-std=c++17'
|
||||
verify_targets_on_windows:
|
||||
name: Verify build targets on Windows
|
||||
platform: windows
|
||||
bazel: ${{ bazel }}
|
||||
build_targets: *build_targets
|
||||
build_flags:
|
||||
- '--cxxopt=/std:c++17'
|
||||
# Work around https://github.com/bazelbuild/bazel/issues/10472
|
||||
verify_targets_on_macos:
|
||||
name: Verify build targets on macOS
|
||||
platform: macos
|
||||
bazel: ${{ bazel }}
|
||||
build_targets: *build_targets
|
||||
build_flags: &macos_workaround
|
||||
- '--cxxopt=-std=c++17'
|
||||
- '--sandbox_block_path=/usr/local'
|
||||
bcr_test_module:
|
||||
module_path: util/bazel-example
|
||||
matrix: *matrix
|
||||
tasks:
|
||||
run_test_module_on_linux:
|
||||
name: Run test module on Linux
|
||||
platform: ${{ linux_platforms }}
|
||||
bazel: ${{ bazel }}
|
||||
build_targets:
|
||||
- //...
|
||||
build_flags:
|
||||
- '--cxxopt=-std=c++17'
|
||||
run_test_module_on_windows:
|
||||
name: Run test module on Windows
|
||||
platform: windows
|
||||
bazel: ${{ bazel }}
|
||||
build_targets:
|
||||
- //...
|
||||
build_flags:
|
||||
- '--cxxopt=/std:c++17'
|
||||
# Work around https://github.com/bazelbuild/bazel/issues/10472
|
||||
run_test_module_on_macos:
|
||||
name: Run test module on macOS
|
||||
platform: macos
|
||||
bazel: ${{ bazel }}
|
||||
build_targets:
|
||||
- //...
|
||||
build_flags: *macos_workaround
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"integrity": "",
|
||||
"strip_prefix": "{REPO}-{VERSION}",
|
||||
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
BasedOnStyle: Google
|
||||
MaxEmptyLinesToKeep: 3
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Right
|
||||
# TODO(davidben): The default for Google style is now Regroup, but the default
|
||||
# IncludeCategories does not recognize <openssl/header.h>. We should
|
||||
# reconfigure IncludeCategories to match. For now, keep it at Preserve.
|
||||
IncludeBlocks: Preserve
|
||||
InsertBraces: true
|
||||
TypenameMacros: ['LHASH_OF', 'STACK_OF']
|
||||
StatementMacros:
|
||||
- "DECLARE_ASN1_ALLOC_FUNCTIONS"
|
||||
- "DECLARE_ASN1_ALLOC_FUNCTIONS_name"
|
||||
- "DECLARE_ASN1_ENCODE_FUNCTIONS"
|
||||
- "DECLARE_ASN1_ENCODE_FUNCTIONS_const"
|
||||
- "DECLARE_ASN1_FUNCTIONS"
|
||||
- "DECLARE_ASN1_FUNCTIONS_const"
|
||||
- "DECLARE_ASN1_FUNCTIONS_fname"
|
||||
- "DECLARE_ASN1_FUNCTIONS_name"
|
||||
- "DECLARE_PEM_read"
|
||||
- "DECLARE_PEM_read_bio"
|
||||
- "DECLARE_PEM_read_fp"
|
||||
- "DECLARE_PEM_rw"
|
||||
- "DECLARE_PEM_rw_cb"
|
||||
- "DECLARE_PEM_rw_const"
|
||||
- "DECLARE_PEM_write"
|
||||
- "DECLARE_PEM_write_bio"
|
||||
- "DECLARE_PEM_write_bio_const"
|
||||
- "DECLARE_PEM_write_cb"
|
||||
- "DECLARE_PEM_write_cb_bio"
|
||||
- "DECLARE_PEM_write_cb_fp"
|
||||
- "DECLARE_PEM_write_const"
|
||||
- "DECLARE_PEM_write_fp"
|
||||
- "DECLARE_PEM_write_fp_const"
|
||||
- "IMPLEMENT_ASN1_ALLOC_FUNCTIONS"
|
||||
- "IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname"
|
||||
- "IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname"
|
||||
- "IMPLEMENT_ASN1_DUP_FUNCTION"
|
||||
- "IMPLEMENT_ASN1_DUP_FUNCTION_const"
|
||||
- "IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname"
|
||||
- "IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname"
|
||||
- "IMPLEMENT_ASN1_FUNCTIONS"
|
||||
- "IMPLEMENT_ASN1_FUNCTIONS_const"
|
||||
- "IMPLEMENT_ASN1_FUNCTIONS_const_fname"
|
||||
- "IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name"
|
||||
- "IMPLEMENT_ASN1_FUNCTIONS_fname"
|
||||
- "IMPLEMENT_ASN1_FUNCTIONS_name"
|
||||
- "IMPLEMENT_ASN1_TYPE_ex"
|
||||
- "IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS"
|
||||
- "IMPLEMENT_PEM_read"
|
||||
- "IMPLEMENT_PEM_read_bio"
|
||||
- "IMPLEMENT_PEM_read_fp"
|
||||
- "IMPLEMENT_PEM_rw"
|
||||
- "IMPLEMENT_PEM_rw_cb"
|
||||
- "IMPLEMENT_PEM_rw_const"
|
||||
- "IMPLEMENT_PEM_write"
|
||||
- "IMPLEMENT_PEM_write_bio"
|
||||
- "IMPLEMENT_PEM_write_bio_const"
|
||||
- "IMPLEMENT_PEM_write_cb"
|
||||
- "IMPLEMENT_PEM_write_cb_bio"
|
||||
- "IMPLEMENT_PEM_write_cb_bio_const"
|
||||
- "IMPLEMENT_PEM_write_cb_const"
|
||||
- "IMPLEMENT_PEM_write_cb_fp"
|
||||
- "IMPLEMENT_PEM_write_cb_fp_const"
|
||||
- "IMPLEMENT_PEM_write_const"
|
||||
- "IMPLEMENT_PEM_write_fp"
|
||||
- "IMPLEMENT_PEM_write_fp_const"
|
||||
- "ASN1_ADB_END"
|
||||
- "ASN1_CHOICE_END"
|
||||
- "ASN1_CHOICE_END_cb"
|
||||
- "ASN1_ITEM_TEMPLATE_END"
|
||||
- "ASN1_SEQUENCE_END"
|
||||
- "ASN1_SEQUENCE_END_cb"
|
||||
- "ASN1_SEQUENCE_END_enc"
|
||||
- "ASN1_SEQUENCE_END_ref"
|
||||
# This isn't quite right, but it causes clang-format to do a slightly better
|
||||
# job with this macro.
|
||||
- "ASN1_EX_TEMPLATE_TYPE"
|
||||
40
src/.gitignore
vendored
40
src/.gitignore
vendored
@@ -1,40 +0,0 @@
|
||||
/bazel-*
|
||||
/build
|
||||
/build32
|
||||
/build64
|
||||
/ssl/test/runner/runner
|
||||
*.pyc
|
||||
*.swp
|
||||
*.swo
|
||||
/doc/*.html
|
||||
/doc/doc.css
|
||||
/rust/Cargo.lock
|
||||
/rust/bssl-crypto/Cargo.lock
|
||||
/rust/target
|
||||
/user.bazelrc
|
||||
|
||||
/util/bazel-example/bazel-*
|
||||
/util/bazel-example/MODULE.bazel.lock
|
||||
|
||||
/util/bot/android_ndk
|
||||
/util/bot/android_sdk/public
|
||||
/util/bot/cmake
|
||||
/util/bot/golang
|
||||
/util/bot/libFuzzer
|
||||
/util/bot/libcxx
|
||||
/util/bot/libcxxabi
|
||||
/util/bot/llvm-build
|
||||
/util/bot/llvm-libc
|
||||
/util/bot/nasm-win32.exe
|
||||
/util/bot/ninja
|
||||
/util/bot/perl-win32
|
||||
/util/bot/qemu-static
|
||||
/util/bot/sde-linux64
|
||||
/util/bot/sde-linux64.tar.xz
|
||||
/util/bot/sde-win32
|
||||
/util/bot/sde-win32.tar.xz
|
||||
/util/bot/tools
|
||||
/util/bot/windows_sdk
|
||||
|
||||
# Ignore target under any directory.
|
||||
target/
|
||||
@@ -1,324 +0,0 @@
|
||||
# BoringSSL API Conventions
|
||||
|
||||
This document describes conventions for BoringSSL APIs. The [style
|
||||
guide](./STYLE.md) also includes guidelines, but this document is targeted at
|
||||
both API consumers and developers. API documentation in BoringSSL may assume
|
||||
these conventions by default, rather than repeating them for every function.
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
All supported public APIs are documented in the public header files, found in
|
||||
`include/openssl`. The API documentation is also available
|
||||
[online](https://commondatastorage.googleapis.com/chromium-boringssl-docs/headers.html).
|
||||
|
||||
Experimental public APIs are found in `include/openssl/experimental`. Use of
|
||||
these will likely be incompatible with changes in the near future as they are
|
||||
finalized.
|
||||
|
||||
## Forward declarations
|
||||
|
||||
Do not write `typedef struct foo_st FOO` or try otherwise to define BoringSSL's
|
||||
types. Including `openssl/base.h` (or `openssl/ossl_typ.h` for consumers who
|
||||
wish to be OpenSSL-compatible) will forward-declare each type without importing
|
||||
the rest of the library or invasive macros.
|
||||
|
||||
|
||||
## Error-handling
|
||||
|
||||
Most functions in BoringSSL may fail, either due to allocation failures or input
|
||||
errors. Functions which return an `int` typically return one on success and zero
|
||||
on failure. Functions which return a pointer typically return `NULL` on failure.
|
||||
However, due to legacy constraints, some functions are more complex. Consult the
|
||||
API documentation before using a function.
|
||||
|
||||
On error, most functions also push errors on the error queue, an `errno`-like
|
||||
mechanism. See the documentation for
|
||||
[err.h](https://commondatastorage.googleapis.com/chromium-boringssl-docs/err.h.html)
|
||||
for more details.
|
||||
|
||||
As with `errno`, callers must test the function's return value, not the error
|
||||
queue to determine whether an operation failed. Some codepaths may not interact
|
||||
with the error queue, and the error queue may have state from a previous failed
|
||||
operation. After checking for failure, the caller can then inspect the error
|
||||
queue in the failure case for details.
|
||||
|
||||
As a notable exception, some functions in the SSL/TLS library use a multi-step
|
||||
process to indicate failure: First, the return value indicates whether the
|
||||
operation failed. Then, `SSL_get_error` indicates whether the failure was due to
|
||||
an error (`SSL_ERROR_SSL`) or some recoverable condition (e.g.
|
||||
`SSL_ERROR_WANT_READ`). In the former case, the caller can use the error queue
|
||||
for more information.
|
||||
|
||||
When ignoring a failed operation, it is recommended to call `ERR_clear_error` to
|
||||
avoid the state interacting with future operations. Failing to do so should not
|
||||
affect the actual behavior of any functions, but may result in errors from both
|
||||
operations being mixed in error logging. We hope to
|
||||
[improve](https://bugs.chromium.org/p/boringssl/issues/detail?id=38) this
|
||||
situation in the future.
|
||||
|
||||
Where possible, avoid conditioning on specific reason codes and limit usage to
|
||||
logging. The reason codes are very fine-grained and tend to leak details of the
|
||||
library's internal structure. Changes in the library often have a side effect of
|
||||
changing the exact reason code returned.
|
||||
|
||||
|
||||
## Memory allocation
|
||||
|
||||
BoringSSL allocates memory via `OPENSSL_malloc`, found in `mem.h`. Use
|
||||
`OPENSSL_free`, found in the same header file, to release it. BoringSSL
|
||||
functions will fail gracefully on allocation error, but it is recommended to use
|
||||
a `malloc` implementation that `abort`s on failure.
|
||||
|
||||
|
||||
## Pointers and slices
|
||||
|
||||
Unless otherwise specified, pointer parameters that refer to a single object,
|
||||
either as an input or output parameter, may not be `NULL`. In this case,
|
||||
BoringSSL often will not check for `NULL` before dereferencing, so passing
|
||||
`NULL` may crash or exhibit other undefined behavior. (Sometimes the function
|
||||
will check for `NULL` anyway, for OpenSSL compatibility, but we still consider
|
||||
passing `NULL` to be a caller error.)
|
||||
|
||||
Pointer parameters may also refer to a contiguous sequence of objects, sometimes
|
||||
referred to as a *slice*. These will typically be a pair of pointer and length
|
||||
parameters named like `plaintext` and `plaintext_len`, or `objs` and `num_objs`.
|
||||
We prefer the former for byte buffers and the latter for sequences of other
|
||||
types. The documentation will usually refer to both parameters together, e.g.
|
||||
"`EVP_DigestUpdate` hashes `len` bytes from `data`."
|
||||
|
||||
Parameters in C and C++ that use array syntax, such as
|
||||
`uint8_t out[SHA256_DIGEST_LENGTH]`, are really pointers. In BoringSSL's uses of
|
||||
this syntax, the pointer must point to the specified number of values.
|
||||
|
||||
In other cases, the documentation will describe how the function parameters
|
||||
determine the slice's length. For example, a slice's length may be measured in
|
||||
units other than element count, multiple slice parameters may share a length, or
|
||||
a slice's length may be implicitly determined by other means like RSA key size.
|
||||
|
||||
By default, BoringSSL follows C++'s
|
||||
[slice conventions](https://davidben.net/2024/01/15/empty-slices.html)
|
||||
for pointers. That is, unless otherwise specified, pointers for non-empty
|
||||
(non-zero length) slices must be represented by a valid pointer to that many
|
||||
objects in memory. Pointers for empty (zero length) slices must either be `NULL`
|
||||
or point within some sequence of objects of a compatible type.
|
||||
|
||||
WARNING: The dangling, non-null pointer used by Rust empty slices may *not* be
|
||||
passed into BoringSSL. Rust FFIs must adjust such pointers to before passing to
|
||||
BoringSSL. For example, see the `FfiSlice` abstraction in `bssl-crypto`. (We may
|
||||
relax this if pointer arithmetic rules in C/C++ are adjusted to permit Rust's
|
||||
pointers. Until then, it is impractical for a C/C++ library to act on such a
|
||||
slice representation. See
|
||||
[this document](https://davidben.net/2024/01/15/empty-slices.html) for more
|
||||
discussion.)
|
||||
|
||||
In some cases, OpenSSL compatibility requires that a function will treat `NULL`
|
||||
slice pointers differently from non-`NULL` pointers. Such behavior will be
|
||||
described in documentation. For examples, see `EVP_EncryptUpdate`,
|
||||
`EVP_DigestSignFinal`, and `HMAC_Init_ex`. Callers passing potentially empty
|
||||
slices into such functions should take care that the `NULL` case is either
|
||||
unreachable or still has the desired behavior.
|
||||
|
||||
If a `const char *` parameter is described as a "NUL-terminated string" or a
|
||||
"C string", it must point to a sequence of `char` values containing a NUL (zero)
|
||||
value, which determines the length. Unless otherwise specified, the pointer may
|
||||
not be `NULL`, matching the C standard library.
|
||||
|
||||
For purposes of C and C++'s
|
||||
[strict aliasing](https://en.cppreference.com/w/c/language/object#Strict_aliasing)
|
||||
requirements, objects passed by pointers must be accessible as the specified
|
||||
type. `uint8_t` may be assumed to be the same type as `unsigned char` and thus
|
||||
may be the pointer type for all object types. BoringSSL does not support
|
||||
platforms where `uint8_t` is a non-character type. However, there is no
|
||||
strict aliasing sanitizer, very few C and C++ codebases are valid by strict
|
||||
aliasing, and BoringSSL itself has some
|
||||
[known strict aliasing bugs](https://crbug.com/boringssl/444), thus we strongly
|
||||
recommend consumers build with `-fno-strict-aliasing`.
|
||||
|
||||
Pointer parameters additionally have ownership and lifetime requirements,
|
||||
discussed in the section below.
|
||||
|
||||
|
||||
## Object initialization and cleanup
|
||||
|
||||
BoringSSL defines a number of structs for use in its APIs. It is a C library,
|
||||
so the caller is responsible for ensuring these structs are properly
|
||||
initialized and released. Consult the documentation for a module for the
|
||||
proper use of its types. Some general conventions are listed below.
|
||||
|
||||
|
||||
### Heap-allocated types
|
||||
|
||||
Some types, such as `RSA`, are heap-allocated. All instances will be allocated
|
||||
and returned from BoringSSL's APIs. It is an error to instantiate a heap-
|
||||
allocated type on the stack or embedded within another object.
|
||||
|
||||
Heap-allocated types may have functioned named like `RSA_new` which allocates a
|
||||
fresh blank `RSA`. Other functions may also return newly-allocated instances.
|
||||
For example, `RSA_parse_public_key` is documented to return a newly-allocated
|
||||
`RSA` object.
|
||||
|
||||
Heap-allocated objects must be released by the corresponding free function,
|
||||
named like `RSA_free`. Like C's `free` and C++'s `delete`, all free functions
|
||||
internally check for `NULL`. It is redundant to check for `NULL` before calling.
|
||||
|
||||
A heap-allocated type may be reference-counted. In this case, a function named
|
||||
like `RSA_up_ref` will be available to take an additional reference count. The
|
||||
free function must be called to decrement the reference count. It will only
|
||||
release resources when the final reference is released. For OpenSSL
|
||||
compatibility, these functions return `int`, but callers may assume they always
|
||||
successfully return one because reference counts use saturating arithmetic.
|
||||
|
||||
C++ consumers are recommended to use `bssl::UniquePtr` to manage heap-allocated
|
||||
objects. `bssl::UniquePtr<T>`, like other types, is forward-declared in
|
||||
`openssl/base.h`. Code that needs access to the free functions, such as code
|
||||
which destroys a `bssl::UniquePtr`, must include the corresponding module's
|
||||
header. (This matches `std::unique_ptr`'s relationship with forward
|
||||
declarations.) Note, despite the name, `bssl::UniquePtr` is also used with
|
||||
reference-counted types. It owns a single reference to the object. To take an
|
||||
additional reference, use the `bssl::UpRef` function, which will return a
|
||||
separate `bssl::UniquePtr`.
|
||||
|
||||
|
||||
### Stack-allocated types
|
||||
|
||||
Other types in BoringSSL are stack-allocated, such as `EVP_MD_CTX`. These
|
||||
types may be allocated on the stack or embedded within another object.
|
||||
However, they must still be initialized before use.
|
||||
|
||||
Every stack-allocated object in BoringSSL has a *zero state*, analogous to
|
||||
initializing a pointer to `NULL`. In this state, the object may not be
|
||||
completely initialized, but it is safe to call cleanup functions. Entering the
|
||||
zero state cannot fail. (It is usually `memset(0)`.)
|
||||
|
||||
The function to enter the zero state is named like `EVP_MD_CTX_init` or
|
||||
`CBB_zero` and will always return `void`. To release resources associated with
|
||||
the type, call the cleanup function, named like `EVP_MD_CTX_cleanup`. The
|
||||
cleanup function must be called on all codepaths, regardless of success or
|
||||
failure. For example:
|
||||
|
||||
uint8_t md[EVP_MAX_MD_SIZE];
|
||||
unsigned md_len;
|
||||
EVP_MD_CTX ctx;
|
||||
EVP_MD_CTX_init(&ctx); /* Enter the zero state. */
|
||||
int ok = EVP_DigestInit_ex(&ctx, EVP_sha256(), NULL) &&
|
||||
EVP_DigestUpdate(&ctx, "hello ", 6) &&
|
||||
EVP_DigestUpdate(&ctx, "world", 5) &&
|
||||
EVP_DigestFinal_ex(&ctx, md, &md_len);
|
||||
EVP_MD_CTX_cleanup(&ctx); /* Release |ctx|. */
|
||||
|
||||
Note that `EVP_MD_CTX_cleanup` is called whether or not the `EVP_Digest*`
|
||||
operations succeeded. More complex C functions may use the `goto err` pattern:
|
||||
|
||||
int ret = 0;
|
||||
EVP_MD_CTX ctx;
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
|
||||
if (!some_other_operation()) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
uint8_t md[EVP_MAX_MD_SIZE];
|
||||
unsigned md_len;
|
||||
if (!EVP_DigestInit_ex(&ctx, EVP_sha256(), NULL) ||
|
||||
!EVP_DigestUpdate(&ctx, "hello ", 6) ||
|
||||
!EVP_DigestUpdate(&ctx, "world", 5) ||
|
||||
!EVP_DigestFinal_ex(&ctx, md, &md_len) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return ret;
|
||||
|
||||
Note that, because `ctx` is set to the zero state before any failures,
|
||||
`EVP_MD_CTX_cleanup` is safe to call even if the first operation fails before
|
||||
`EVP_DigestInit_ex`. However, it would be illegal to move the `EVP_MD_CTX_init`
|
||||
below the `some_other_operation` call.
|
||||
|
||||
As a rule of thumb, enter the zero state of stack-allocated structs in the
|
||||
same place they are declared.
|
||||
|
||||
C++ consumers are recommended to use the wrappers named like
|
||||
`bssl::ScopedEVP_MD_CTX`, defined in the corresponding module's header. These
|
||||
wrappers are automatically initialized to the zero state and are automatically
|
||||
cleaned up.
|
||||
|
||||
|
||||
### Data-only types
|
||||
|
||||
A few types, such as `SHA_CTX`, are data-only types and do not require cleanup.
|
||||
These are usually for low-level cryptographic operations. These types may be
|
||||
used freely without special cleanup conventions.
|
||||
|
||||
|
||||
### Ownership and lifetime
|
||||
|
||||
When working with allocated objects, it is important to think about *ownership*
|
||||
of each object, or what code is responsible for releasing it. This matches the
|
||||
corresponding notion in higher-level languages like C++ and Rust.
|
||||
|
||||
Ownership applies to both uniquely-owned types and reference-counted types. For
|
||||
the latter, ownership means the code is responsible for releasing one
|
||||
reference. Note a *reference* in BoringSSL refers to an increment (and eventual
|
||||
decrement) of an object's reference count, not `T&` in C++. Thus, to "take a
|
||||
reference" means to increment the reference count and take ownership of
|
||||
decrementing it.
|
||||
|
||||
As BoringSSL's APIs are primarily in C, ownership and lifetime obligations are
|
||||
not rigorously annotated in the type signatures or checked at compile-time.
|
||||
Instead, they are described in
|
||||
[API documentation](https://commondatastorage.googleapis.com/chromium-boringssl-docs/headers.html).
|
||||
This section describes some conventions.
|
||||
|
||||
Unless otherwise documented, functions do not take ownership of pointer
|
||||
arguments. The pointer typically must remain valid for the duration of the
|
||||
function call. The function may internally copy information from the argument or
|
||||
take a reference, but the caller is free to release its copy or reference at any
|
||||
point after the call completes.
|
||||
|
||||
A function may instead be documented to *take* or *transfer* ownership of a
|
||||
pointer. The caller must own the object before the function call and, after
|
||||
transfer, no longer owns it. As a corollary, the caller may no longer reference
|
||||
the object without a separate guarantee on the lifetime. The function may even
|
||||
release the object before returning. Callers that wish to independently retain a
|
||||
transfered object must therefore take a reference or make a copy before
|
||||
transferring. Callers should also take note of whether the function is
|
||||
documented to transfer pointers unconditionally or only on success. Unlike C++
|
||||
and Rust, functions in BoringSSL typically only transfer on success.
|
||||
|
||||
Likewise, output pointers may be owning or non-owning. Unless otherwise
|
||||
documented, functions output non-owning pointers. The caller is not responsible
|
||||
for releasing the output pointer, but it must not use the pointer beyond its
|
||||
lifetime. The pointer may be released when the parent object is released or even
|
||||
sooner on state change in the parent object.
|
||||
|
||||
If documented to output a *newly-allocated* object or a *reference* or *copy* of
|
||||
one, the caller is responsible for releasing the object when it is done.
|
||||
|
||||
By convention, functions named `get0` return non-owning pointers. Functions
|
||||
named `new` or `get1` return owning pointers. Functions named `set0` take
|
||||
ownership of arguments. Functions named `set1` do not. They typically take a
|
||||
reference or make a copy internally. These names originally referred to the
|
||||
effect on a reference count, but the convention applies equally to
|
||||
non-reference-counted types.
|
||||
|
||||
API documentation may also describe more complex obligations. For instance, an
|
||||
object may borrow a pointer for longer than the duration of a single function
|
||||
call, in which case the caller must ensure the lifetime extends accordingly.
|
||||
|
||||
Memory errors are one of the most common and dangerous bugs in C and C++, so
|
||||
callers are encouraged to make use of tools such as
|
||||
[AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html) and
|
||||
higher-level languages.
|
||||
|
||||
|
||||
## Thread safety
|
||||
|
||||
BoringSSL is internally aware of the platform threading library and calls into
|
||||
it as needed. Consult the API documentation for the threading guarantees of
|
||||
particular objects. In general, stateless reference-counted objects like `RSA`
|
||||
or `EVP_PKEY` which represent keys may typically be used from multiple threads
|
||||
simultaneously, provided no thread mutates the key.
|
||||
50
src/AUTHORS
50
src/AUTHORS
@@ -1,50 +0,0 @@
|
||||
# This is the list of BoringSSL's significant contributors.
|
||||
#
|
||||
# This does not necessarily list everyone who has contributed code,
|
||||
# especially since many employees of one corporation may be contributing.
|
||||
# To see the full list of contributors, see the revision history in
|
||||
# source control.
|
||||
Google LLC
|
||||
Brian Smith
|
||||
Apple Inc
|
||||
|
||||
# Additionally, much of the code in BoringSSL is derived from code in the
|
||||
# OpenSSL project. We thank the OpenSSL project’s contributors for their
|
||||
# work. Some of these contributors are listed below. For the full list of
|
||||
# these contributors, see AUTHORS.md in OpenSSL and the revision history
|
||||
# in OpenSSL’s source control.
|
||||
OpenSSL Software Services, Inc.
|
||||
OpenSSL Software Foundation, Inc.
|
||||
Andy Polyakov
|
||||
Ben Laurie
|
||||
Ben Kaduk
|
||||
Bernd Edlinger
|
||||
Bodo Möller
|
||||
David Benjamin
|
||||
David von Oheimb
|
||||
Dmitry Belyavskiy (Дмитрий Белявский)
|
||||
Emilia Käsper
|
||||
Eric Young
|
||||
Geoff Thorpe
|
||||
Holger Reif
|
||||
Kurt Roeckx
|
||||
Lutz Jänicke
|
||||
Mark J. Cox
|
||||
Matt Caswell
|
||||
Matthias St. Pierre
|
||||
Nicola Tuveri
|
||||
Nils Larsch
|
||||
Patrick Steuer
|
||||
Paul Dale
|
||||
Paul C. Sutton
|
||||
Paul Yang
|
||||
Ralf S. Engelschall
|
||||
Rich Salz
|
||||
Richard Levitte
|
||||
Shane Lontis
|
||||
Stephen Henson
|
||||
Steve Marquess
|
||||
Tim Hudson
|
||||
Tomáš Mráz
|
||||
Ulf Möller
|
||||
Viktor Dukhovni
|
||||
@@ -1,88 +0,0 @@
|
||||
# How to change BoringSSL's API
|
||||
|
||||
BoringSSL has more flexibility in changing things than many other library projects because we have a reasonable idea of who our users are. Still, breaking changes require some care. We depend on tight feedback loops with our consumers so that we can learn about mistakes and fix them. For that to work, updating BoringSSL must be smooth.
|
||||
|
||||
Ultimately, the strategy for each breaking change is decided on a case-by-case basis. This document provides guidelines and techniques to help with a smooth transition.
|
||||
|
||||
## Breakage risk
|
||||
|
||||
Traditionally, breaking changes are defined in terms of API or ABI surface. Exposed symbols and type signatures cannot change, etc. But this is a poor approximation of the true impact. Removing an API may not a breaking change if no one is using it. Conversely, [Hyrum's Law](http://www.hyrumslaw.com/) applies. Fixing a bug may be a breaking change for some consumer which was depending on that bug.
|
||||
|
||||
Thus, we do not think about whether a change is formally a breaking change, but about the *risk* of it breaking someone.
|
||||
|
||||
Some changes, such as internal cleanups or bug-fixes, are low risk and do not need special measures. Any problems can be handled when the affected consumer updates BoringSSL and notices.
|
||||
|
||||
Other changes, such as removing an API, forbidding some edge case, or adjusting some behavior, are more likely to break things. To help the consumer triage any resulting failures, include some text in the commit message, prefixed by `Update-Note: `. This can include what this change may break and instructions on how to fix the issue.
|
||||
|
||||
## Code Search
|
||||
|
||||
The vast majority of BoringSSL consumers are conveniently indexed in various Code Search instances. This can predict the impact of a risky change and identify code to fix ahead of time. The document “How to Code Search” in the (Google-only) [go/boringssl-folder](https://goto.google.com/boringssl-folder) includes notes on this.
|
||||
|
||||
## Evaluate a change's cost
|
||||
|
||||
If some change has high cost (from having to fix consumers) and relatively little benefit to BoringSSL, it may not be worth the trouble. For instance, it is likely not worth removing a small compatibility function in the corner of the library that is easily dropped by the static linker.
|
||||
|
||||
Conversely, a change that leads to a major improvement to all BoringSSL consumers, at the cost of fixing one or two consumers, is typically worth it.
|
||||
|
||||
## Fixing consumers
|
||||
|
||||
If code search reveals call sites that are definitely going to break, prefer to handle these before making the change. While unexpected breakage is always possible, we generally consider it the responsibility of the developer or group making a change to handle impact of that change. Teams are generally unhappy to be surprised by new migration work but happy to have migration work done for them.
|
||||
|
||||
In most cases, this is straightforward:
|
||||
|
||||
1. Add the replacement API.
|
||||
2. As the replacement API enters each consuming repository, migrate callers to it.
|
||||
3. Remove the original API once all consumers have been migrated.
|
||||
|
||||
The removal should still include an `Update-Note` tag, in case some were missed.
|
||||
|
||||
In some cases, this kind of staged approach is not feasible: perhaps the same code cannot simultaneously work before and after the change, or perhaps there are too many different versions in play. For instance, [Conscrypt](https://github.com/google/conscrypt) feeds into three different repositories. The GitHub repository consumes BoringSSL's `main` branch directly. It is pushed into Android, where it consumes Android's `external/boringssl`. Yet another copy is pushed into the internal repository, where it consumes that copy of BoringSSL. As each of these Conscrypts are updated independently from their corresponding BoringSSLs, Conscrypt upstream cannot rely on a new BoringSSL API until it is present in all copies of BoringSSL its downstreams rely on.
|
||||
|
||||
In that case, a multi-sided change may be more appropriate:
|
||||
|
||||
1. Upload the breaking change to Gerrit, but do not submit it yet. Increment the `BORINGSSL_API_VERSION` symbol.
|
||||
2. Update the consuming repository with `#if BORINGSSL_API_VERSION < N` preprocessor logic. Leave a comment to remove this later, linking to your BoringSSL change.
|
||||
3. When the `BORINGSSL_API_VERSION` check has propagated to relevant copies of the consuming repository, submit the BoringSSL change.
|
||||
4. When the BoringSSL change has propagated to relevant copies of BoringSSL, remove the staging logic from the consumer.
|
||||
|
||||
Finally, in some cases, the consumer's change may be committed atomically with the BoringSSL update. This can only be done for code which only consumes one instance of BoringSSL (so the Conscrypt example above is not eligible). Check with that project's maintainer first or, better, be that project's maintainer.
|
||||
|
||||
If more complex changes are needed in some consumer, communicate with the relevant maintainers to plan the transition.
|
||||
|
||||
## Fail early, fail closed
|
||||
|
||||
When breaking changes do occur, they should fail as early and as detectably as possible.
|
||||
|
||||
Ideally, problematic consumers fail to compile. Prefer to remove functions completely over leaving an always failing stub function. Sometimes this is not possible due to other consumers, particularly bindings libraries. Alternatively, if a stub function can be reasonably justified as still satisfying the API constraints, consider adding one to improve compatibility. For example, BoringSSL has many no-op stubs corresponding to OpenSSL's many initialization functions.
|
||||
|
||||
If some parameter now must be `NULL`, change the type to an opaque struct pointer. Consumers passing non-`NULL` pointers will then fail to compile.
|
||||
|
||||
If breaking the compile is not feasible, break at runtime, in the hope that consumers have some amount of test coverage. When doing so, try to fail on the common case. In particular, do not rely on consumers adequately testing or even checking for failure cases. One strategy is to bring the object into a “poison” state: if an illegal operation occurs, set a flag to fail all subsequent ones.
|
||||
|
||||
In other functions, it may be appropriate to simply call `abort()`.
|
||||
|
||||
## Unexpected breakage
|
||||
|
||||
While we try to avoid breaking things, sometimes things unexpectedly break. Depending on the impact, we may fix the consumer, make a small fix to BoringSSL, or revert the change to either try again later or revise the approach.
|
||||
|
||||
If we do not ultimately fix the consumer, add a test in BoringSSL to capture the unexpected API contract, so future regressions are caught quickly.
|
||||
|
||||
## Canary changes and bake time
|
||||
|
||||
When planning a large project that depends on a breaking change, prefer to make the breaking change first—before committing larger changes. Or, when changing toolchain or language requirements, add a small instance of the dependency somewhere first then wait a couple of weeks for the change to appear in consumers. This ensures that reverting the change is still feasible if necessary.
|
||||
|
||||
While we rely on a tight feedback loop with our consumers, there are a few consumers which update less frequently. For extremely risky changes, such as introducing C++ to a target, it may be prudent to wait much longer.
|
||||
|
||||
## Third-party code
|
||||
|
||||
In many cases, we are interested in changing behavior which came from OpenSSL. OpenSSL's API surface is huge, but only a small subset is actually used. So we can and occasionally do change these behaviors. This is more complex than changing BoringSSL-only behavior due to third-party code.
|
||||
|
||||
We use BoringSSL with many third-party projects that normally use OpenSSL. Generally, we consider this our burden to make this work and do not encourage external projects to depend on BoringSSL. While we can and do maintain patches for this as necessary, it has overhead and so the cost of breaking third-party code is higher.
|
||||
|
||||
We lean fairly strongly towards making changes to BoringSSL over patching third-party code, unless the third-party change fixes a security problem.
|
||||
|
||||
Additionally, changing an OpenSSL API will not only affect third-party code we use today, but also any third-party code we use in the future. Thus Code Search is less useful as an absolute predictor, and the various other considerations in this document are more important.
|
||||
|
||||
If the patch to support a BoringSSL change can be generally useful to the third-party project, send it upstream. For instance, it may use the APIs better, clean up code, or help support newer versions of OpenSSL. In general, we try to target compatibility with “most” “well-behaved” OpenSSL consumers.
|
||||
|
||||
Finally, if some particular OpenSSL API or pattern is problematic to BoringSSL, it is likely problematic to OpenSSL too. Consider filing a bug with them to suggest a change, either in new code going forward or for the next API break. OpenSSL's release cycles and feedback loops are much longer than BoringSSL's, so this is usually not immediately useful, but it keeps the ecosystem moving in the right direction.
|
||||
201
src/BUILD.bazel
201
src/BUILD.bazel
@@ -1,201 +0,0 @@
|
||||
# Copyright 2024 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
load("@rules_license//rules:license.bzl", "license")
|
||||
load(
|
||||
":gen/sources.bzl",
|
||||
"bcm_internal_headers",
|
||||
"bcm_sources",
|
||||
"bcm_sources_asm",
|
||||
"bssl_internal_headers",
|
||||
"bssl_sources",
|
||||
"crypto_headers",
|
||||
"crypto_internal_headers",
|
||||
"crypto_sources",
|
||||
"crypto_sources_asm",
|
||||
"crypto_test_data",
|
||||
"crypto_test_sources",
|
||||
"decrepit_internal_headers",
|
||||
"decrepit_sources",
|
||||
"decrepit_test_sources",
|
||||
"pki_headers",
|
||||
"pki_internal_headers",
|
||||
"pki_sources",
|
||||
"pki_test_data",
|
||||
"pki_test_sources",
|
||||
"ssl_headers",
|
||||
"ssl_internal_headers",
|
||||
"ssl_sources",
|
||||
"ssl_test_sources",
|
||||
"test_support_internal_headers",
|
||||
"test_support_sources",
|
||||
"test_support_sources_asm",
|
||||
"urandom_test_sources",
|
||||
)
|
||||
load(":util/util.bzl", "bssl_cc_binary", "bssl_cc_library", "bssl_cc_test")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = [":license"],
|
||||
# Disable the parse_headers feature. It does not work well in C right now.
|
||||
# See https://github.com/bazelbuild/bazel/issues/23460 for details. When
|
||||
# that is fixed, if enabled, we likely also need to rename some headers to
|
||||
# .inc per
|
||||
# https://google.github.io/styleguide/cppguide.html#Self_contained_Headers
|
||||
features = ["-parse_headers"],
|
||||
)
|
||||
|
||||
license(
|
||||
name = "license",
|
||||
package_name = "BoringSSL",
|
||||
license_kinds = [
|
||||
"@rules_license//licenses/spdx:Apache-2.0",
|
||||
],
|
||||
license_text = "LICENSE",
|
||||
)
|
||||
|
||||
exports_files(["LICENSE"])
|
||||
|
||||
bssl_cc_library(
|
||||
name = "crypto",
|
||||
srcs = bcm_sources + crypto_sources,
|
||||
hdrs = crypto_headers,
|
||||
asm_srcs = bcm_sources_asm + crypto_sources_asm,
|
||||
copts = ["-DBORINGSSL_IMPLEMENTATION"],
|
||||
includes = ["include"],
|
||||
internal_hdrs = bcm_internal_headers + crypto_internal_headers,
|
||||
linkopts = select({
|
||||
"@platforms//os:windows": [
|
||||
"-defaultlib:advapi32.lib",
|
||||
"-defaultlib:ws2_32.lib",
|
||||
],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
bssl_cc_library(
|
||||
name = "ssl",
|
||||
srcs = ssl_sources,
|
||||
hdrs = ssl_headers,
|
||||
copts = ["-DBORINGSSL_IMPLEMENTATION"],
|
||||
internal_hdrs = ssl_internal_headers,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":crypto_internal"],
|
||||
)
|
||||
|
||||
bssl_cc_library(
|
||||
name = "test_support",
|
||||
testonly = True,
|
||||
srcs = test_support_sources,
|
||||
asm_srcs = test_support_sources_asm,
|
||||
copts = ["-DBORINGSSL_USE_BAZEL_RUNFILES"],
|
||||
internal_hdrs = test_support_internal_headers,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
"@bazel_tools//tools/cpp/runfiles",
|
||||
"@googletest//:gtest",
|
||||
],
|
||||
)
|
||||
|
||||
bssl_cc_test(
|
||||
name = "crypto_test",
|
||||
size = "large",
|
||||
srcs = crypto_test_sources,
|
||||
data = crypto_test_data,
|
||||
# crypto_test references assembly symbols directly and thus must be linked
|
||||
# statically.
|
||||
linkstatic = True,
|
||||
shard_count = 32,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":test_support",
|
||||
"@googletest//:gtest",
|
||||
],
|
||||
)
|
||||
|
||||
bssl_cc_test(
|
||||
name = "urandom_test",
|
||||
srcs = urandom_test_sources,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":test_support",
|
||||
"@googletest//:gtest",
|
||||
],
|
||||
)
|
||||
|
||||
bssl_cc_test(
|
||||
name = "ssl_test",
|
||||
srcs = ssl_test_sources,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":ssl_internal",
|
||||
":test_support",
|
||||
"@googletest//:gtest",
|
||||
],
|
||||
)
|
||||
|
||||
bssl_cc_binary(
|
||||
name = "bssl",
|
||||
srcs = bssl_sources + bssl_internal_headers,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":ssl_internal",
|
||||
],
|
||||
)
|
||||
|
||||
# Build, but do not export libdecrepit.
|
||||
bssl_cc_library(
|
||||
name = "decrepit",
|
||||
srcs = decrepit_sources,
|
||||
copts = ["-DBORINGSSL_IMPLEMENTATION"],
|
||||
internal_hdrs = decrepit_internal_headers,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":ssl_internal",
|
||||
],
|
||||
)
|
||||
|
||||
bssl_cc_test(
|
||||
name = "decrepit_test",
|
||||
srcs = decrepit_test_sources,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":decrepit",
|
||||
":test_support",
|
||||
"@googletest//:gtest",
|
||||
],
|
||||
)
|
||||
|
||||
# Build, but do not (yet) export libpki.
|
||||
bssl_cc_library(
|
||||
name = "pki",
|
||||
srcs = pki_sources,
|
||||
hdrs = pki_headers,
|
||||
copts = ["-DBORINGSSL_IMPLEMENTATION"],
|
||||
internal_hdrs = pki_internal_headers,
|
||||
deps = [":crypto"],
|
||||
)
|
||||
|
||||
bssl_cc_test(
|
||||
name = "pki_test",
|
||||
srcs = pki_test_sources,
|
||||
data = pki_test_data,
|
||||
deps = [
|
||||
":crypto_internal",
|
||||
":pki",
|
||||
":test_support",
|
||||
"@googletest//:gtest",
|
||||
],
|
||||
)
|
||||
221
src/BUILDING.md
221
src/BUILDING.md
@@ -1,221 +0,0 @@
|
||||
# Building BoringSSL
|
||||
|
||||
## Checking out BoringSSL
|
||||
|
||||
git clone "https://boringssl.googlesource.com/boringssl"
|
||||
|
||||
## Build Prerequisites
|
||||
|
||||
The standalone CMake build is primarily intended for developers. If embedding
|
||||
BoringSSL into another project with a pre-existing build system, see
|
||||
[INCORPORATING.md](./INCORPORATING.md).
|
||||
|
||||
Unless otherwise noted, build tools must at most five years old, matching
|
||||
[Abseil guidelines](https://abseil.io/about/compatibility). If in doubt, use the
|
||||
most recent stable version of each tool.
|
||||
|
||||
* [CMake](https://cmake.org/download/) 3.12 or later is required.
|
||||
|
||||
* Building with [Ninja](https://ninja-build.org/) instead of Make is
|
||||
recommended, because it makes builds faster. On Windows, CMake's Visual
|
||||
Studio generator may also work, but it not tested regularly and requires
|
||||
recent versions of CMake for assembly support.
|
||||
|
||||
* On Windows only, [NASM](https://www.nasm.us/) is required. If not found
|
||||
by CMake, it may be configured explicitly by setting
|
||||
`CMAKE_ASM_NASM_COMPILER`.
|
||||
|
||||
* Compilers for C11 and C++17, or later, are required. On Windows, MSVC from
|
||||
Visual Studio 2022 or later with Windows 10 SDK 2104 or later are
|
||||
supported, but using the latest versions is recommended. Recent versions of
|
||||
GCC (6.1+) and Clang should work on non-Windows platforms, and maybe on
|
||||
Windows too.
|
||||
|
||||
## Building
|
||||
|
||||
Using Ninja (note the 'N' is capitalized in the cmake invocation):
|
||||
|
||||
cmake -GNinja -B build
|
||||
ninja -C build
|
||||
|
||||
Using Make (does not work on Windows):
|
||||
|
||||
cmake -B build
|
||||
make -C build
|
||||
|
||||
This produces a debug build by default. Optimisation isn't enabled, and debug
|
||||
assertions are included. Pass `-DCMAKE_BUILD_TYPE=Release` to `cmake` to
|
||||
configure a release build:
|
||||
|
||||
cmake -GNinja -B build -DCMAKE_BUILD_TYPE=Release
|
||||
ninja -C build
|
||||
|
||||
If you want to cross-compile then there is an example toolchain file for 32-bit
|
||||
Intel in `util/`. Wipe out the build directory, run `cmake` like this:
|
||||
|
||||
cmake -B build -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja
|
||||
|
||||
If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On
|
||||
Windows, where functions need to be tagged with `dllimport` when coming from a
|
||||
shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s
|
||||
the BoringSSL headers.
|
||||
|
||||
In order to serve environments where code-size is important as well as those
|
||||
where performance is the overriding concern, `OPENSSL_SMALL` can be defined to
|
||||
remove some code that is especially large.
|
||||
|
||||
See [CMake's documentation](https://cmake.org/cmake/help/v3.4/manual/cmake-variables.7.html)
|
||||
for other variables which may be used to configure the build.
|
||||
|
||||
You usually don't need to run `cmake` again after changing `CMakeLists.txt`
|
||||
files because the build scripts will detect changes to them and rebuild
|
||||
themselves automatically.
|
||||
|
||||
### Building for Android
|
||||
|
||||
It's possible to build BoringSSL with the Android NDK using CMake. Recent
|
||||
versions of the NDK include a CMake toolchain file which works with CMake 3.6.0
|
||||
or later. This has been tested with version r16b of the NDK.
|
||||
|
||||
Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the
|
||||
directory. Then run CMake like this:
|
||||
|
||||
cmake -DANDROID_ABI=armeabi-v7a \
|
||||
-DANDROID_PLATFORM=android-19 \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
|
||||
-GNinja -B build
|
||||
|
||||
Once you've run that, Ninja should produce Android-compatible binaries. You
|
||||
can replace `armeabi-v7a` in the above with `arm64-v8a` and use API level 21 or
|
||||
higher to build aarch64 binaries.
|
||||
|
||||
For other options, see the documentation in the toolchain file.
|
||||
|
||||
To debug the resulting binaries on an Android device with `gdb`, run the
|
||||
commands below. Replace `ARCH` with the architecture of the target device, e.g.
|
||||
`arm` or `arm64`.
|
||||
|
||||
adb push ${ANDROID_NDK}/prebuilt/android-ARCH/gdbserver/gdbserver \
|
||||
/data/local/tmp
|
||||
adb forward tcp:5039 tcp:5039
|
||||
adb shell /data/local/tmp/gdbserver :5039 /path/on/device/to/binary
|
||||
|
||||
Then run the following in a separate shell. Replace `HOST` with the OS and
|
||||
architecture of the host machine, e.g. `linux-x86_64`.
|
||||
|
||||
${ANDROID_NDK}/prebuilt/HOST/bin/gdb
|
||||
target remote :5039 # in gdb
|
||||
|
||||
### Building for iOS
|
||||
|
||||
To build for iOS, pass `-DCMAKE_OSX_SYSROOT=iphoneos` and
|
||||
`-DCMAKE_OSX_ARCHITECTURES=ARCH` to CMake, where `ARCH` is the desired
|
||||
architecture, matching values used in the `-arch` flag in Apple's toolchain.
|
||||
|
||||
Passing multiple architectures for a multiple-architecture build is not
|
||||
supported.
|
||||
|
||||
### Building with Prefixed Symbols
|
||||
|
||||
BoringSSL's build system has experimental support for adding a custom prefix to
|
||||
all symbols. This can be useful when linking multiple versions of BoringSSL in
|
||||
the same project to avoid symbol conflicts. Symbol prefixing requires the most
|
||||
recent stable version of [Go](https://go.dev/).
|
||||
|
||||
In order to build with prefixed symbols, the `BORINGSSL_PREFIX` CMake variable
|
||||
should specify the prefix to add to all symbols, and the
|
||||
`BORINGSSL_PREFIX_SYMBOLS` CMake variable should specify the path to a file
|
||||
which contains a list of symbols which should be prefixed (one per line;
|
||||
comments are supported with `#`). In other words, `cmake -B build
|
||||
-DBORINGSSL_PREFIX=MY_CUSTOM_PREFIX
|
||||
-DBORINGSSL_PREFIX_SYMBOLS=/path/to/symbols.txt` will configure the build to add
|
||||
the prefix `MY_CUSTOM_PREFIX` to all of the symbols listed in
|
||||
`/path/to/symbols.txt`.
|
||||
|
||||
It is currently the caller's responsibility to create and maintain the list of
|
||||
symbols to be prefixed. Alternatively, `util/read_symbols.go` reads the list of
|
||||
exported symbols from a `.a` file, and can be used in a build script to generate
|
||||
the symbol list on the fly (by building without prefixing, using
|
||||
`read_symbols.go` to construct a symbol list, and then building again with
|
||||
prefixing).
|
||||
|
||||
This mechanism is under development and may change over time. Please contact the
|
||||
BoringSSL maintainers if making use of it.
|
||||
|
||||
## Known Limitations on Windows
|
||||
|
||||
* CMake can generate Visual Studio projects, but the generated project files
|
||||
don't have steps for assembling the assembly language source files, so they
|
||||
currently cannot be used to build BoringSSL.
|
||||
|
||||
## ARM CPU Capabilities
|
||||
|
||||
ARM, unlike Intel, does not have a userspace instruction that allows
|
||||
applications to discover the capabilities of the processor. Instead, the
|
||||
capability information has to be provided by a combination of compile-time
|
||||
information and the operating system.
|
||||
|
||||
BoringSSL determines capabilities at compile-time based on `__ARM_NEON`,
|
||||
`__ARM_FEATURE_AES`, and other preprocessor symbols defined in
|
||||
[Arm C Language Extensions (ACLE)](https://developer.arm.com/architectures/system-architectures/software-standards/acle).
|
||||
These values are usually controlled by the `-march` flag. You can also define
|
||||
any of the following to enable the corresponding ARM feature, but using the ACLE
|
||||
symbols via `-march` is recommended.
|
||||
|
||||
* `OPENSSL_STATIC_ARMCAP_NEON`
|
||||
* `OPENSSL_STATIC_ARMCAP_AES`
|
||||
* `OPENSSL_STATIC_ARMCAP_SHA1`
|
||||
* `OPENSSL_STATIC_ARMCAP_SHA256`
|
||||
* `OPENSSL_STATIC_ARMCAP_PMULL`
|
||||
|
||||
The resulting binary will assume all such features are always present. This can
|
||||
reduce code size, by allowing the compiler to omit fallbacks. However, if the
|
||||
feature is not actually supported at runtime, BoringSSL will likely crash.
|
||||
|
||||
BoringSSL will additionally query the operating system at runtime for additional
|
||||
features, e.g. with `getauxval` on Linux. This allows a single binary to use
|
||||
newer instructions when present, but still function on CPUs without them. But
|
||||
some environments don't support runtime queries. If building for those, define
|
||||
`OPENSSL_STATIC_ARMCAP` to limit BoringSSL to compile-time capabilities. If not
|
||||
defined, the target operating system must be known to BoringSSL.
|
||||
|
||||
## Binary Size
|
||||
|
||||
The implementations of some algorithms require a trade-off between binary size
|
||||
and performance. For instance, BoringSSL's fastest P-256 implementation uses a
|
||||
148 KiB pre-computed table. To optimize instead for binary size, pass
|
||||
`-DOPENSSL_SMALL=1` to CMake or define the `OPENSSL_SMALL` preprocessor symbol.
|
||||
|
||||
# Running Tests
|
||||
|
||||
There are two additional dependencies for running tests:
|
||||
|
||||
* The most recent stable version of [Go](https://go.dev/) is required.
|
||||
Note Go is exempt from the five year support window. If not found by CMake,
|
||||
the go executable may be configured explicitly by setting `GO_EXECUTABLE`.
|
||||
|
||||
* On x86_64 Linux, the tests have an optional
|
||||
[libunwind](https://www.nongnu.org/libunwind/) dependency to test the
|
||||
assembly more thoroughly.
|
||||
|
||||
There are two sets of tests: the C/C++ tests and the blackbox tests. For former
|
||||
are built by Ninja and can be run from the top-level directory with `go run
|
||||
util/all_tests.go`. The latter have to be run separately by running `go test`
|
||||
from within `ssl/test/runner`.
|
||||
|
||||
Both sets of tests may also be run with `ninja -C build run_tests`, but CMake
|
||||
3.2 or later is required to avoid Ninja's output buffering.
|
||||
|
||||
# Pre-generated Files
|
||||
|
||||
If modifying perlasm files, or `util/pregenerate/build.json`, you will need to
|
||||
run `go run ./util/pregenerate` to refresh some pre-generated files. To do this,
|
||||
you will need a recent version of Perl.
|
||||
|
||||
On Windows, [Active State Perl](http://www.activestate.com/activeperl/) has been
|
||||
reported to work, as has MSYS Perl.
|
||||
[Strawberry Perl](http://strawberryperl.com/) also works but it adds GCC
|
||||
to `PATH`, which can confuse some build tools when identifying the compiler
|
||||
(removing `C:\Strawberry\c\bin` from `PATH` should resolve any problems).
|
||||
|
||||
See (gen/README.md)[./gen/README.md] for more details.
|
||||
@@ -1,811 +0,0 @@
|
||||
# Copyright 2014 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Defer enabling C and CXX languages.
|
||||
project(BoringSSL NONE)
|
||||
|
||||
# Don't install BoringSSL to system directories by default; it has no stable
|
||||
# ABI. Instead, default to an "install" directory under the source.
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install CACHE PATH "" FORCE)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# On Windows, prefer cl over gcc if both are available. By default most of
|
||||
# the CMake generators prefer gcc, even on Windows.
|
||||
set(CMAKE_GENERATOR_CC cl)
|
||||
endif()
|
||||
|
||||
include(cmake/go.cmake)
|
||||
include(cmake/paths.cmake)
|
||||
include(gen/sources.cmake)
|
||||
|
||||
enable_language(C)
|
||||
enable_language(CXX)
|
||||
|
||||
# TODO(crbug,com/389897612): Register tests with CTest. For now, we include this
|
||||
# only to pick up the standard |BUILD_TESTING| option.
|
||||
include(CTest)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(INSTALL_ENABLED 1)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_CROSSCOMPILING)
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PkgConfig_FOUND)
|
||||
pkg_check_modules(LIBUNWIND libunwind-generic>=1.3.0)
|
||||
if(LIBUNWIND_FOUND)
|
||||
add_definitions(-DBORINGSSL_HAVE_LIBUNWIND)
|
||||
else()
|
||||
message("libunwind not found. Disabling unwind tests.")
|
||||
endif()
|
||||
else()
|
||||
message("pkgconfig not found. Disabling unwind tests.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
||||
if(NOT FIPS)
|
||||
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithassert" OR
|
||||
NOT CMAKE_BUILD_TYPE_LOWER MATCHES "rel")
|
||||
add_definitions(-DBORINGSSL_DISPATCH_TEST)
|
||||
# CMake automatically connects include_directories to the NASM
|
||||
# command-line, but not add_definitions.
|
||||
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_DISPATCH_TEST")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Add a RelWithAsserts build configuration. It is the same as Release, except it
|
||||
# does not define NDEBUG, so asserts run.
|
||||
foreach(VAR CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_ASM_FLAGS)
|
||||
string(REGEX REPLACE "(^| )[/-]DNDEBUG( |$)" " " "${VAR}_RELWITHASSERTS"
|
||||
"${${VAR}_RELEASE}")
|
||||
endforeach()
|
||||
|
||||
if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS)
|
||||
require_go()
|
||||
add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX})
|
||||
# CMake automatically connects include_directories to the NASM command-line,
|
||||
# but not add_definitions.
|
||||
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}")
|
||||
|
||||
# Use "symbol_prefix_include" to store generated header files
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include)
|
||||
add_custom_command(
|
||||
OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h
|
||||
symbol_prefix_include/boringssl_prefix_symbols_asm.h
|
||||
symbol_prefix_include/boringssl_prefix_symbols_nasm.inc
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include
|
||||
COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS}
|
||||
DEPENDS util/make_prefix_headers.go
|
||||
${BORINGSSL_PREFIX_SYMBOLS})
|
||||
|
||||
# add_dependencies needs a target, not a file, so we add an intermediate
|
||||
# target.
|
||||
add_custom_target(
|
||||
boringssl_prefix_symbols
|
||||
DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h
|
||||
symbol_prefix_include/boringssl_prefix_symbols_asm.h
|
||||
symbol_prefix_include/boringssl_prefix_symbols_nasm.inc)
|
||||
elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS)
|
||||
message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS")
|
||||
else()
|
||||
add_custom_target(boringssl_prefix_symbols)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CLANG 1)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
set(EMSCRIPTEN 1)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
|
||||
# Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
|
||||
# primarily on our normal Clang one.
|
||||
set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wwrite-strings -Wvla -Wshadow -Wtype-limits -Wmissing-field-initializers")
|
||||
if(MSVC)
|
||||
# clang-cl sets different default warnings than clang. It also treats -Wall
|
||||
# as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall.
|
||||
# See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900")
|
||||
else()
|
||||
if(EMSCRIPTEN)
|
||||
# emscripten's emcc/clang does not accept the "-ggdb" flag.
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -g")
|
||||
else()
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb")
|
||||
endif()
|
||||
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -fvisibility=hidden -fno-common")
|
||||
endif()
|
||||
|
||||
if(CLANG)
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -Wextra-semi -fcolor-diagnostics")
|
||||
else()
|
||||
# GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
|
||||
# and declare that the code is trying to free a stack pointer.
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
|
||||
endif()
|
||||
|
||||
# -Wstring-concatenation was added in Clang 12.0.0, which corresponds to
|
||||
# AppleClang 13.0.0 per the table in
|
||||
# https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
|
||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0") OR
|
||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0.0"))
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wstring-concatenation")
|
||||
endif()
|
||||
|
||||
# Clang 12's -Wframe-larger-than reportedly does not work in clang-cl. See
|
||||
# https://crbug.com/boringssl/709. Clang 13 includes the following fix, which
|
||||
# may be related. Speculatively gate on Clang 13. That corresponds to
|
||||
# AppleClang 13.1.6.
|
||||
# https://github.com/llvm/llvm-project/commit/6aaf4fa2885600b0e31042071ad06f78218ab0f2
|
||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0.0") OR
|
||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.1.6"))
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wframe-larger-than=25344")
|
||||
endif()
|
||||
|
||||
# -Wctad-maybe-unsupported was added in Clang 10, which is AppleClang 12.0.0.
|
||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0") OR
|
||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0"))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wctad-maybe-unsupported")
|
||||
endif()
|
||||
|
||||
if(CLANG OR CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0")
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wformat-signedness")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations -Wnon-virtual-dtor")
|
||||
|
||||
# In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
|
||||
# and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
|
||||
# spelling for both and -Wmissing-declarations is some other warning.
|
||||
#
|
||||
# https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
|
||||
# https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
|
||||
# https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
|
||||
if(CLANG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
|
||||
endif()
|
||||
elseif(MSVC)
|
||||
set(MSVC_DISABLED_WARNINGS_LIST
|
||||
"C4100" # 'exarg' : unreferenced formal parameter
|
||||
"C4127" # conditional expression is constant
|
||||
"C4244" # 'function' : conversion from 'int' to 'uint8_t',
|
||||
# possible loss of data
|
||||
"C4267" # conversion from 'size_t' to 'int', possible loss of data
|
||||
"C4702" # unreachable code; MSVC's warning is too aggressive. See
|
||||
# https://crbug.com/385161043
|
||||
"C4706" # assignment within conditional expression
|
||||
)
|
||||
string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
|
||||
${MSVC_DISABLED_WARNINGS_LIST})
|
||||
set(CMAKE_C_FLAGS "-utf-8 -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}")
|
||||
# Without /Zc:__cplusplus, MSVC does not define the right value for
|
||||
# __cplusplus. See https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
# If this becomes too problematic for downstream code, we can look at
|
||||
# _MSVC_LANG.
|
||||
set(CMAKE_CXX_FLAGS "-utf-8 -W4 -WX ${MSVC_DISABLED_WARNINGS_STR} -Zc:__cplusplus")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DNOMINMAX)
|
||||
# Allow use of fopen.
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
# pthread_rwlock_t on Linux requires a feature flag. We limit this to Linux
|
||||
# because, on Apple platforms, it instead disables APIs we use. See compat(5)
|
||||
# and sys/cdefs.h. Reportedly, FreeBSD also breaks when this is set. See
|
||||
# https://crbug.com/boringssl/471.
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
|
||||
endif()
|
||||
|
||||
if(FUZZ)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0")
|
||||
message(FATAL_ERROR "You need Clang ≥ 6.0.0")
|
||||
endif()
|
||||
|
||||
add_definitions(-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
set(RUNNER_ARGS "-deterministic" "-fuzzer" "-shim-config" "fuzzer_mode.json")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls")
|
||||
endif()
|
||||
|
||||
add_definitions(-DBORINGSSL_IMPLEMENTATION)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-DBORINGSSL_SHARED_LIBRARY)
|
||||
# Enable position-independent code globally. This is needed because
|
||||
# some library targets are OBJECT libraries.
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||
endif()
|
||||
|
||||
if(MSAN)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
|
||||
endif()
|
||||
|
||||
if(ASAN)
|
||||
message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
|
||||
endif()
|
||||
|
||||
if(ASAN)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
|
||||
endif()
|
||||
|
||||
if(CFI)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "Cannot enable CFI unless using Clang")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin")
|
||||
# We use Chromium's copy of clang, which requires -fuse-ld=lld if building
|
||||
# with -flto. That, in turn, can't handle -ggdb.
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
|
||||
string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
# -flto causes object files to contain LLVM bitcode. Mixing those with
|
||||
# assembly output in the same static library breaks the linker.
|
||||
set(OPENSSL_NO_ASM "1")
|
||||
endif()
|
||||
|
||||
if(TSAN)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "Cannot enable TSAN unless using Clang")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
|
||||
endif()
|
||||
|
||||
if(UBSAN)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "Cannot enable UBSAN unless using Clang")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
|
||||
|
||||
if(NOT UBSAN_RECOVER)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover=undefined")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=undefined")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-sanitize-recover=undefined")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(GCOV)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
||||
if(FIPS)
|
||||
require_go()
|
||||
add_definitions(-DBORINGSSL_FIPS)
|
||||
if(FIPS_BREAK_TEST)
|
||||
add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
|
||||
endif()
|
||||
# The FIPS integrity check does not work for ASan and MSan builds.
|
||||
if(NOT ASAN AND NOT MSAN)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(FIPS_SHARED "1")
|
||||
else()
|
||||
set(FIPS_DELOCATE "1")
|
||||
endif()
|
||||
endif()
|
||||
if(FIPS_SHARED)
|
||||
# The Android CMake files set -ffunction-sections and -fdata-sections,
|
||||
# which is incompatible with FIPS_SHARED.
|
||||
set(CMAKE_C_FLAGS
|
||||
"${CMAKE_C_FLAGS} -fno-function-sections -fno-data-sections")
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -fno-function-sections -fno-data-sections")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(OPENSSL_SMALL)
|
||||
add_definitions(-DOPENSSL_SMALL)
|
||||
endif()
|
||||
|
||||
if(CONSTANT_TIME_VALIDATION)
|
||||
add_definitions(-DBORINGSSL_CONSTANT_TIME_VALIDATION)
|
||||
endif()
|
||||
|
||||
if(MALLOC_FAILURE_TESTING)
|
||||
add_definitions(-DBORINGSSL_MALLOC_FAILURE_TESTING)
|
||||
endif()
|
||||
|
||||
if(OPENSSL_NO_ASM)
|
||||
add_definitions(-DOPENSSL_NO_ASM)
|
||||
endif()
|
||||
|
||||
if(FIPS_DELOCATE OR NOT OPENSSL_NO_ASM)
|
||||
# On x86 and x86_64 Windows, we use the NASM output.
|
||||
if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
|
||||
enable_language(ASM_NASM)
|
||||
set(OPENSSL_NASM TRUE)
|
||||
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
|
||||
else()
|
||||
enable_language(ASM)
|
||||
if (NOT OPENSSL_NO_ASM)
|
||||
set(OPENSSL_ASM TRUE)
|
||||
endif()
|
||||
# Work around https://gitlab.kitware.com/cmake/cmake/-/issues/20771 in older
|
||||
# CMake versions.
|
||||
if(APPLE AND CMAKE_VERSION VERSION_LESS 3.19)
|
||||
if(CMAKE_OSX_SYSROOT)
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
|
||||
endif()
|
||||
foreach(arch ${CMAKE_OSX_ARCHITECTURES})
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
|
||||
endforeach()
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
|
||||
endif()
|
||||
# Clang's integerated assembler does not support debug symbols.
|
||||
if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(OPENSSL_NO_SSE2_FOR_TESTING)
|
||||
add_definitions(-DOPENSSL_NO_SSE2_FOR_TESTING)
|
||||
endif()
|
||||
|
||||
if(USE_CUSTOM_LIBCXX)
|
||||
if(NOT CLANG)
|
||||
message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang")
|
||||
endif()
|
||||
|
||||
# CMake does not allow installing a library without installing dependencies.
|
||||
# If we installed libcrypto, we'd have to install our custom libc++, which
|
||||
# does not make sense. As this is a test-only configuration, disable
|
||||
# installing.
|
||||
set(INSTALL_ENABLED 0)
|
||||
|
||||
# CMAKE_CXX_FLAGS ends up in the linker flags as well, so use
|
||||
# add_compile_options. There does not appear to be a way to set
|
||||
# language-specific compile-only flags.
|
||||
add_compile_options("-nostdinc++")
|
||||
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib++")
|
||||
include_directories(
|
||||
SYSTEM
|
||||
util/bot/libcxx-config
|
||||
util/bot/libcxx/include
|
||||
util/bot/libcxxabi/include
|
||||
)
|
||||
|
||||
# This is patterned after buildtools/third_party/libc++/BUILD.gn and
|
||||
# buildtools/third_party/libc++abi/BUILD.gn in Chromium.
|
||||
|
||||
file(GLOB LIBCXX_SOURCES "util/bot/libcxx/src/*.cpp")
|
||||
file(GLOB LIBCXXABI_SOURCES "util/bot/libcxxabi/src/*.cpp")
|
||||
|
||||
# This file is meant for exception-less builds.
|
||||
list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp")
|
||||
# libc++ also defines new and delete.
|
||||
list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp")
|
||||
if(TSAN)
|
||||
# ThreadSanitizer tries to intercept these symbols. Skip them to avoid
|
||||
# symbol conflicts.
|
||||
list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp")
|
||||
endif()
|
||||
|
||||
add_library(libcxxabi ${LIBCXXABI_SOURCES})
|
||||
target_compile_definitions(
|
||||
libcxxabi PRIVATE
|
||||
-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
|
||||
)
|
||||
|
||||
add_library(libcxx ${LIBCXX_SOURCES})
|
||||
if(ASAN OR MSAN OR TSAN)
|
||||
# Sanitizers try to intercept new and delete.
|
||||
target_compile_definitions(
|
||||
libcxx PRIVATE
|
||||
-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS
|
||||
)
|
||||
endif()
|
||||
target_compile_definitions(
|
||||
libcxx PRIVATE
|
||||
-D_LIBCPP_BUILDING_LIBRARY
|
||||
-DLIBCXX_BUILDING_LIBCXXABI
|
||||
-DLIBC_NAMESPACE=bssl_llvm_libc
|
||||
)
|
||||
# LLVM libc++ depends on some shared headers from LLVM libc.
|
||||
target_include_directories(libcxx PRIVATE util/bot/llvm-libc)
|
||||
set_target_properties(
|
||||
libcxx libcxxabi PROPERTIES
|
||||
COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough"
|
||||
# libc++ and libc++abi must be built in C++23 mode.
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED TRUE
|
||||
)
|
||||
# libc++abi depends on libc++ internal headers.
|
||||
set_property(TARGET libcxx libcxxabi APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/util/bot/libcxx/src")
|
||||
target_link_libraries(libcxx libcxxabi)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
# Add minimal googletest targets. The provided one has many side-effects, and
|
||||
# googletest has a very straightforward build.
|
||||
add_library(
|
||||
boringssl_gtest
|
||||
third_party/googletest/googlemock/src/gmock-all.cc
|
||||
third_party/googletest/googletest/src/gtest-all.cc
|
||||
)
|
||||
if(USE_CUSTOM_LIBCXX)
|
||||
target_link_libraries(boringssl_gtest libcxx)
|
||||
endif()
|
||||
target_include_directories(
|
||||
boringssl_gtest
|
||||
PUBLIC
|
||||
third_party/googletest/googlemock/include
|
||||
third_party/googletest/googletest/include
|
||||
PRIVATE
|
||||
third_party/googletest/googlemock
|
||||
third_party/googletest/googletest
|
||||
)
|
||||
|
||||
# Declare a dummy target to build all unit tests. Test targets should inject
|
||||
# themselves as dependencies next to the target definition.
|
||||
add_custom_target(all_tests)
|
||||
|
||||
add_subdirectory(ssl/test)
|
||||
endif()
|
||||
|
||||
if(OPENSSL_ASM)
|
||||
set(CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
|
||||
set(BCM_SOURCES_ASM_USED ${BCM_SOURCES_ASM})
|
||||
set(TEST_SUPPORT_SOURCES_ASM_USED ${TEST_SUPPORT_SOURCES_ASM})
|
||||
elseif(OPENSSL_NASM)
|
||||
set(CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
|
||||
set(BCM_SOURCES_ASM_USED ${BCM_SOURCES_NASM})
|
||||
set(TEST_SUPPORT_SOURCES_ASM_USED ${TEST_SUPPORT_SOURCES_NASM})
|
||||
endif()
|
||||
|
||||
if(FIPS_DELOCATE AND FIPS_SHARED)
|
||||
message(FATAL_ERROR "Can't set both delocate and shared mode for FIPS build")
|
||||
endif()
|
||||
|
||||
# OSS-Fuzz relies on BORINGSSL_ALLOW_CXX_RUNTIME because -fno-rtti and
|
||||
# -fsanitize=vptr are incompatible.
|
||||
set(NO_CXX_RUNTIME_FLAGS)
|
||||
if(NOT MSVC AND NOT BORINGSSL_ALLOW_CXX_RUNTIME)
|
||||
# Without -fno-exceptions, use of std::unique_ptr emits a call to
|
||||
# std::terminate.
|
||||
set(NO_CXX_RUNTIME_FLAGS -fno-exceptions -fno-rtti)
|
||||
endif()
|
||||
|
||||
if(FIPS_DELOCATE)
|
||||
add_library(bcm_c_generated_asm STATIC ${BCM_SOURCES})
|
||||
# The C++ code in libcrypto shouldn't depend on libstdc++.
|
||||
target_compile_options(bcm_c_generated_asm PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}> "-S")
|
||||
add_dependencies(bcm_c_generated_asm boringssl_prefix_symbols)
|
||||
target_include_directories(bcm_c_generated_asm PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
set_target_properties(bcm_c_generated_asm PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
if(CLANG)
|
||||
# Clang warns when passing both -c (from CMake) and -S.
|
||||
target_compile_options(bcm_c_generated_asm PRIVATE "-Wno-unused-command-line-argument")
|
||||
endif()
|
||||
|
||||
set(TARGET_FLAG "")
|
||||
if(CMAKE_ASM_COMPILER_TARGET)
|
||||
set(TARGET_FLAG "--target=${CMAKE_ASM_COMPILER_TARGET}")
|
||||
endif()
|
||||
|
||||
go_executable(delocate boringssl.googlesource.com/boringssl.git/util/fipstools/delocate)
|
||||
add_custom_command(
|
||||
OUTPUT bcm-delocated.S
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/delocate
|
||||
-a $<TARGET_FILE:bcm_c_generated_asm>
|
||||
-o ${CMAKE_CURRENT_BINARY_DIR}/bcm-delocated.S
|
||||
-cc ${CMAKE_ASM_COMPILER}
|
||||
-cc-flags "${TARGET_FLAG} ${CMAKE_ASM_FLAGS}"
|
||||
${BCM_SOURCES_ASM_USED}
|
||||
${CRYPTO_HEADERS}
|
||||
DEPENDS bcm_c_generated_asm
|
||||
delocate
|
||||
${BCM_SOURCES_ASM_USED}
|
||||
${CRYPTO_HEADERS}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_library(bcm_hashunset STATIC bcm-delocated.S)
|
||||
set_target_properties(bcm_hashunset PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
set_target_properties(bcm_hashunset PROPERTIES LINKER_LANGUAGE C)
|
||||
|
||||
go_executable(inject_hash
|
||||
boringssl.googlesource.com/boringssl.git/util/fipstools/inject_hash)
|
||||
add_custom_command(
|
||||
OUTPUT bcm.o
|
||||
COMMAND ./inject_hash -o bcm.o -in-archive $<TARGET_FILE:bcm_hashunset>
|
||||
DEPENDS bcm_hashunset inject_hash
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
set(CRYPTO_FIPS_OBJECTS bcm.o)
|
||||
elseif(FIPS_SHARED)
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "FIPS_SHARED set but not BUILD_SHARED_LIBS")
|
||||
endif()
|
||||
|
||||
add_library(bcm_library STATIC ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED})
|
||||
# The C++ code in libcrypto shouldn't depend on libstdc++.
|
||||
target_compile_options(bcm_library PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
|
||||
add_dependencies(bcm_library boringssl_prefix_symbols)
|
||||
target_include_directories(bcm_library PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT bcm.o
|
||||
COMMAND ${CMAKE_LINKER} -r -T ${CMAKE_CURRENT_SOURCE_DIR}/crypto/fipsmodule/fips_shared.lds -o bcm.o --whole-archive $<TARGET_FILE:bcm_library>
|
||||
DEPENDS bcm_library crypto/fipsmodule/fips_shared.lds
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
set(CRYPTO_FIPS_OBJECTS bcm.o)
|
||||
else()
|
||||
add_library(fipsmodule OBJECT ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED})
|
||||
# The C++ code in libcrypto shouldn't depend on libstdc++.
|
||||
target_compile_options(fipsmodule PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
|
||||
add_dependencies(fipsmodule boringssl_prefix_symbols)
|
||||
target_include_directories(fipsmodule PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
set(CRYPTO_FIPS_OBJECTS $<TARGET_OBJECTS:fipsmodule>)
|
||||
endif()
|
||||
|
||||
add_library(crypto ${CRYPTO_SOURCES} ${CRYPTO_FIPS_OBJECTS} ${CRYPTO_SOURCES_ASM_USED})
|
||||
# The C++ code in libcrypto shouldn't depend on libstdc++.
|
||||
target_compile_options(crypto PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
|
||||
target_include_directories(crypto PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
set_property(TARGET crypto PROPERTY EXPORT_NAME Crypto)
|
||||
|
||||
if(FIPS_SHARED)
|
||||
# Rewrite libcrypto.so to inject the correct module hash value. This assumes
|
||||
# UNIX-style library naming, but we only support FIPS mode on Linux anyway.
|
||||
add_custom_command(
|
||||
TARGET crypto POST_BUILD
|
||||
COMMAND ${GO_EXECUTABLE} run
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/fipstools/inject_hash/inject_hash.go
|
||||
-o libcrypto.so -in-object libcrypto.so
|
||||
# The DEPENDS argument to a POST_BUILD rule appears to be ignored. Thus
|
||||
# go_executable isn't used (as it doesn't get built), but we list this
|
||||
# dependency anyway in case it starts working in some CMake version.
|
||||
DEPENDS util/fipstools/inject_hash/inject_hash.go
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
add_dependencies(crypto boringssl_prefix_symbols)
|
||||
if(WIN32)
|
||||
target_link_libraries(crypto ws2_32)
|
||||
endif()
|
||||
|
||||
# CMAKE_SYSTEM_NAME is "Generic" for embedded OSes:
|
||||
# https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html#toolchain-files
|
||||
#
|
||||
# For now we assume embedded OSes do not have threads. Additionally, the Threads
|
||||
# package does not work with Android, but Android does not require any extra
|
||||
# parameters to link pthreads.
|
||||
if(NOT CMAKE_SYSTEM_NAME MATCHES "^(Generic|Android)$")
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(crypto Threads::Threads)
|
||||
endif()
|
||||
|
||||
# Every target depends on crypto, so we add libcxx as a dependency here to
|
||||
# simplify injecting it everywhere.
|
||||
if(USE_CUSTOM_LIBCXX)
|
||||
target_link_libraries(crypto libcxx)
|
||||
endif()
|
||||
|
||||
add_library(ssl ${SSL_SOURCES})
|
||||
# Although libssl also provides headers that require an include directory, the
|
||||
# flag is already specified by libcrypto, so we omit target_include_directories
|
||||
# here.
|
||||
set_property(TARGET ssl PROPERTY EXPORT_NAME SSL)
|
||||
target_link_libraries(ssl crypto)
|
||||
|
||||
add_library(decrepit ${DECREPIT_SOURCES})
|
||||
target_link_libraries(decrepit ssl crypto)
|
||||
|
||||
if(APPLE)
|
||||
set(PKI_CXX_FLAGS "-fno-aligned-new")
|
||||
endif()
|
||||
add_library(pki ${PKI_SOURCES})
|
||||
target_link_libraries(pki crypto)
|
||||
target_compile_options(pki PRIVATE ${PKI_CXX_FLAGS})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_library(test_support_lib STATIC
|
||||
${TEST_SUPPORT_SOURCES} ${TEST_SUPPORT_SOURCES_ASM_USED})
|
||||
if(LIBUNWIND_FOUND)
|
||||
target_compile_options(test_support_lib PRIVATE ${LIBUNWIND_CFLAGS_OTHER})
|
||||
target_include_directories(test_support_lib PRIVATE ${LIBUNWIND_INCLUDE_DIRS})
|
||||
target_link_libraries(test_support_lib ${LIBUNWIND_LDFLAGS})
|
||||
endif()
|
||||
if(WIN32)
|
||||
target_link_libraries(test_support_lib dbghelp)
|
||||
endif()
|
||||
target_link_libraries(test_support_lib boringssl_gtest crypto)
|
||||
|
||||
# urandom_test is a separate binary because it needs to be able to observe the
|
||||
# PRNG initialisation, which means that it can't have other tests running before
|
||||
# it does.
|
||||
add_executable(urandom_test ${URANDOM_TEST_SOURCES})
|
||||
target_link_libraries(urandom_test test_support_lib boringssl_gtest crypto)
|
||||
add_dependencies(all_tests urandom_test)
|
||||
|
||||
add_executable(crypto_test ${CRYPTO_TEST_SOURCES})
|
||||
target_link_libraries(crypto_test test_support_lib boringssl_gtest crypto)
|
||||
add_dependencies(all_tests crypto_test)
|
||||
|
||||
add_executable(ssl_test ${SSL_TEST_SOURCES})
|
||||
target_link_libraries(ssl_test test_support_lib boringssl_gtest ssl crypto)
|
||||
add_dependencies(all_tests ssl_test)
|
||||
add_executable(decrepit_test ${DECREPIT_TEST_SOURCES})
|
||||
target_link_libraries(decrepit_test test_support_lib boringssl_gtest
|
||||
decrepit ssl crypto)
|
||||
add_dependencies(all_tests decrepit_test)
|
||||
|
||||
add_executable(pki_test ${PKI_TEST_SOURCES})
|
||||
target_link_libraries(pki_test test_support_lib boringssl_gtest pki crypto)
|
||||
target_compile_options(pki_test PRIVATE ${PKI_CXX_FLAGS})
|
||||
add_dependencies(all_tests pki_test)
|
||||
|
||||
add_executable(test_fips util/fipstools/test_fips.cc)
|
||||
target_link_libraries(test_fips crypto)
|
||||
endif()
|
||||
|
||||
if(FIPS)
|
||||
add_executable(modulewrapper ${MODULEWRAPPER_SOURCES})
|
||||
target_link_libraries(modulewrapper crypto)
|
||||
endif()
|
||||
|
||||
add_executable(bssl ${BSSL_SOURCES})
|
||||
target_link_libraries(bssl ssl crypto)
|
||||
|
||||
if(FUZZ)
|
||||
if(LIBFUZZER_FROM_DEPS)
|
||||
file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
|
||||
add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
|
||||
# libFuzzer does not pass our aggressive warnings. It also must be built
|
||||
# without -fsanitize-coverage options or clang crashes.
|
||||
set_target_properties(
|
||||
Fuzzer PROPERTIES
|
||||
COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_subdirectory(fuzz)
|
||||
endif()
|
||||
|
||||
if(RUST_BINDINGS)
|
||||
find_program(BINDGEN_EXECUTABLE bindgen)
|
||||
if(NOT BINDGEN_EXECUTABLE)
|
||||
message(FATAL_ERROR "Could not find bindgen but was asked to generate Rust bindings.")
|
||||
else()
|
||||
add_subdirectory(rust)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(HANDSHAKER_ARGS "-handshaker-path" $<TARGET_FILE:handshaker>)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
if(FIPS)
|
||||
add_custom_target(
|
||||
acvp_tests
|
||||
COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_CURRENT_BINARY_DIR}/acvptool
|
||||
boringssl.googlesource.com/boringssl.git/util/fipstools/acvp/acvptool
|
||||
COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_CURRENT_BINARY_DIR}/testmodulewrapper
|
||||
boringssl.googlesource.com/boringssl.git/util/fipstools/acvp/acvptool/testmodulewrapper
|
||||
COMMAND cd util/fipstools/acvp/acvptool/test &&
|
||||
${GO_EXECUTABLE} run check_expected.go
|
||||
-tool ${CMAKE_CURRENT_BINARY_DIR}/acvptool
|
||||
-module-wrappers modulewrapper:$<TARGET_FILE:modulewrapper>,testmodulewrapper:${CMAKE_CURRENT_BINARY_DIR}/testmodulewrapper
|
||||
-tests tests.json
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS modulewrapper
|
||||
USES_TERMINAL)
|
||||
|
||||
add_custom_target(
|
||||
fips_specific_tests_if_any
|
||||
DEPENDS acvp_tests
|
||||
)
|
||||
else()
|
||||
add_custom_target(fips_specific_tests_if_any)
|
||||
endif()
|
||||
|
||||
file(STRINGS util/go_tests.txt GO_TESTS)
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
|
||||
util/go_tests.txt)
|
||||
|
||||
if(GO_EXECUTABLE)
|
||||
add_custom_target(
|
||||
run_tests
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Running Go tests"
|
||||
COMMAND ${GO_EXECUTABLE} test ${GO_TESTS}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Running unit tests"
|
||||
COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Running SSL tests"
|
||||
COMMAND cd ssl/test/runner &&
|
||||
${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
|
||||
${HANDSHAKER_ARGS} ${RUNNER_ARGS}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS all_tests bssl_shim handshaker fips_specific_tests_if_any
|
||||
USES_TERMINAL)
|
||||
else()
|
||||
add_custom_target(
|
||||
run_tests
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Running tests requires Go"
|
||||
COMMAND ${CMAKE_COMMAND} -E false)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(INSTALL_ENABLED)
|
||||
install(TARGETS crypto ssl EXPORT OpenSSLTargets)
|
||||
install(TARGETS bssl)
|
||||
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(EXPORT OpenSSLTargets
|
||||
FILE OpenSSLTargets.cmake
|
||||
NAMESPACE OpenSSL::
|
||||
DESTINATION lib/cmake/OpenSSL)
|
||||
install(FILES cmake/OpenSSLConfig.cmake DESTINATION lib/cmake/OpenSSL)
|
||||
endif()
|
||||
@@ -1,96 +0,0 @@
|
||||
Want to contribute? Great! First, read this page (including the small print at the end).
|
||||
|
||||
### Before you contribute
|
||||
Before we can use your code, you must sign the
|
||||
[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual)
|
||||
(CLA), which you can do online. The CLA is necessary mainly because you own the
|
||||
copyright to your changes, even after your contribution becomes part of our
|
||||
codebase, so we need your permission to use and distribute your code. We also
|
||||
need to be sure of various other things—for instance that you'll tell us if you
|
||||
know that your code infringes on other people's patents. You don't have to sign
|
||||
the CLA until after you've submitted your code for review and a member has
|
||||
approved it, but you must do it before we can put your code into our codebase.
|
||||
Before you start working on a larger contribution, you should get in touch with
|
||||
us first via email with your idea so that we can help out and possibly guide
|
||||
you. Coordinating up front makes it much easier to avoid frustration later on.
|
||||
|
||||
### Code reviews
|
||||
All submissions, including submissions by project members, require review. We
|
||||
use [Gerrit](https://boringssl-review.googlesource.com) for this purpose.
|
||||
|
||||
#### Setup
|
||||
If you have not done so on this machine, you will need to set up a password for
|
||||
Gerrit. Sign in with a Google account, visit
|
||||
[this link](https://boringssl.googlesource.com/), and click the "Generate
|
||||
Password" link in the top right.
|
||||
|
||||
You must also have a Gerrit account associated with
|
||||
your Google account. To do this visit the [Gerrit review server](https://boringssl-review.googlesource.com)
|
||||
and click "Sign in" (top right).
|
||||
|
||||
Finally, you will need to prepare your checkout to
|
||||
[add Change-Ids](https://gerrit-review.googlesource.com/Documentation/cmd-hook-commit-msg.html)
|
||||
on commit. Run:
|
||||
|
||||
curl -Lo .git/hooks/commit-msg https://boringssl-review.googlesource.com/tools/hooks/commit-msg
|
||||
chmod u+x .git/hooks/commit-msg
|
||||
|
||||
#### Uploading changes
|
||||
To upload a change, push it to the special `refs/for/main` target:
|
||||
|
||||
git push origin HEAD:refs/for/main
|
||||
|
||||
The output will then give you a link to the change. Add `agl@google.com`,
|
||||
`davidben@google.com` as reviewers.
|
||||
|
||||
Pushing a commit with the same Change-Id as an existing change will upload a new
|
||||
version of it. (Use the `git rebase` or `git commit --amend` commands.)
|
||||
|
||||
For more detailed instructions, see the
|
||||
[Gerrit User Guide](https://gerrit-review.googlesource.com/Documentation/intro-user.html).
|
||||
|
||||
### Copyright headers
|
||||
New files contributed directly to BoringSSL should use the following copyright
|
||||
header, where `YEAR` is the year the file was added:
|
||||
|
||||
Copyright YEAR The BoringSSL Authors
|
||||
|
||||
To list individual contributors, we maintain an [AUTHORS](./AUTHORS) file at the
|
||||
top level of the project. See [this documentation](https://opensource.google/documentation/reference/releasing/authors)
|
||||
for more details. If you wish to be added, you are welcome to add yourself as
|
||||
part of your contribution, or request that we add you.
|
||||
|
||||
We started the AUTHORS file after the project began, and after receiving many
|
||||
valuable contributions. To avoid being presumptuous, we did not proactively list
|
||||
all past contributors. If you previously made a contribution, you are likewise
|
||||
welcome to send us a patch to be added, or request that we add you.
|
||||
|
||||
After the copyright lines, files should include the license notice described in
|
||||
the Apache 2.0 appendix. Thus new files should begin with the following header:
|
||||
|
||||
// Copyright YEAR The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
### The small print
|
||||
Contributions made by corporations are covered by a different agreement than
|
||||
the one above, the
|
||||
[Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate).
|
||||
|
||||
The following are Google-internal bug numbers where explicit permission from
|
||||
some authors is recorded for use of their work. (This is purely for our own
|
||||
record keeping.)
|
||||
* 27287199
|
||||
* 27287880
|
||||
* 27287883
|
||||
* 263291445
|
||||
@@ -1,78 +0,0 @@
|
||||
# Fuzz testing
|
||||
|
||||
Modern fuzz testers are very effective and we wish to use them to ensure that no silly bugs creep into BoringSSL.
|
||||
|
||||
We use Clang's [libFuzzer](http://llvm.org/docs/LibFuzzer.html) for fuzz testing and there are a number of fuzz testing functions in `fuzz/`. They are not built by default because they require that the rest of BoringSSL be built with some changes that make fuzzing much more effective, but are completely unsafe for real use.
|
||||
|
||||
In order to build the fuzz tests you will need at least Clang 6.0. Pass `-DFUZZ=1` on the CMake command line to enable building BoringSSL with coverage and AddressSanitizer, and to build the fuzz test binaries. You'll probably need to set the `CC` and `CXX` environment variables too, like this:
|
||||
|
||||
```
|
||||
CC=clang CXX=clang++ cmake -GNinja -DFUZZ=1 -B build
|
||||
ninja -C build
|
||||
```
|
||||
|
||||
|
||||
From the `build/` directory, you can then run the fuzzers. For example:
|
||||
|
||||
```
|
||||
./fuzz/cert -max_len=10000 -jobs=32 -workers=32 ../fuzz/cert_corpus/
|
||||
```
|
||||
|
||||
The arguments to `jobs` and `workers` should be the number of cores that you wish to dedicate to fuzzing. By default, libFuzzer uses the largest test in the corpus (or 64 if empty) as the maximum test case length. The `max_len` argument overrides this.
|
||||
|
||||
The recommended values of `max_len` for each test are:
|
||||
|
||||
| Test | `max_len` value |
|
||||
|---------------|-----------------|
|
||||
| `bn_div` | 384 |
|
||||
| `bn_mod_exp` | 4096 |
|
||||
| `cert` | 10000 |
|
||||
| `client` | 20000 |
|
||||
| `pkcs8` | 2048 |
|
||||
| `privkey` | 2048 |
|
||||
| `server` | 4096 |
|
||||
| `session` | 8192 |
|
||||
| `spki` | 1024 |
|
||||
| `read_pem` | 512 |
|
||||
| `ssl_ctx_api` | 256 |
|
||||
|
||||
These were determined by rounding up the length of the largest case in the corpus.
|
||||
|
||||
There are directories in `fuzz/` for each of the fuzzing tests which contain seed files for fuzzing. Some of the seed files were generated manually but many of them are “interesting” results generated by the fuzzing itself. (Where “interesting” means that it triggered a previously unknown path in the code.)
|
||||
|
||||
## Minimising the corpora
|
||||
|
||||
When a large number of new seeds are available, it's a good idea to minimise the corpus so that different seeds that trigger the same code paths can be deduplicated.
|
||||
|
||||
In order to minimise all the corpora, build for fuzzing and run `./fuzz/minimise_corpora.sh`. Note that minimisation is, oddly, often not idempotent for unknown reasons.
|
||||
|
||||
## Fuzzer mode
|
||||
|
||||
When `-DFUZZ=1` is passed into CMake, BoringSSL builds with `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` defined. BoringSSL will then:
|
||||
|
||||
* Replace `RAND_bytes` with a deterministic PRNG. Call `RAND_reset_for_fuzzing()` at the start of fuzzers which use `RAND_bytes` to reset the PRNG state.
|
||||
|
||||
Additionally, if `CRYPTO_set_fuzzer_mode()` is called to enable fuzzer mode, BoringSSL will:
|
||||
|
||||
* Modify the TLS stack to perform all signature checks (CertificateVerify and ServerKeyExchange) and the Finished check, but always act as if the check succeeded.
|
||||
|
||||
* Treat every cipher as the NULL cipher.
|
||||
|
||||
* Tickets are unencrypted and the MAC check is performed but ignored.
|
||||
|
||||
* renegotiation\_info checks are ignored.
|
||||
|
||||
This is to prevent the fuzzer from getting stuck at a cryptographic invariant in the protocol.
|
||||
|
||||
## TLS transcripts
|
||||
|
||||
The `client` and `server` corpora are seeded from the test suite. The test suite has a `-fuzzer` flag which mirrors the fuzzer mode changes above and a `-deterministic` flag which removes all non-determinism on the Go side. Not all tests pass, so `ssl/test/runner/fuzzer_mode.json` contains the necessary suppressions. The `run_tests` target will pass appropriate command-line flags.
|
||||
|
||||
There are separate fuzzers, `client_no_fuzzer_mode` and `server_no_fuzzer_mode`, with fuzzer mode disabled. This configuration is run in the same way but without `-fuzzer` and `-shim-config` flags.
|
||||
|
||||
If both sets of tests pass, refresh the fuzzer corpora with `refresh_ssl_corpora.sh`:
|
||||
|
||||
```
|
||||
cd fuzz
|
||||
./refresh_ssl_corpora.sh /path/to/fuzzer/mode/build /path/to/non/fuzzer/mode/build
|
||||
```
|
||||
@@ -1,121 +0,0 @@
|
||||
# Incorporating BoringSSL into a project
|
||||
|
||||
**Note**: if your target project is not a Google project then first read the
|
||||
[main README](./README.md) about the purpose of BoringSSL.
|
||||
|
||||
If you are porting BoringSSL to a new platform see
|
||||
["go/boringssl-on-new-platform"](https://goto.corp.google.com/boringssl-on-new-platform) (Google
|
||||
Internal) for information about porting BoringSSL to a new platform for a Google
|
||||
project.
|
||||
|
||||
## Which branch to use
|
||||
|
||||
BoringSSL usage typically follows a
|
||||
["live at head"](https://abseil.io/about/philosophy#we-recommend-that-you-choose-to-live-at-head)
|
||||
model. Projects pin to whatever the current latest of BoringSSL is at the time
|
||||
of update, and regularly update it to pick up new changes.
|
||||
|
||||
Some systems cannot consume git revisions and expect git tags. BoringSSL tags
|
||||
periodic snapshots as "releases", to meet the needs of those systems. These
|
||||
versions do not represent any kind of stability or development milestone.
|
||||
BoringSSL does not branch at these releases and will not cherry-pick bugfixes to
|
||||
them. Unless there is a technical constraint to use one of these revisions,
|
||||
projects should simply use the latest untagged revision when updating.
|
||||
|
||||
While the BoringSSL repository may contain project-specific branches, e.g.
|
||||
`chromium-2214`, those are _not_ supported release branches and must not as
|
||||
such. In rare cases, BoringSSL will temporarily maintain a short-lived branch on
|
||||
behalf of a project. Most such branches are no longer updated, because the
|
||||
corresponding project no longer needs them, and we do not create new ones to
|
||||
replace the ones that are no longer updated. E.g., not every Chromium release
|
||||
branch has a corresponding BoringSSL `chromium-*` branch. Even while active, the
|
||||
branch may not contain all changes relevant to a general BoringSSL consumer.
|
||||
|
||||
## Bazel
|
||||
|
||||
If you are using [Bazel](https://bazel.build) then you can use the [boringssl
|
||||
module](https://registry.bazel.build/modules/boringssl) in the Bazel Central
|
||||
Registry with bzlmod. Look up the latest version and add the following to your
|
||||
`MODULE.bazel` file:
|
||||
|
||||
bazel_dep(name = "boringssl", version = "INSERT_VERSION_HERE")
|
||||
|
||||
Substitute the latest version in for `INSERT_VERSION_HERE`.
|
||||
|
||||
BoringSSL will periodically ship snapshots to Bazel Central Registry. As with
|
||||
other dependencies, periodically keep the referenced version up-to-date.
|
||||
|
||||
## Directory layout
|
||||
|
||||
Typically projects create a `third_party/boringssl` directory to put
|
||||
BoringSSL-specific files into. The source code of BoringSSL itself goes into
|
||||
`third_party/boringssl/src`, either by copying or as a
|
||||
[submodule](https://git-scm.com/docs/git-submodule).
|
||||
|
||||
It's generally a mistake to put BoringSSL's source code into
|
||||
`third_party/boringssl` directly because custom build files need to go somewhere
|
||||
and merging these with the BoringSSL source code makes updating things more
|
||||
complex.
|
||||
|
||||
## Build support
|
||||
|
||||
BoringSSL is designed to work with many different build systems. The project
|
||||
currently has [CMake](https://cmake.org/) and [Bazel](https://bazel.build/)
|
||||
builds checked in. Other build systems, and embedders with custom build needs,
|
||||
are supported by separating the source list, maintained by BoringSSL, and the
|
||||
top-level build logic, maintained by the embedder.
|
||||
|
||||
Source lists for various build systems are pre-generated and live in the `gen`
|
||||
directory. For example, source lists for
|
||||
[GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md) live in
|
||||
[gen/sources.gni](./gen/sources.gni). There is also a generic
|
||||
[gen/sources.json](./gen/sources.json) file for projects to consume if needed.
|
||||
[util/build/build.go](./util/build/build.go) describes what the various source
|
||||
lists mean. Most projects should concatenate the `bcm` and `crypto` targets.
|
||||
|
||||
If you don't use any of the supported build systems, you should augment the
|
||||
[util/pregenerate](./util/pregenerate) tool to support it, or
|
||||
consume [gen/sources.json](./gen/sources.json).
|
||||
|
||||
Historically, source lists were generated at update time with the
|
||||
[`util/generate_build_files.py`](./util/generate_build_files.py) script. We are
|
||||
in the process of transitioning builds to the pre-generated files, so that
|
||||
embedders do not need to run a custom script when updating BoringSSL.
|
||||
|
||||
## Defines
|
||||
|
||||
BoringSSL does not present a lot of configurability in order to reduce the
|
||||
number of configurations that need to be tested. But there are a couple of
|
||||
\#defines that you may wish to set:
|
||||
|
||||
`OPENSSL_NO_ASM` prevents the use of assembly code (although it's up to you to
|
||||
ensure that the build system doesn't link it in if you wish to reduce binary
|
||||
size). This will have a significant performance impact but can be useful if you
|
||||
wish to use tools like
|
||||
[AddressSanitizer](http://clang.llvm.org/docs/AddressSanitizer.html) that
|
||||
interact poorly with assembly code.
|
||||
|
||||
`OPENSSL_SMALL` removes some code that is especially large at some performance
|
||||
cost.
|
||||
|
||||
## Symbols
|
||||
|
||||
You cannot link multiple versions of BoringSSL or OpenSSL into a single binary
|
||||
without dealing with symbol conflicts. If you are statically linking multiple
|
||||
versions together, there's not a lot that can be done because C doesn't have a
|
||||
module system.
|
||||
|
||||
If you are using multiple versions in a single binary, in different shared
|
||||
objects, ensure you build BoringSSL with `-fvisibility=hidden` and do not
|
||||
export any of BoringSSL's symbols. This will prevent any collisions with other
|
||||
verisons that may be included in other shared objects. Note that this requires
|
||||
that all callers of BoringSSL APIs live in the same shared object as BoringSSL.
|
||||
|
||||
If you require that BoringSSL APIs be used across shared object boundaries,
|
||||
continue to build with `-fvisibility=hidden` but define
|
||||
`BORINGSSL_SHARED_LIBRARY` in both BoringSSL and consumers. BoringSSL's own
|
||||
source files (but *not* consumers' source files) must also build with
|
||||
`BORINGSSL_IMPLEMENTATION` defined. This will export BoringSSL's public symbols
|
||||
in the resulting shared object while hiding private symbols. However note that,
|
||||
as with a static link, this precludes dynamically linking with another version
|
||||
of BoringSSL or OpenSSL.
|
||||
@@ -1,36 +0,0 @@
|
||||
# Copyright 2024 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# When tagging a new periodic snapshot, bump the version here and then tag at
|
||||
# the revision where we bump the version.
|
||||
module(
|
||||
name = "boringssl",
|
||||
version = "0.20250415.0",
|
||||
compatibility_level = 2,
|
||||
)
|
||||
|
||||
# Periodically update the following dependencies to their latest versions
|
||||
# listed on https://registry.bazel.build/. When doing so, run
|
||||
# `bazelisk test ...` to update the hashes in MODULE.bazel.lock.
|
||||
|
||||
# In principle, googletest is only needed for tests and could be a
|
||||
# dev_dependency. But it would then be impossible for downstream modules to run
|
||||
# BoringSSL's tests. The downstream module provides the toolchain, so we may
|
||||
# need to request they run tests when triaging issues. If
|
||||
# https://github.com/bazelbuild/bazel/issues/22187 is ever fixed, we can change
|
||||
# this.
|
||||
bazel_dep(name = "googletest", version = "1.16.0")
|
||||
bazel_dep(name = "platforms", version = "0.0.11")
|
||||
bazel_dep(name = "rules_cc", version = "0.1.1")
|
||||
bazel_dep(name = "rules_license", version = "1.0.0")
|
||||
136
src/MODULE.bazel.lock
generated
136
src/MODULE.bazel.lock
generated
@@ -1,136 +0,0 @@
|
||||
{
|
||||
"lockFileVersion": 13,
|
||||
"registryFileHashes": {
|
||||
"https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230125.1/MODULE.bazel": "89047429cb0207707b2dface14ba7f8df85273d484c2572755be4bab7ce9c3a0",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230802.0.bcr.1/MODULE.bazel": "1c8cec495288dccd14fdae6e3f95f772c1c91857047a098fad772034264cc8cb",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230802.0/MODULE.bazel": "d253ae36a8bd9ee3c5955384096ccb6baf16a1b1e93e858370da0a3b94f77c16",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20240116.2/MODULE.bazel": "73939767a4686cd9a520d16af5ab440071ed75cec1a876bf2fcfaf1f71987a16",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20250127.0/MODULE.bazel": "d1086e248cda6576862b4b3fe9ad76a214e08c189af5b42557a6e1888812c5d5",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20250127.0/source.json": "1b996859f840d8efc7c720efc61dcf2a84b1261cb3974cbbe9b6666ebf567775",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.15.1/MODULE.bazel": "a0556fefca0b1bb2de8567b8827518f94db6a6e7e7d632b4c48dc5f865bc7c85",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.15.1/source.json": "517f2b77430084c541bc9be2db63fdcbb7102938c5f64c17ee60ffda2e5cf07b",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.19.0/source.json": "d7bf14517c1b25b9d9c580b0f8795fceeae08a7590f507b76aace528e941375d",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953",
|
||||
"https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84",
|
||||
"https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8",
|
||||
"https://bcr.bazel.build/modules/google_benchmark/1.8.2/MODULE.bazel": "a70cf1bba851000ba93b58ae2f6d76490a9feb74192e57ab8e8ff13c34ec50cb",
|
||||
"https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4",
|
||||
"https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/MODULE.bazel": "22c31a561553727960057361aa33bf20fb2e98584bc4fec007906e27053f80c6",
|
||||
"https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f",
|
||||
"https://bcr.bazel.build/modules/googletest/1.15.2/MODULE.bazel": "6de1edc1d26cafb0ea1a6ab3f4d4192d91a312fd2d360b63adaa213cd00b2108",
|
||||
"https://bcr.bazel.build/modules/googletest/1.16.0/MODULE.bazel": "a175623c69e94fca4ca7acbc12031e637b0c489318cd4805606981d4d7adb34a",
|
||||
"https://bcr.bazel.build/modules/googletest/1.16.0/source.json": "dd011b202542efcd4c0e3df34b1558d41598c6f287846728315ded5f7984b77a",
|
||||
"https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075",
|
||||
"https://bcr.bazel.build/modules/jsoncpp/1.9.5/source.json": "4108ee5085dd2885a341c7fab149429db457b3169b86eb081fa245eadf69169d",
|
||||
"https://bcr.bazel.build/modules/libpfm/4.11.0/MODULE.bazel": "45061ff025b301940f1e30d2c16bea596c25b176c8b6b3087e92615adbd52902",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.11/source.json": "f7e188b79ebedebfe75e9e1d098b8845226c7992b307e28e1496f23112e8fc29",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc",
|
||||
"https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7",
|
||||
"https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c",
|
||||
"https://bcr.bazel.build/modules/protobuf/27.0/source.json": "1acf3d080c728d42f423fde5422fd0a1a24f44c15908124ce12363a253384193",
|
||||
"https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0",
|
||||
"https://bcr.bazel.build/modules/protobuf/3.19.6/MODULE.bazel": "9233edc5e1f2ee276a60de3eaa47ac4132302ef9643238f23128fea53ea12858",
|
||||
"https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e",
|
||||
"https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34",
|
||||
"https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/source.json": "6900fdc8a9e95866b8c0d4ad4aba4d4236317b5c1cd04c502df3f0d33afed680",
|
||||
"https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206",
|
||||
"https://bcr.bazel.build/modules/re2/2024-07-02/MODULE.bazel": "0eadc4395959969297cbcf31a249ff457f2f1d456228c67719480205aa306daa",
|
||||
"https://bcr.bazel.build/modules/re2/2024-07-02/source.json": "547d0111a9d4f362db32196fef805abbf3676e8d6afbe44d395d87816c1130ca",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.17/MODULE.bazel": "2ae1d8f4238ec67d7185d8861cb0a2cdf4bc608697c331b95bf990e69b62e64a",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.1.1/source.json": "d61627377bd7dd1da4652063e368d9366fc9a73920bfa396798ad92172cf645c",
|
||||
"https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6",
|
||||
"https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
|
||||
"https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.6.5/MODULE.bazel": "481164be5e02e4cab6e77a36927683263be56b7e36fef918b458d7a8a1ebadb1",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.6.5/source.json": "a805b889531d1690e3c72a7a7e47a870d00323186a9904b36af83aa3d053ee8d",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.1/source.json": "5abb45cc9beb27b77aec6a65a11855ef2b55d95dfdc358e9f312b78ae0ba32d5",
|
||||
"https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0",
|
||||
"https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d",
|
||||
"https://bcr.bazel.build/modules/rules_license/1.0.0/MODULE.bazel": "a7fda60eefdf3d8c827262ba499957e4df06f659330bbe6cdbdb975b768bb65c",
|
||||
"https://bcr.bazel.build/modules/rules_license/1.0.0/source.json": "a52c89e54cc311196e478f8382df91c15f7a2bfdf4c6cd0e2675cc2ff0b56efb",
|
||||
"https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc",
|
||||
"https://bcr.bazel.build/modules/rules_pkg/0.7.0/source.json": "c2557066e0c0342223ba592510ad3d812d4963b9024831f7f66fd0584dd8c66c",
|
||||
"https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06",
|
||||
"https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7",
|
||||
"https://bcr.bazel.build/modules/rules_proto/6.0.0-rc1/MODULE.bazel": "1e5b502e2e1a9e825eef74476a5a1ee524a92297085015a052510b09a1a09483",
|
||||
"https://bcr.bazel.build/modules/rules_proto/6.0.0-rc1/source.json": "8d8448e71706df7450ced227ca6b3812407ff5e2ccad74a43a9fbe79c84e34e0",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.22.1/MODULE.bazel": "26114f0c0b5e93018c0c066d6673f1a2c3737c7e90af95eff30cfee38d0bbac7",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.25.0/MODULE.bazel": "72f1506841c920a1afec76975b35312410eea3aa7b63267436bfb1dd91d2d382",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.33.2/MODULE.bazel": "3e036c4ad8d804a4dad897d333d8dce200d943df4827cb849840055be8d2e937",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.33.2/source.json": "e539592cd3aae4492032cecea510e46ca16eeb972271560b922cae9893944e2f",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.3/source.json": "cd53fe968dc8cd98197c052db3db6d82562960c87b61e7a90ee96f8e4e0dda97",
|
||||
"https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43",
|
||||
"https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0",
|
||||
"https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27",
|
||||
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79",
|
||||
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d"
|
||||
},
|
||||
"selectedYankedVersions": {},
|
||||
"moduleExtensions": {
|
||||
"@@apple_support~//crosstool:setup.bzl%apple_cc_configure_extension": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "ltCGFbl/LQQZXn/LEMXfKX7pGwyqNiOCHcmiQW0tmjM=",
|
||||
"usagesDigest": "2Jj0sTGzjx2KfYRjWYbL6DZ1bi8HL2roIAGfOViiul8=",
|
||||
"recordedFileInputs": {},
|
||||
"recordedDirentsInputs": {},
|
||||
"envVariables": {},
|
||||
"generatedRepoSpecs": {
|
||||
"local_config_apple_cc_toolchains": {
|
||||
"bzlFile": "@@apple_support~//crosstool:setup.bzl",
|
||||
"ruleClassName": "_apple_cc_autoconf_toolchains",
|
||||
"attributes": {}
|
||||
},
|
||||
"local_config_apple_cc": {
|
||||
"bzlFile": "@@apple_support~//crosstool:setup.bzl",
|
||||
"ruleClassName": "_apple_cc_autoconf",
|
||||
"attributes": {}
|
||||
}
|
||||
},
|
||||
"recordedRepoMappingEntries": [
|
||||
[
|
||||
"apple_support~",
|
||||
"bazel_tools",
|
||||
"bazel_tools"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
306
src/PORTING.md
306
src/PORTING.md
@@ -1,306 +0,0 @@
|
||||
# Porting from OpenSSL to BoringSSL
|
||||
|
||||
BoringSSL is an OpenSSL derivative and is mostly source-compatible, for the
|
||||
subset of OpenSSL retained. Libraries ideally need little to no changes for
|
||||
BoringSSL support, provided they do not use removed APIs. In general, see if the
|
||||
library compiles and, on failure, consult the documentation in the header files
|
||||
and see if problematic features can be removed.
|
||||
|
||||
BoringSSL's `OPENSSL_VERSION_NUMBER` matches the OpenSSL version it targets.
|
||||
Version checks for OpenSSL should ideally work as-is in BoringSSL. BoringSSL
|
||||
also defines upstream's `OPENSSL_NO_*` feature macros corresponding to removed
|
||||
features. If the preprocessor is needed, use these version checks or feature
|
||||
macros where possible, especially when patching third-party projects. Such
|
||||
patches are more generally useful to OpenSSL consumers and thus more
|
||||
appropriate to send upstream.
|
||||
|
||||
In some cases, BoringSSL-specific code may be necessary. Use the
|
||||
`OPENSSL_IS_BORINGSSL` preprocessor macro in `#ifdef`s. However, first contact
|
||||
the BoringSSL maintainers about the missing APIs. We will typically add
|
||||
compatibility functions for convenience. In particular, *contact BoringSSL
|
||||
maintainers before working around missing OpenSSL 1.1.0 accessors*. BoringSSL
|
||||
was originally derived from OpenSSL 1.0.2 but now targets OpenSSL 1.1.0. Some
|
||||
newer APIs may be missing but can be added on request. (Not all projects have
|
||||
been ported to OpenSSL 1.1.0, so BoringSSL also remains largely compatible with
|
||||
OpenSSL 1.0.2.)
|
||||
|
||||
The `OPENSSL_IS_BORINGSSL` macro may also be used to distinguish OpenSSL from
|
||||
BoringSSL in configure scripts. Do not use the presence or absence of particular
|
||||
symbols to detect BoringSSL.
|
||||
|
||||
Note: BoringSSL does *not* have a stable API or ABI. It must be updated with its
|
||||
consumers. It is not suitable for, say, a system library in a traditional Linux
|
||||
distribution. For instance, Chromium statically links the specific revision of
|
||||
BoringSSL it was built against. Likewise, Android's system-internal copy of
|
||||
BoringSSL is not exposed by the NDK and must not be used by third-party
|
||||
applications.
|
||||
|
||||
|
||||
## Major API changes
|
||||
|
||||
### Integer types
|
||||
|
||||
Some APIs have been converted to use `size_t` for consistency and to avoid
|
||||
integer overflows at the API boundary. (Existing logic uses a mismash of `int`,
|
||||
`long`, and `unsigned`.) For the most part, implicit casts mean that existing
|
||||
code continues to compile. In some cases, this may require BoringSSL-specific
|
||||
code, particularly to avoid compiler warnings.
|
||||
|
||||
Most notably, the `STACK_OF(T)` types have all been converted to use `size_t`
|
||||
instead of `int` for indices and lengths.
|
||||
|
||||
### Reference counts and opaque types
|
||||
|
||||
Some external consumers increment reference counts directly by calling
|
||||
`CRYPTO_add` with the corresponding `CRYPTO_LOCK_*` value. These APIs no longer
|
||||
exist in BoringSSL. Instead, code which increments reference counts should call
|
||||
the corresponding `FOO_up_ref` function, such as `EVP_PKEY_up_ref`.
|
||||
|
||||
BoringSSL also hides some structs which were previously exposed in OpenSSL
|
||||
1.0.2, particularly in libssl. Use the relevant accessors instead.
|
||||
|
||||
Note that some of these APIs were added in OpenSSL 1.1.0, so projects which do
|
||||
not yet support 1.1.0 may need additional `#ifdef`s. Projects supporting OpenSSL
|
||||
1.1.0 should not require modification.
|
||||
|
||||
### Error codes
|
||||
|
||||
OpenSSL's errors are extremely specific, leaking internals of the library,
|
||||
including even a function code for the function which emitted the error! As some
|
||||
logic in BoringSSL has been rewritten, code which conditions on the error may
|
||||
break (grep for `ERR_GET_REASON` and `ERR_GET_FUNC`). This danger also exists
|
||||
when upgrading OpenSSL versions.
|
||||
|
||||
Where possible, avoid conditioning on the exact error reason. Otherwise, a
|
||||
BoringSSL `#ifdef` may be necessary. Exactly how best to resolve this issue is
|
||||
still being determined. It's possible some new APIs will be added in the future.
|
||||
|
||||
Function codes have been completely removed. Remove code which conditions on
|
||||
these as it will break with the slightest change in the library, OpenSSL or
|
||||
BoringSSL.
|
||||
|
||||
### `*_ctrl` functions
|
||||
|
||||
Some OpenSSL APIs are implemented with `ioctl`-style functions such as
|
||||
`SSL_ctrl` and `EVP_PKEY_CTX_ctrl`, combined with convenience macros, such as
|
||||
|
||||
# define SSL_CTX_set_mode(ctx,op) \
|
||||
SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
|
||||
|
||||
In BoringSSL, these macros have been replaced with proper functions. The
|
||||
underlying `_ctrl` functions have been removed.
|
||||
|
||||
For convenience, `SSL_CTRL_*` values are retained as macros to `doesnt_exist` so
|
||||
existing code which uses them (or the wrapper macros) in `#ifdef` expressions
|
||||
will continue to function. However, the macros themselves will not work.
|
||||
|
||||
Switch any `*_ctrl` callers to the macro/function versions. This works in both
|
||||
OpenSSL and BoringSSL. Note that BoringSSL's function versions will be
|
||||
type-checked and may require more care with types. See the end of this
|
||||
document for a table of functions to use.
|
||||
|
||||
### HMAC `EVP_PKEY`s
|
||||
|
||||
`EVP_PKEY_HMAC` is removed. Use the `HMAC_*` functions in `hmac.h` instead. This
|
||||
is compatible with OpenSSL.
|
||||
|
||||
### DSA `EVP_PKEY`s
|
||||
|
||||
`EVP_PKEY_DSA` is deprecated. It is currently still possible to parse DER into a
|
||||
DSA `EVP_PKEY`, but signing or verifying with those objects will not work.
|
||||
|
||||
### DES
|
||||
|
||||
The `DES_cblock` type has been switched from an array to a struct to avoid the
|
||||
pitfalls around array types in C. Where features which require DES cannot be
|
||||
disabled, BoringSSL-specific codepaths may be necessary.
|
||||
|
||||
### TLS renegotiation
|
||||
|
||||
OpenSSL enables TLS renegotiation by default and accepts renegotiation requests
|
||||
from the peer transparently. Renegotiation is an extremely problematic protocol
|
||||
feature, so BoringSSL rejects peer renegotiations by default.
|
||||
|
||||
To enable renegotiation, call `SSL_set_renegotiate_mode` and set it to
|
||||
`ssl_renegotiate_once` or `ssl_renegotiate_freely`. Renegotiation is only
|
||||
supported as a client in TLS and the HelloRequest must be received at a
|
||||
quiet point in the application protocol. This is sufficient to support the
|
||||
common use of requesting a new client certificate between an HTTP request and
|
||||
response in (unpipelined) HTTP/1.1.
|
||||
|
||||
Things which do not work:
|
||||
|
||||
* There is no support for renegotiation as a server. (Attempts by clients will
|
||||
result in a fatal alert so that ClientHello messages cannot be used to flood
|
||||
a server and escape higher-level limits.)
|
||||
|
||||
* There is no support for renegotiation in DTLS.
|
||||
|
||||
* There is no support for initiating renegotiation; `SSL_renegotiate` always
|
||||
fails and `SSL_set_state` does nothing.
|
||||
|
||||
* Interleaving application data with the new handshake is forbidden.
|
||||
|
||||
* If a HelloRequest is received while `SSL_write` has unsent application data,
|
||||
the renegotiation is rejected.
|
||||
|
||||
* Renegotiation does not participate in session resumption. The client will
|
||||
not offer a session on renegotiation or resume any session established by a
|
||||
renegotiation handshake.
|
||||
|
||||
* The server may not change its certificate in the renegotiation. This mitigates
|
||||
the [triple handshake attack](https://mitls.org/pages/attacks/3SHAKE). Any new
|
||||
stapled OCSP response and SCT list will be ignored. As no authentication state
|
||||
may change, BoringSSL will not re-verify the certificate on a renegotiation.
|
||||
Callbacks such as `SSL_CTX_set_custom_verify` will only run on the initial
|
||||
handshake.
|
||||
|
||||
### Lowercase hexadecimal
|
||||
|
||||
BoringSSL's `BN_bn2hex` function uses lowercase hexadecimal digits instead of
|
||||
uppercase. Some code may require changes to avoid being sensitive to this
|
||||
difference.
|
||||
|
||||
### Legacy ASN.1 functions
|
||||
|
||||
OpenSSL's ASN.1 stack uses `d2i` functions for parsing. They have the form:
|
||||
|
||||
RSA *d2i_RSAPrivateKey(RSA **out, const uint8_t **inp, long len);
|
||||
|
||||
In addition to returning the result, OpenSSL places it in `*out` if `out` is
|
||||
not `NULL`. On input, if `*out` is not `NULL`, OpenSSL will usually (but not
|
||||
always) reuse that object rather than allocating a new one. In BoringSSL, these
|
||||
functions will always allocate a new object and free the previous one.
|
||||
|
||||
Ensure that callers do not rely on this object reuse behavior. It is
|
||||
recommended to avoid the `out` parameter completely and always pass in `NULL`.
|
||||
In most cases, even in OpenSSL, relying on object reuse is not safe because, on
|
||||
parse error, OpenSSL will free the reused object. Note that less error-prone
|
||||
APIs are available for BoringSSL-specific code (see below).
|
||||
|
||||
### Memory allocation
|
||||
|
||||
OpenSSL provides wrappers `OPENSSL_malloc` and `OPENSSL_free` over the standard
|
||||
`malloc` and `free`. Memory allocated by OpenSSL should be released with
|
||||
`OPENSSL_free`, not the standard `free`. However, by default, they are
|
||||
implemented directly using `malloc` and `free`, so code which mixes them up
|
||||
usually works.
|
||||
|
||||
In BoringSSL, these functions maintain additional book-keeping to zero memory
|
||||
on `OPENSSL_free`, so any mixups must be fixed.
|
||||
|
||||
## Optional BoringSSL-specific simplifications
|
||||
|
||||
BoringSSL makes some changes to OpenSSL which simplify the API but remain
|
||||
compatible with OpenSSL consumers. In general, consult the BoringSSL
|
||||
documentation for any functions in new BoringSSL-only code.
|
||||
|
||||
### Return values
|
||||
|
||||
Most OpenSSL APIs return 1 on success and either 0 or -1 on failure. BoringSSL
|
||||
has narrowed most of these to 1 on success and 0 on failure. BoringSSL-specific
|
||||
code may take advantage of the less error-prone APIs and use `!` to check for
|
||||
errors.
|
||||
|
||||
### Initialization
|
||||
|
||||
OpenSSL has a number of different initialization functions for setting up error
|
||||
strings and loading algorithms, etc. All of these functions still exist in
|
||||
BoringSSL for convenience, but they do nothing and are not necessary. BoringSSL
|
||||
internally initializes itself as needed.
|
||||
|
||||
### Threading
|
||||
|
||||
OpenSSL provides a number of APIs to configure threading callbacks and set up
|
||||
locks. Without initializing these, the library is not thread-safe. Configuring
|
||||
these does nothing in BoringSSL. Instead, BoringSSL calls pthreads and the
|
||||
corresponding Windows APIs internally and is always thread-safe where the API
|
||||
guarantees it.
|
||||
|
||||
### ASN.1
|
||||
|
||||
BoringSSL is in the process of deprecating OpenSSL's `d2i` and `i2d` in favor of
|
||||
new functions using the much less error-prone `CBS` and `CBB` types.
|
||||
BoringSSL-only code should use those functions where available.
|
||||
|
||||
|
||||
## Replacements for `CTRL` values
|
||||
|
||||
When porting code which uses `SSL_CTX_ctrl` or `SSL_ctrl`, use the replacement
|
||||
functions below. If a function has both `SSL_CTX` and `SSL` variants, only the
|
||||
`SSL_CTX` version is listed.
|
||||
|
||||
Note some values correspond to multiple functions depending on the `larg`
|
||||
parameter.
|
||||
|
||||
`CTRL` value | Replacement function(s)
|
||||
-------------|-------------------------
|
||||
`DTLS_CTRL_GET_TIMEOUT` | `DTLSv1_get_timeout`
|
||||
`DTLS_CTRL_HANDLE_TIMEOUT` | `DTLSv1_handle_timeout`
|
||||
`SSL_CTRL_CHAIN` | `SSL_CTX_set0_chain` or `SSL_CTX_set1_chain`
|
||||
`SSL_CTRL_CHAIN_CERT` | `SSL_add0_chain_cert` or `SSL_add1_chain_cert`
|
||||
`SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS` | `SSL_CTX_clear_extra_chain_certs`
|
||||
`SSL_CTRL_CLEAR_MODE` | `SSL_CTX_clear_mode`
|
||||
`SSL_CTRL_CLEAR_OPTIONS` | `SSL_CTX_clear_options`
|
||||
`SSL_CTRL_EXTRA_CHAIN_CERT` | `SSL_CTX_add_extra_chain_cert`
|
||||
`SSL_CTRL_GET_CHAIN_CERTS` | `SSL_CTX_get0_chain_certs`
|
||||
`SSL_CTRL_GET_CLIENT_CERT_TYPES` | `SSL_get0_certificate_types`
|
||||
`SSL_CTRL_GET_EXTRA_CHAIN_CERTS` | `SSL_CTX_get_extra_chain_certs` or `SSL_CTX_get_extra_chain_certs_only`
|
||||
`SSL_CTRL_GET_MAX_CERT_LIST` | `SSL_CTX_get_max_cert_list`
|
||||
`SSL_CTRL_GET_NUM_RENEGOTIATIONS` | `SSL_num_renegotiations`
|
||||
`SSL_CTRL_GET_READ_AHEAD` | `SSL_CTX_get_read_ahead`
|
||||
`SSL_CTRL_GET_RI_SUPPORT` | `SSL_get_secure_renegotiation_support`
|
||||
`SSL_CTRL_GET_SESSION_REUSED` | `SSL_session_reused`
|
||||
`SSL_CTRL_GET_SESS_CACHE_MODE` | `SSL_CTX_get_session_cache_mode`
|
||||
`SSL_CTRL_GET_SESS_CACHE_SIZE` | `SSL_CTX_sess_get_cache_size`
|
||||
`SSL_CTRL_GET_TLSEXT_TICKET_KEYS` | `SSL_CTX_get_tlsext_ticket_keys`
|
||||
`SSL_CTRL_GET_TOTAL_RENEGOTIATIONS` | `SSL_total_renegotiations`
|
||||
`SSL_CTRL_MODE` | `SSL_CTX_get_mode` or `SSL_CTX_set_mode`
|
||||
`SSL_CTRL_NEED_TMP_RSA` | `SSL_CTX_need_tmp_RSA` is equivalent, but [*do not use this function*](https://freakattack.com/). (It is a no-op in BoringSSL.)
|
||||
`SSL_CTRL_OPTIONS` | `SSL_CTX_get_options` or `SSL_CTX_set_options`
|
||||
`SSL_CTRL_SESS_NUMBER` | `SSL_CTX_sess_number`
|
||||
`SSL_CTRL_SET_CURVES` | `SSL_CTX_set1_curves`
|
||||
`SSL_CTRL_SET_ECDH_AUTO` | `SSL_CTX_set_ecdh_auto`
|
||||
`SSL_CTRL_SET_MAX_CERT_LIST` | `SSL_CTX_set_max_cert_list`
|
||||
`SSL_CTRL_SET_MAX_SEND_FRAGMENT` | `SSL_CTX_set_max_send_fragment`
|
||||
`SSL_CTRL_SET_MSG_CALLBACK` | `SSL_set_msg_callback`
|
||||
`SSL_CTRL_SET_MSG_CALLBACK_ARG` | `SSL_set_msg_callback_arg`
|
||||
`SSL_CTRL_SET_MTU` | `SSL_set_mtu`
|
||||
`SSL_CTRL_SET_READ_AHEAD` | `SSL_CTX_set_read_ahead`
|
||||
`SSL_CTRL_SET_SESS_CACHE_MODE` | `SSL_CTX_set_session_cache_mode`
|
||||
`SSL_CTRL_SET_SESS_CACHE_SIZE` | `SSL_CTX_sess_set_cache_size`
|
||||
`SSL_CTRL_SET_TLSEXT_HOSTNAME` | `SSL_set_tlsext_host_name`
|
||||
`SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG` | `SSL_CTX_set_tlsext_servername_arg`
|
||||
`SSL_CTRL_SET_TLSEXT_SERVERNAME_CB` | `SSL_CTX_set_tlsext_servername_callback`
|
||||
`SSL_CTRL_SET_TLSEXT_TICKET_KEYS` | `SSL_CTX_set_tlsext_ticket_keys`
|
||||
`SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB` | `SSL_CTX_set_tlsext_ticket_key_cb`
|
||||
`SSL_CTRL_SET_TMP_DH` | `SSL_CTX_set_tmp_dh`
|
||||
`SSL_CTRL_SET_TMP_DH_CB` | `SSL_CTX_set_tmp_dh_callback`
|
||||
`SSL_CTRL_SET_TMP_ECDH` | `SSL_CTX_set_tmp_ecdh`
|
||||
`SSL_CTRL_SET_TMP_ECDH_CB` | `SSL_CTX_set_tmp_ecdh_callback`
|
||||
`SSL_CTRL_SET_TMP_RSA` | `SSL_CTX_set_tmp_rsa` is equivalent, but [*do not use this function*](https://freakattack.com/). (It is a no-op in BoringSSL.)
|
||||
`SSL_CTRL_SET_TMP_RSA_CB` | `SSL_CTX_set_tmp_rsa_callback` is equivalent, but [*do not use this function*](https://freakattack.com/). (It is a no-op in BoringSSL.)
|
||||
|
||||
## Significant API additions
|
||||
|
||||
In some places, BoringSSL has added significant APIs. Use of these APIs goes beyound “porting” and means giving up on OpenSSL compatibility.
|
||||
|
||||
One example of this has already been mentioned: the [CBS and CBB](https://commondatastorage.googleapis.com/chromium-boringssl-docs/bytestring.h.html) functions should be used whenever parsing or serialising data.
|
||||
|
||||
### CRYPTO\_BUFFER
|
||||
|
||||
With the standard OpenSSL APIs, when making many TLS connections, the certificate data for each connection is retained in memory in an expensive `X509` structure. Additionally, common certificates often appear in the chains for multiple connections and are needlessly duplicated in memory.
|
||||
|
||||
A [`CRYPTO_BUFFER`](https://commondatastorage.googleapis.com/chromium-boringssl-docs/pool.h.html) is just an opaque byte string. A `CRYPTO_BUFFER_POOL` is an intern table for these buffers, i.e. it ensures that only a single copy of any given byte string is kept for each pool.
|
||||
|
||||
The function `TLS_with_buffers_method` returns an `SSL_METHOD` that avoids creating `X509` objects for certificates. Additionally, `SSL_CTX_set0_buffer_pool` can be used to install a pool on an `SSL_CTX` so that certificates can be deduplicated across connections and across `SSL_CTX`s.
|
||||
|
||||
When using these functions, the application also needs to ensure that it doesn't call other functions that deal with `X509` or `X509_NAME` objects. For example, `SSL_get_peer_certificate` or `SSL_get_peer_cert_chain`. Doing so will trigger an assert in debug mode and will result in NULLs in release mode. Instead, call the buffer-based alternatives such as `SSL_get0_peer_certificates`. (See [ssl.h](https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html) for functions taking or returning `CRYPTO_BUFFER`.) The buffer-based alternative functions will work even when not using `TLS_with_buffers_method`, thus application code can transition gradually.
|
||||
|
||||
In order to use buffers, the application code also needs to implement its own certificate verification using `SSL_[CTX_]set_custom_verify`. Otherwise all connections will fail with a verification error. Auto-chaining is also disabled when using buffers.
|
||||
|
||||
Once those changes have been completed, the whole of the OpenSSL X.509 and ASN.1 code should be eliminated by the linker if BoringSSL is linked statically.
|
||||
|
||||
### Asynchronous and opaque private keys
|
||||
|
||||
OpenSSL offers the ENGINE API for implementing opaque private keys (i.e. private keys where software only has oracle access because the secrets are held in special hardware or on another machine). While the ENGINE API has been mostly removed from BoringSSL, it is still possible to support opaque keys in this way. However, when using such keys with TLS and BoringSSL, you should strongly prefer using `SSL_PRIVATE_KEY_METHOD` via `SSL[_CTX]_set_private_key_method`. This allows a handshake to be suspended while the private operation is in progress. It also supports more forms of opaque key as it exposes higher-level information about the operation to be performed.
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
|
||||
<!--
|
||||
This file is for using BoringSSL in Apple ecosystems. You may have to point
|
||||
Xcode at it yourself. See
|
||||
https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
|
||||
-->
|
||||
|
||||
<dict>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,45 +0,0 @@
|
||||
# BoringSSL
|
||||
|
||||
BoringSSL is a fork of OpenSSL that is designed to meet Google's needs.
|
||||
|
||||
Although BoringSSL is an open source project, it is not intended for general
|
||||
use, as OpenSSL is. We don't recommend that third parties depend upon it. Doing
|
||||
so is likely to be frustrating because there are no guarantees of API or ABI
|
||||
stability.
|
||||
|
||||
Programs ship their own copies of BoringSSL when they use it and we update
|
||||
everything as needed when deciding to make API changes. This allows us to
|
||||
mostly avoid compromises in the name of compatibility. It works for us, but it
|
||||
may not work for you.
|
||||
|
||||
BoringSSL arose because Google used OpenSSL for many years in various ways and,
|
||||
over time, built up a large number of patches that were maintained while
|
||||
tracking upstream OpenSSL. As Google's product portfolio became more complex,
|
||||
more copies of OpenSSL sprung up and the effort involved in maintaining all
|
||||
these patches in multiple places was growing steadily.
|
||||
|
||||
Currently BoringSSL is the SSL library in Chrome/Chromium, Android (but it's
|
||||
not part of the NDK) and a number of other apps/programs.
|
||||
|
||||
Project links:
|
||||
|
||||
* [API documentation](https://commondatastorage.googleapis.com/chromium-boringssl-docs/headers.html)
|
||||
* [Issue tracker](https://crbug.com/boringssl)
|
||||
* [Filing new (public) issues](https://crbug.com/boringssl/new)
|
||||
* [CI](https://ci.chromium.org/p/boringssl/g/main/console)
|
||||
* [Code review](https://boringssl-review.googlesource.com)
|
||||
|
||||
To file a security issue, use the [Chromium process](https://www.chromium.org/Home/chromium-security/reporting-security-bugs/) and mention in the report this is for BoringSSL. You can ignore the parts of the process that are specific to Chromium/Chrome.
|
||||
|
||||
There are other files in this directory which might be helpful:
|
||||
|
||||
* [PORTING.md](./PORTING.md): how to port OpenSSL-using code to BoringSSL.
|
||||
* [BUILDING.md](./BUILDING.md): how to build BoringSSL
|
||||
* [INCORPORATING.md](./INCORPORATING.md): how to incorporate BoringSSL into a project.
|
||||
* [API-CONVENTIONS.md](./API-CONVENTIONS.md): general API conventions for BoringSSL consumers and developers.
|
||||
* [STYLE.md](./STYLE.md): rules and guidelines for coding style.
|
||||
* include/openssl: public headers with API documentation in comments. Also [available online](https://commondatastorage.googleapis.com/chromium-boringssl-docs/headers.html).
|
||||
* [FUZZING.md](./FUZZING.md): information about fuzzing BoringSSL.
|
||||
* [CONTRIBUTING.md](./CONTRIBUTING.md): how to contribute to BoringSSL.
|
||||
* [BREAKING-CHANGES.md](./BREAKING-CHANGES.md): notes on potentially-breaking changes.
|
||||
* [SANDBOXING.md](./SANDBOXING.md): notes on using BoringSSL in a sandboxed environment.
|
||||
@@ -1,140 +0,0 @@
|
||||
# Using BoringSSL in a Sandbox
|
||||
|
||||
Sandboxes are a valuable tool for securing applications, so BoringSSL aims to
|
||||
support them. However, it is difficult to make concrete API guarantees with
|
||||
sandboxes. Sandboxes remove low-level OS resources and system calls, which
|
||||
breaks platform abstractions. A syscall-filtering sandbox may, for instance, be
|
||||
sensitive to otherwise non-breaking changes to use newer syscalls
|
||||
in either BoringSSL or the C library.
|
||||
|
||||
Some functions in BoringSSL, such as `BIO_new_file`, inherently need OS
|
||||
resources like the filesystem. We assume that sandboxed consumers either avoid
|
||||
those functions or make necessary resources available. Other functions like
|
||||
`RSA_sign` are purely computational, but still have some baseline OS
|
||||
dependencies.
|
||||
|
||||
Sandboxes which drop privileges partway through a process's lifetime are
|
||||
additionally sensitive to OS resources retained across the transitions. For
|
||||
instance, if a library function internally opened and retained a handle to the
|
||||
user's home directory, and then the application called `chroot`, that handle
|
||||
would be a sandbox escape.
|
||||
|
||||
This document attempts to describe these baseline OS dependencies and long-lived
|
||||
internal resources. These dependencies may change over time, but we aim to
|
||||
[work with sandboxed consumers](./BREAKING-CHANGES.md) when they do. However,
|
||||
each sandbox imposes different constraints, so, above all, sandboxed consumers
|
||||
must have ample test coverage to detect issues as they arise.
|
||||
|
||||
## Baseline dependencies
|
||||
|
||||
Callers must assume that any BoringSSL function may perform one of the following
|
||||
operations:
|
||||
|
||||
### Memory allocation
|
||||
|
||||
Any BoringSSL function may allocate memory via `malloc` and related functions.
|
||||
|
||||
### Thread synchronization
|
||||
|
||||
Any BoringSSL function may call into the platform's thread synchronization
|
||||
primitives, including read/write locks and the equivalent of `pthread_once`.
|
||||
These must succeed, or BoringSSL will abort the process. Callers, however, can
|
||||
assume that BoringSSL functions will not spawn internal threads, unless
|
||||
otherwise documented.
|
||||
|
||||
Syscall-filtering sandboxes should note that BoringSSL uses `pthread_rwlock_t`
|
||||
on POSIX systems, which is less common and may not be part of other libraries'
|
||||
syscall surface. Additionally, thread synchronization primitives usually have an
|
||||
atomics-based fast path. If a sandbox blocks a necessary pthreads syscall, it
|
||||
may not show up in testing without lock contention.
|
||||
|
||||
### Standard error
|
||||
|
||||
Any BoringSSL function may write to `stderr` or file descriptor
|
||||
`STDERR_FILENO` (2), either via `FILE` APIs or low-level functions like `write`.
|
||||
Writes to `stderr` may fail, but there must some file at `STDERR_FILENO` which
|
||||
will tolerate error messages from BoringSSL. (The file descriptor must be
|
||||
allocated so calls to `open` do not accidentally open something else there.)
|
||||
|
||||
Note some C standard library implementations also log to `stderr`, so callers
|
||||
should ensure this regardless.
|
||||
|
||||
### Entropy
|
||||
|
||||
Any BoringSSL function may draw entropy from the OS. On Windows, this uses
|
||||
`RtlGenRandom` and, on POSIX systems, this uses `getrandom`, `getentropy`, or a
|
||||
`read` from a file descriptor to `/dev/urandom`. These operations must succeed
|
||||
or BoringSSL will abort the process. BoringSSL only probes for `getrandom`
|
||||
support once and assumes support is consistent for the lifetime of the address
|
||||
space (and any copies made via `fork`). If a syscall-filtering sandbox is
|
||||
enabled partway through this lifetime and changes whether `getrandom` works,
|
||||
BoringSSL may abort the process. Sandboxes are recommended to allow
|
||||
`getrandom`.
|
||||
|
||||
Note even deterministic algorithms may require OS entropy. For example,
|
||||
RSASSA-PKCS1-v1_5 is deterministic, but BoringSSL draws entropy to implement
|
||||
RSA blinding.
|
||||
|
||||
Entropy gathering additionally has some initialization dependencies described in
|
||||
the following section.
|
||||
|
||||
## Initialization
|
||||
|
||||
BoringSSL has some uncommon OS dependencies which are only used once to
|
||||
initialize some state. Sandboxes which drop privileges after some setup work may
|
||||
use `CRYPTO_pre_sandbox_init` to initialize this state ahead of time. Otherwise,
|
||||
callers must assume any BoringSSL function may depend on these resources, in
|
||||
addition to the operations above.
|
||||
|
||||
### CPU capabilities
|
||||
|
||||
On Linux ARM platforms, BoringSSL depends on OS APIs to query CPU capabilities.
|
||||
32-bit and 64-bit ARM both depend on the `getauxval` function. 32-bit ARM, to
|
||||
work around bugs in older Android devices, may additionally read
|
||||
`/proc/cpuinfo`.
|
||||
|
||||
On 64-bit Apple ARM platforms, BoringSSL needs to query `hw.optional.*` sysctls.
|
||||
|
||||
If querying CPU capabilities fails, BoringSSL will still function, but may not
|
||||
perform as well.
|
||||
|
||||
### Entropy
|
||||
|
||||
On Linux systems without a working `getrandom`, drawing entropy from the OS
|
||||
additionally requires opening `/dev/urandom`. If this fails, BoringSSL will
|
||||
abort the process. BoringSSL retains the resulting file descriptor, even across
|
||||
privilege transitions.
|
||||
|
||||
### Fork protection
|
||||
|
||||
On Linux, BoringSSL allocates a page and calls `madvise` with `MADV_WIPEONFORK`
|
||||
to protect single-use state from `fork`. This operation must not crash, but if
|
||||
it fails, BoringSSL will use alternate fork-safety strategies, potentially at a
|
||||
performance cost. If it succeeds, BoringSSL assumes `MADV_WIPEONFORK` is
|
||||
functional and relies on it for fork-safety. Sandboxes must not report success
|
||||
if they ignore the `MADV_WIPEONFORK` flag. As of writing, QEMU will ignore
|
||||
`madvise` calls and report success, so BoringSSL detects this by calling
|
||||
`madvise` with -1. Sandboxes must cleanly report an error instead of crashing.
|
||||
|
||||
Once initialized, this mechanism does not require system calls in the steady
|
||||
state, though note the configured page will be inherited across privilege
|
||||
transitions.
|
||||
|
||||
## C and C++ standard library
|
||||
|
||||
BoringSSL depends on the C and C++ standard libraries which, themselves, do not
|
||||
make any guarantees about sandboxes. If it produces the correct answer and has
|
||||
no observable invalid side effects, it is possible, though unreasonable, for
|
||||
`memcmp` to create and close a socket.
|
||||
|
||||
BoringSSL assumes that functions in the C and C++ library only have the platform
|
||||
dependencies which would be "reasonable". For instance, a function in BoringSSL
|
||||
which aims not to open files will still freely call any libc memory and
|
||||
string functions.
|
||||
|
||||
Note some C functions, such as `strerror`, may read files relating to the user's
|
||||
locale. BoringSSL may trigger these paths and assumes the sandbox environment
|
||||
will tolerate this. BoringSSL additionally cannot make guarantees about which
|
||||
system calls are used by standard library's syscall wrappers. In some cases, the
|
||||
compiler may add dependencies. (Some C++ language features emit locking code.)
|
||||
Syscall-filtering sandboxes may need updates as these dependencies change.
|
||||
233
src/STYLE.md
233
src/STYLE.md
@@ -1,233 +0,0 @@
|
||||
# BoringSSL Style Guide
|
||||
|
||||
BoringSSL usually follows the
|
||||
[Google C++ style guide](https://google.github.io/styleguide/cppguide.html),
|
||||
The rest of this document describes differences and clarifications on
|
||||
top of the base guide.
|
||||
|
||||
|
||||
## Legacy code
|
||||
|
||||
As a derivative of OpenSSL, BoringSSL contains a lot of legacy code that
|
||||
does not follow this style guide. Particularly where public API is
|
||||
concerned, balance consistency within a module with the benefits of a
|
||||
given rule. Module-wide deviations on naming should be respected while
|
||||
integer and return value conventions take precedence over consistency.
|
||||
|
||||
Modules from OpenSSL's legacy ASN.1 and X.509 stack are retained for
|
||||
compatibility and left largely unmodified. To ease importing patches from
|
||||
upstream, they match OpenSSL's new indentation style. For Emacs,
|
||||
`doc/openssl-c-indent.el` from OpenSSL may be helpful in this.
|
||||
|
||||
|
||||
## Language
|
||||
|
||||
The majority of the project is in C, so C++-specific rules in the
|
||||
Google style guide do not apply. Support for C99 features depends on
|
||||
our target platforms. Typically, Chromium's target MSVC is the most
|
||||
restrictive.
|
||||
|
||||
Variable declarations in the middle of a function or inside a `for` loop are
|
||||
allowed and preferred where possible. Note that the common `goto err` cleanup
|
||||
pattern requires lifting some variable declarations.
|
||||
|
||||
Comments should be `// C99-style` for consistency with C++.
|
||||
|
||||
When declaring pointer types, `*` should be placed next to the variable name,
|
||||
not the type. So
|
||||
|
||||
uint8_t *ptr;
|
||||
|
||||
not
|
||||
|
||||
uint8_t* ptr;
|
||||
|
||||
Rather than `malloc()` and `free()`, use the wrappers `OPENSSL_malloc()`
|
||||
and `OPENSSL_free()`. Use the standard C `assert()` function freely.
|
||||
|
||||
Use the following wrappers, found in `crypto/internal.h` instead of the
|
||||
corresponding C standard library functions. They behave the same but avoid
|
||||
confusing undefined behavior.
|
||||
|
||||
* `OPENSSL_memchr`
|
||||
* `OPENSSL_memcmp`
|
||||
* `OPENSSL_memcpy`
|
||||
* `OPENSSL_memmove`
|
||||
* `OPENSSL_memset`
|
||||
|
||||
For new constants, prefer enums when the values are sequential and typed
|
||||
constants for flags. If adding values to an existing set of `#define`s,
|
||||
continue with `#define`.
|
||||
|
||||
|
||||
## libssl
|
||||
|
||||
libssl was originally written in C but is being incrementally rewritten in
|
||||
C++11. As of writing, much of the style matches our C conventions rather than
|
||||
Google C++. Additionally, libssl on Linux currently may not depend on the C++
|
||||
runtime. See the C++ utilities in `ssl/internal.h` for replacements for
|
||||
problematic C++ constructs. The `util/check_imported_libraries.go` script may be
|
||||
used with a shared library build to check if a new construct is okay.
|
||||
|
||||
If unsure, match surrounding code. Discrepancies between it and Google C++ style
|
||||
will be fixed over time.
|
||||
|
||||
|
||||
## Formatting
|
||||
|
||||
Single-statement blocks are not allowed. All conditions and loops must
|
||||
use braces:
|
||||
|
||||
if (foo) {
|
||||
do_something();
|
||||
}
|
||||
|
||||
not
|
||||
|
||||
if (foo)
|
||||
do_something();
|
||||
|
||||
|
||||
## Integers
|
||||
|
||||
Prefer using explicitly-sized integers where appropriate rather than
|
||||
generic C ones. For instance, to represent a byte, use `uint8_t`, not
|
||||
`unsigned char`. Likewise, represent a two-byte field as `uint16_t`, not
|
||||
`unsigned short`.
|
||||
|
||||
Sizes are represented as `size_t`.
|
||||
|
||||
Within a struct that is retained across the lifetime of an SSL
|
||||
connection, if bounds of a size are known and it's easy, use a smaller
|
||||
integer type like `uint8_t`. This is a "free" connection footprint
|
||||
optimization for servers. Don't make code significantly more complex for
|
||||
it, and do still check the bounds when passing in and out of the
|
||||
struct. This narrowing should not propagate to local variables and
|
||||
function parameters.
|
||||
|
||||
When doing arithmetic, account for overflow conditions.
|
||||
|
||||
Except with platform APIs, do not use `ssize_t`. MSVC lacks it, and
|
||||
prefer out-of-band error signaling for `size_t` (see Return values).
|
||||
|
||||
|
||||
## Naming
|
||||
|
||||
Follow Google naming conventions in C++ files. In C files, use the
|
||||
following naming conventions for consistency with existing OpenSSL and C
|
||||
styles:
|
||||
|
||||
Define structs with typedef named `TYPE_NAME`. The corresponding struct
|
||||
should be named `struct type_name_st`.
|
||||
|
||||
Name public functions as `MODULE_function_name`, unless the module
|
||||
already uses a different naming scheme for legacy reasons. The module
|
||||
name should be a type name if the function is a method of a particular
|
||||
type.
|
||||
|
||||
Some types are allocated within the library while others are initialized
|
||||
into a struct allocated by the caller, often on the stack. Name these
|
||||
functions `TYPE_NAME_new`/`TYPE_NAME_free` and
|
||||
`TYPE_NAME_init`/`TYPE_NAME_cleanup`, respectively. All `TYPE_NAME_free`
|
||||
functions must do nothing on `NULL` input.
|
||||
|
||||
If a variable is the length of a pointer value, it has the suffix
|
||||
`_len`. An output parameter is named `out` or has an `out_` prefix. For
|
||||
instance, For instance:
|
||||
|
||||
uint8_t *out,
|
||||
size_t *out_len,
|
||||
const uint8_t *in,
|
||||
size_t in_len,
|
||||
|
||||
Name public headers like `include/openssl/evp.h` with header guards like
|
||||
`OPENSSL_HEADER_EVP_H`. Name internal headers like
|
||||
`crypto/ec/internal.h` with header guards like
|
||||
`OPENSSL_HEADER_CRYPTO_EC_INTERNAL_H`.
|
||||
|
||||
Name enums like `enum unix_hacker_t`. For instance:
|
||||
|
||||
enum should_free_handshake_buffer_t {
|
||||
free_handshake_buffer,
|
||||
dont_free_handshake_buffer,
|
||||
};
|
||||
|
||||
|
||||
## Return values
|
||||
|
||||
As even `malloc` may fail in BoringSSL, the vast majority of functions
|
||||
will have a failure case. Functions should return `int` with one on
|
||||
success and zero on error. Do not overload the return value to both
|
||||
signal success/failure and output an integer. For example:
|
||||
|
||||
OPENSSL_EXPORT int CBS_get_u16(CBS *cbs, uint16_t *out);
|
||||
|
||||
If a function needs more than a true/false result code, define an enum
|
||||
rather than arbitrarily assigning meaning to int values.
|
||||
|
||||
If a function outputs a pointer to an object on success and there are no
|
||||
other outputs, return the pointer directly and `NULL` on error.
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
Where not constrained by legacy code, parameter order should be:
|
||||
|
||||
1. context parameters
|
||||
2. output parameters
|
||||
3. input parameters
|
||||
|
||||
For example,
|
||||
|
||||
/* CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an
|
||||
* ASN.1 object can be written. The |tag| argument will be used as the tag for
|
||||
* the object. It returns one on success or zero on error. */
|
||||
OPENSSL_EXPORT int CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned tag);
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
All public symbols must have a documentation comment in their header
|
||||
file. The style is based on that of Go. The first sentence begins with
|
||||
the symbol name, optionally prefixed with "A" or "An". Apart from the
|
||||
initial mention of symbol, references to other symbols or parameter
|
||||
names should be surrounded by |pipes|.
|
||||
|
||||
Documentation should be concise but completely describe the exposed
|
||||
behavior of the function. Pay special note to success/failure behaviors
|
||||
and caller obligations on object lifetimes. If this sacrifices
|
||||
conciseness, consider simplifying the function's behavior.
|
||||
|
||||
// EVP_DigestVerifyUpdate appends |len| bytes from |data| to the data which
|
||||
// will be verified by |EVP_DigestVerifyFinal|. It returns one on success and
|
||||
// zero otherwise.
|
||||
OPENSSL_EXPORT int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data,
|
||||
size_t len);
|
||||
|
||||
Explicitly mention any surprising edge cases or deviations from common
|
||||
return value patterns in legacy functions.
|
||||
|
||||
// RSA_private_encrypt encrypts |flen| bytes from |from| with the private key in
|
||||
// |rsa| and writes the encrypted data to |to|. The |to| buffer must have at
|
||||
// least |RSA_size| bytes of space. It returns the number of bytes written, or
|
||||
// -1 on error. The |padding| argument must be one of the |RSA_*_PADDING|
|
||||
// values. If in doubt, |RSA_PKCS1_PADDING| is the most common.
|
||||
//
|
||||
// WARNING: this function is dangerous because it breaks the usual return value
|
||||
// convention. Use |RSA_sign_raw| instead.
|
||||
OPENSSL_EXPORT int RSA_private_encrypt(int flen, const uint8_t *from,
|
||||
uint8_t *to, RSA *rsa, int padding);
|
||||
|
||||
Document private functions in their `internal.h` header or, if static,
|
||||
where defined.
|
||||
|
||||
|
||||
## Build logic
|
||||
|
||||
BoringSSL is used by many projects with many different build tools.
|
||||
Reimplementing and maintaining build logic in each downstream build is
|
||||
cumbersome, so build logic should be avoided where possible. Platform-specific
|
||||
files should be excluded by wrapping the contents in `#ifdef`s, rather than
|
||||
computing platform-specific file lists. Generated source files such as perlasm
|
||||
and `err_data.c` may be used in the standalone CMake build but, for downstream
|
||||
builds, they should be pre-generated in `generate_build_files.py`.
|
||||
1069
src/build.json
1069
src/build.json
File diff suppressed because it is too large
Load Diff
@@ -1,46 +0,0 @@
|
||||
# Copyright 2022 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/OpenSSLTargets.cmake)
|
||||
|
||||
# Recursively collect dependency locations for the imported targets.
|
||||
macro(_openssl_config_libraries libraries target)
|
||||
get_property(_DEPS TARGET ${target} PROPERTY INTERFACE_LINK_LIBRARIES)
|
||||
foreach(_DEP ${_DEPS})
|
||||
if(TARGET ${_DEP})
|
||||
_openssl_config_libraries(${libraries} ${_DEP})
|
||||
else()
|
||||
list(APPEND ${libraries} ${_DEP})
|
||||
endif()
|
||||
endforeach()
|
||||
get_property(_LOC TARGET ${target} PROPERTY LOCATION)
|
||||
list(APPEND ${libraries} ${_LOC})
|
||||
endmacro()
|
||||
|
||||
set(OPENSSL_FOUND YES)
|
||||
get_property(OPENSSL_INCLUDE_DIR TARGET OpenSSL::SSL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_property(OPENSSL_CRYPTO_LIBRARY TARGET OpenSSL::Crypto PROPERTY LOCATION)
|
||||
_openssl_config_libraries(OPENSSL_CRYPTO_LIBRARIES OpenSSL::Crypto)
|
||||
list(REMOVE_DUPLICATES OPENSSL_CRYPTO_LIBRARIES)
|
||||
|
||||
get_property(OPENSSL_SSL_LIBRARY TARGET OpenSSL::Crypto PROPERTY LOCATION)
|
||||
_openssl_config_libraries(OPENSSL_SSL_LIBRARIES OpenSSL::SSL)
|
||||
list(REMOVE_DUPLICATES OPENSSL_SSL_LIBRARIES)
|
||||
|
||||
set(OPENSSL_LIBRARIES ${OPENSSL_CRYPTO_LIBRARIES} ${OPENSSL_SSL_LIBRARIES})
|
||||
list(REMOVE_DUPLICATES OPENSSL_LIBRARIES)
|
||||
|
||||
set(_DEP)
|
||||
set(_DEPS)
|
||||
set(_LOC)
|
||||
@@ -1,61 +0,0 @@
|
||||
# Copyright 2023 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Go is an optional dependency. It's a necessary dependency if running tests or
|
||||
# the FIPS build, which will check these.
|
||||
find_program(GO_EXECUTABLE go)
|
||||
|
||||
function(require_go)
|
||||
if(NOT GO_EXECUTABLE)
|
||||
message(FATAL_ERROR "Could not find Go")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(go_executable dest package)
|
||||
require_go()
|
||||
set(godeps "${PROJECT_SOURCE_DIR}/util/godeps.go")
|
||||
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
|
||||
# The DEPFILE parameter to add_custom_command only works with Ninja. Query
|
||||
# the sources at configure time. Additionally, everything depends on go.mod.
|
||||
# That affects what external packages to use.
|
||||
#
|
||||
# TODO(davidben): Starting CMake 3.20, it also works with Make. Starting
|
||||
# 3.21, it works with Visual Studio and Xcode too.
|
||||
execute_process(COMMAND ${GO_EXECUTABLE} run ${godeps} -format cmake
|
||||
-pkg ${package}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE sources
|
||||
RESULT_VARIABLE godeps_result)
|
||||
add_custom_command(OUTPUT ${dest}
|
||||
COMMAND ${GO_EXECUTABLE} build
|
||||
-o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${sources} ${PROJECT_SOURCE_DIR}/go.mod)
|
||||
else()
|
||||
# Ninja expects the target in the depfile to match the output. This is a
|
||||
# relative path from the build directory.
|
||||
binary_dir_relative_path(${dest} target)
|
||||
|
||||
set(depfile "${CMAKE_CURRENT_BINARY_DIR}/${dest}.d")
|
||||
add_custom_command(OUTPUT ${dest}
|
||||
COMMAND ${GO_EXECUTABLE} build
|
||||
-o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package}
|
||||
COMMAND ${GO_EXECUTABLE} run ${godeps} -format depfile
|
||||
-target ${target} -pkg ${package} -out ${depfile}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${godeps} ${PROJECT_SOURCE_DIR}/go.mod
|
||||
DEPFILE ${depfile})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
# Copyright 2023 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# binary_dir_relative_path sets outvar to
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/${cur_bin_dir_relative}, but expressed relative to
|
||||
# ${CMAKE_BINARY_DIR}.
|
||||
#
|
||||
# TODO(davidben): When we require CMake 3.20 or later, this can be replaced with
|
||||
# the built-in cmake_path(RELATIVE_PATH) function.
|
||||
function(binary_dir_relative_path cur_bin_dir_relative outvar)
|
||||
string(LENGTH "${CMAKE_BINARY_DIR}/" root_dir_length)
|
||||
string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}/${cur_bin_dir_relative}" ${root_dir_length} -1 result)
|
||||
set(${outvar} ${result} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# copy_post_build causes targets in ${ARGN} to be copied to
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/${dir} after being built.
|
||||
function(copy_post_build dir)
|
||||
foreach(target ${ARGN})
|
||||
add_custom_command(
|
||||
TARGET ${target}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${dir}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target}> "${CMAKE_CURRENT_BINARY_DIR}/${dir}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
@@ -1,4 +0,0 @@
|
||||
# This file is used by "git cl" to get repository specific information.
|
||||
GERRIT_HOST: True
|
||||
GERRIT_PORT: True
|
||||
CODE_REVIEW_SERVER: https://boringssl-review.googlesource.com
|
||||
@@ -1,523 +0,0 @@
|
||||
// Copyright 2018 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest-spi.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "test/abi_test.h"
|
||||
|
||||
|
||||
static bool test_function_ok;
|
||||
static int TestFunction(int a1, int a2, int a3, int a4, int a5, int a6, int a7,
|
||||
int a8) {
|
||||
test_function_ok = a1 == 1 || a2 == 2 || a3 == 3 || a4 == 4 || a5 == 5 ||
|
||||
a6 == 6 || a7 == 7 || a8 == 8;
|
||||
return 42;
|
||||
}
|
||||
|
||||
TEST(ABITest, SanityCheck) {
|
||||
EXPECT_NE(0, CHECK_ABI_NO_UNWIND(strcmp, "hello", "world"));
|
||||
|
||||
test_function_ok = false;
|
||||
EXPECT_EQ(42, CHECK_ABI_SEH(TestFunction, 1, 2, 3, 4, 5, 6, 7, 8));
|
||||
EXPECT_TRUE(test_function_ok);
|
||||
|
||||
#if defined(SUPPORTS_ABI_TEST)
|
||||
abi_test::internal::CallerState state;
|
||||
RAND_bytes(reinterpret_cast<uint8_t *>(&state), sizeof(state));
|
||||
crypto_word_t argv[] = {
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
};
|
||||
CHECK_ABI_SEH(abi_test_trampoline,
|
||||
reinterpret_cast<crypto_word_t>(TestFunction), &state, argv, 8,
|
||||
0 /* no breakpoint */);
|
||||
|
||||
#if defined(OPENSSL_X86_64)
|
||||
if (abi_test::UnwindTestsEnabled()) {
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_SEH(abi_test_bad_unwind_wrong_register),
|
||||
"was not recovered");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_SEH(abi_test_bad_unwind_temporary),
|
||||
"was not recovered");
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_bad_unwind_wrong_register);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_bad_unwind_temporary);
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
// The invalid epilog makes Windows believe the epilog starts later than it
|
||||
// actually does. As a result, immediately after the popq, it does not
|
||||
// realize the stack has been unwound and repeats the popq. This will result
|
||||
// in reading the wrong return address and fail to unwind. The exact failure
|
||||
// may vary depending on what was on the stack before.
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_SEH(abi_test_bad_unwind_epilog), "");
|
||||
CHECK_ABI_NO_UNWIND(abi_test_bad_unwind_epilog);
|
||||
#endif // OPENSSL_WINDOWS
|
||||
}
|
||||
#endif // OPENSSL_X86_64
|
||||
#endif // SUPPORTS_ABI_TEST
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_X86_64) && defined(SUPPORTS_ABI_TEST)
|
||||
extern "C" {
|
||||
void abi_test_clobber_rax(void);
|
||||
void abi_test_clobber_rbx(void);
|
||||
void abi_test_clobber_rcx(void);
|
||||
void abi_test_clobber_rdx(void);
|
||||
void abi_test_clobber_rsi(void);
|
||||
void abi_test_clobber_rdi(void);
|
||||
void abi_test_clobber_rbp(void);
|
||||
void abi_test_clobber_r8(void);
|
||||
void abi_test_clobber_r9(void);
|
||||
void abi_test_clobber_r10(void);
|
||||
void abi_test_clobber_r11(void);
|
||||
void abi_test_clobber_r12(void);
|
||||
void abi_test_clobber_r13(void);
|
||||
void abi_test_clobber_r14(void);
|
||||
void abi_test_clobber_r15(void);
|
||||
void abi_test_clobber_xmm0(void);
|
||||
void abi_test_clobber_xmm1(void);
|
||||
void abi_test_clobber_xmm2(void);
|
||||
void abi_test_clobber_xmm3(void);
|
||||
void abi_test_clobber_xmm4(void);
|
||||
void abi_test_clobber_xmm5(void);
|
||||
void abi_test_clobber_xmm6(void);
|
||||
void abi_test_clobber_xmm7(void);
|
||||
void abi_test_clobber_xmm8(void);
|
||||
void abi_test_clobber_xmm9(void);
|
||||
void abi_test_clobber_xmm10(void);
|
||||
void abi_test_clobber_xmm11(void);
|
||||
void abi_test_clobber_xmm12(void);
|
||||
void abi_test_clobber_xmm13(void);
|
||||
void abi_test_clobber_xmm14(void);
|
||||
void abi_test_clobber_xmm15(void);
|
||||
} // extern "C"
|
||||
|
||||
TEST(ABITest, X86_64) {
|
||||
// abi_test_trampoline hides unsaved registers from the caller, so we can
|
||||
// safely call the abi_test_clobber_* functions below.
|
||||
abi_test::internal::CallerState state;
|
||||
RAND_bytes(reinterpret_cast<uint8_t *>(&state), sizeof(state));
|
||||
CHECK_ABI_NO_UNWIND(abi_test_trampoline,
|
||||
reinterpret_cast<crypto_word_t>(abi_test_clobber_rbx),
|
||||
&state, nullptr, 0, 0 /* no breakpoint */);
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_rax);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_rbx),
|
||||
"rbx was not restored after return");
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_rcx);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_rdx);
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_rdi),
|
||||
"rdi was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_rsi),
|
||||
"rsi was not restored after return");
|
||||
#else
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_rdi);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_rsi);
|
||||
#endif
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_rbp),
|
||||
"rbp was not restored after return");
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r8);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r9);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r10);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r11);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r12),
|
||||
"r12 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r13),
|
||||
"r13 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r14),
|
||||
"r14 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r15),
|
||||
"r15 was not restored after return");
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm0);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm1);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm2);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm3);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm4);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm5);
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm6),
|
||||
"xmm6 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm7),
|
||||
"xmm7 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm8),
|
||||
"xmm8 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm9),
|
||||
"xmm9 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm10),
|
||||
"xmm10 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm11),
|
||||
"xmm11 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm12),
|
||||
"xmm12 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm13),
|
||||
"xmm13 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm14),
|
||||
"xmm14 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm15),
|
||||
"xmm15 was not restored after return");
|
||||
#else
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm6);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm7);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm8);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm9);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm10);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm11);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm12);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm13);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm14);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm15);
|
||||
#endif
|
||||
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_set_direction_flag),
|
||||
"Direction flag set after return");
|
||||
EXPECT_EQ(0, abi_test_get_and_clear_direction_flag())
|
||||
<< "CHECK_ABI did not insulate the caller from direction flag errors";
|
||||
}
|
||||
#endif // OPENSSL_X86_64 && SUPPORTS_ABI_TEST
|
||||
|
||||
#if defined(OPENSSL_X86) && defined(SUPPORTS_ABI_TEST)
|
||||
extern "C" {
|
||||
void abi_test_clobber_eax(void);
|
||||
void abi_test_clobber_ebx(void);
|
||||
void abi_test_clobber_ecx(void);
|
||||
void abi_test_clobber_edx(void);
|
||||
void abi_test_clobber_esi(void);
|
||||
void abi_test_clobber_edi(void);
|
||||
void abi_test_clobber_ebp(void);
|
||||
void abi_test_clobber_xmm0(void);
|
||||
void abi_test_clobber_xmm1(void);
|
||||
void abi_test_clobber_xmm2(void);
|
||||
void abi_test_clobber_xmm3(void);
|
||||
void abi_test_clobber_xmm4(void);
|
||||
void abi_test_clobber_xmm5(void);
|
||||
void abi_test_clobber_xmm6(void);
|
||||
void abi_test_clobber_xmm7(void);
|
||||
} // extern "C"
|
||||
|
||||
TEST(ABITest, X86) {
|
||||
// abi_test_trampoline hides unsaved registers from the caller, so we can
|
||||
// safely call the abi_test_clobber_* functions below.
|
||||
abi_test::internal::CallerState state;
|
||||
RAND_bytes(reinterpret_cast<uint8_t *>(&state), sizeof(state));
|
||||
CHECK_ABI_NO_UNWIND(abi_test_trampoline,
|
||||
reinterpret_cast<crypto_word_t>(abi_test_clobber_ebx),
|
||||
&state, nullptr, 0, 0 /* no breakpoint */);
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_eax);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_ebx),
|
||||
"ebx was not restored after return");
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_ecx);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_edx);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_edi),
|
||||
"edi was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_esi),
|
||||
"esi was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_ebp),
|
||||
"ebp was not restored after return");
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm0);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm1);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm2);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm3);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm4);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm5);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm6);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_xmm7);
|
||||
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_set_direction_flag),
|
||||
"Direction flag set after return");
|
||||
EXPECT_EQ(0, abi_test_get_and_clear_direction_flag())
|
||||
<< "CHECK_ABI did not insulate the caller from direction flag errors";
|
||||
}
|
||||
#endif // OPENSSL_X86 && SUPPORTS_ABI_TEST
|
||||
|
||||
#if defined(OPENSSL_ARM) && defined(SUPPORTS_ABI_TEST)
|
||||
extern "C" {
|
||||
void abi_test_clobber_r0(void);
|
||||
void abi_test_clobber_r1(void);
|
||||
void abi_test_clobber_r2(void);
|
||||
void abi_test_clobber_r3(void);
|
||||
void abi_test_clobber_r4(void);
|
||||
void abi_test_clobber_r5(void);
|
||||
void abi_test_clobber_r6(void);
|
||||
void abi_test_clobber_r7(void);
|
||||
void abi_test_clobber_r8(void);
|
||||
void abi_test_clobber_r9(void);
|
||||
void abi_test_clobber_r10(void);
|
||||
void abi_test_clobber_r11(void);
|
||||
void abi_test_clobber_r12(void);
|
||||
// r13, r14, and r15, are sp, lr, and pc, respectively.
|
||||
|
||||
void abi_test_clobber_d0(void);
|
||||
void abi_test_clobber_d1(void);
|
||||
void abi_test_clobber_d2(void);
|
||||
void abi_test_clobber_d3(void);
|
||||
void abi_test_clobber_d4(void);
|
||||
void abi_test_clobber_d5(void);
|
||||
void abi_test_clobber_d6(void);
|
||||
void abi_test_clobber_d7(void);
|
||||
void abi_test_clobber_d8(void);
|
||||
void abi_test_clobber_d9(void);
|
||||
void abi_test_clobber_d10(void);
|
||||
void abi_test_clobber_d11(void);
|
||||
void abi_test_clobber_d12(void);
|
||||
void abi_test_clobber_d13(void);
|
||||
void abi_test_clobber_d14(void);
|
||||
void abi_test_clobber_d15(void);
|
||||
} // extern "C"
|
||||
|
||||
TEST(ABITest, ARM) {
|
||||
// abi_test_trampoline hides unsaved registers from the caller, so we can
|
||||
// safely call the abi_test_clobber_* functions below.
|
||||
abi_test::internal::CallerState state;
|
||||
RAND_bytes(reinterpret_cast<uint8_t *>(&state), sizeof(state));
|
||||
CHECK_ABI_NO_UNWIND(abi_test_trampoline,
|
||||
reinterpret_cast<crypto_word_t>(abi_test_clobber_r4),
|
||||
&state, nullptr, 0, 0 /* no breakpoint */);
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r0);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r1);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r2);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r3);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r4),
|
||||
"r4 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r5),
|
||||
"r5 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r6),
|
||||
"r6 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r7),
|
||||
"r7 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r8),
|
||||
"r8 was not restored after return");
|
||||
#if defined(OPENSSL_APPLE)
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r9);
|
||||
#else
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r9),
|
||||
"r9 was not restored after return");
|
||||
#endif
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r10),
|
||||
"r10 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_r11),
|
||||
"r11 was not restored after return");
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_r12);
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d0);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d1);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d2);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d3);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d4);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d5);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d6);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d7);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d8),
|
||||
"d8 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d9),
|
||||
"d9 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d10),
|
||||
"d10 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d11),
|
||||
"d11 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d12),
|
||||
"d12 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d13),
|
||||
"d13 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d14),
|
||||
"d14 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d15),
|
||||
"d15 was not restored after return");
|
||||
}
|
||||
#endif // OPENSSL_ARM && SUPPORTS_ABI_TEST
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(SUPPORTS_ABI_TEST)
|
||||
extern "C" {
|
||||
void abi_test_clobber_x0(void);
|
||||
void abi_test_clobber_x1(void);
|
||||
void abi_test_clobber_x2(void);
|
||||
void abi_test_clobber_x3(void);
|
||||
void abi_test_clobber_x4(void);
|
||||
void abi_test_clobber_x5(void);
|
||||
void abi_test_clobber_x6(void);
|
||||
void abi_test_clobber_x7(void);
|
||||
void abi_test_clobber_x8(void);
|
||||
void abi_test_clobber_x9(void);
|
||||
void abi_test_clobber_x10(void);
|
||||
void abi_test_clobber_x11(void);
|
||||
void abi_test_clobber_x12(void);
|
||||
void abi_test_clobber_x13(void);
|
||||
void abi_test_clobber_x14(void);
|
||||
void abi_test_clobber_x15(void);
|
||||
void abi_test_clobber_x16(void);
|
||||
void abi_test_clobber_x17(void);
|
||||
// x18 is the platform register and off limits.
|
||||
void abi_test_clobber_x19(void);
|
||||
void abi_test_clobber_x20(void);
|
||||
void abi_test_clobber_x21(void);
|
||||
void abi_test_clobber_x22(void);
|
||||
void abi_test_clobber_x23(void);
|
||||
void abi_test_clobber_x24(void);
|
||||
void abi_test_clobber_x25(void);
|
||||
void abi_test_clobber_x26(void);
|
||||
void abi_test_clobber_x27(void);
|
||||
void abi_test_clobber_x28(void);
|
||||
void abi_test_clobber_x29(void);
|
||||
|
||||
void abi_test_clobber_d0(void);
|
||||
void abi_test_clobber_d1(void);
|
||||
void abi_test_clobber_d2(void);
|
||||
void abi_test_clobber_d3(void);
|
||||
void abi_test_clobber_d4(void);
|
||||
void abi_test_clobber_d5(void);
|
||||
void abi_test_clobber_d6(void);
|
||||
void abi_test_clobber_d7(void);
|
||||
void abi_test_clobber_d8(void);
|
||||
void abi_test_clobber_d9(void);
|
||||
void abi_test_clobber_d10(void);
|
||||
void abi_test_clobber_d11(void);
|
||||
void abi_test_clobber_d12(void);
|
||||
void abi_test_clobber_d13(void);
|
||||
void abi_test_clobber_d14(void);
|
||||
void abi_test_clobber_d15(void);
|
||||
void abi_test_clobber_d16(void);
|
||||
void abi_test_clobber_d17(void);
|
||||
void abi_test_clobber_d18(void);
|
||||
void abi_test_clobber_d19(void);
|
||||
void abi_test_clobber_d20(void);
|
||||
void abi_test_clobber_d21(void);
|
||||
void abi_test_clobber_d22(void);
|
||||
void abi_test_clobber_d23(void);
|
||||
void abi_test_clobber_d24(void);
|
||||
void abi_test_clobber_d25(void);
|
||||
void abi_test_clobber_d26(void);
|
||||
void abi_test_clobber_d27(void);
|
||||
void abi_test_clobber_d28(void);
|
||||
void abi_test_clobber_d29(void);
|
||||
void abi_test_clobber_d30(void);
|
||||
void abi_test_clobber_d31(void);
|
||||
|
||||
void abi_test_clobber_v8_upper(void);
|
||||
void abi_test_clobber_v9_upper(void);
|
||||
void abi_test_clobber_v10_upper(void);
|
||||
void abi_test_clobber_v11_upper(void);
|
||||
void abi_test_clobber_v12_upper(void);
|
||||
void abi_test_clobber_v13_upper(void);
|
||||
void abi_test_clobber_v14_upper(void);
|
||||
void abi_test_clobber_v15_upper(void);
|
||||
} // extern "C"
|
||||
|
||||
TEST(ABITest, AArch64) {
|
||||
// abi_test_trampoline hides unsaved registers from the caller, so we can
|
||||
// safely call the abi_test_clobber_* functions below.
|
||||
abi_test::internal::CallerState state;
|
||||
RAND_bytes(reinterpret_cast<uint8_t *>(&state), sizeof(state));
|
||||
CHECK_ABI_NO_UNWIND(abi_test_trampoline,
|
||||
reinterpret_cast<crypto_word_t>(abi_test_clobber_x19),
|
||||
&state, nullptr, 0, 0 /* no breakpoint */);
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x0);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x1);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x2);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x3);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x4);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x5);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x6);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x7);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x8);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x9);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x10);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x11);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x12);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x13);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x14);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x15);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x16);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_x17);
|
||||
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x19),
|
||||
"x19 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x20),
|
||||
"x20 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x21),
|
||||
"x21 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x22),
|
||||
"x22 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x23),
|
||||
"x23 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x24),
|
||||
"x24 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x25),
|
||||
"x25 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x26),
|
||||
"x26 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x27),
|
||||
"x27 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x28),
|
||||
"x28 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_x29),
|
||||
"x29 was not restored after return");
|
||||
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d0);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d1);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d2);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d3);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d4);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d5);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d6);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d7);
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d8),
|
||||
"d8 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d9),
|
||||
"d9 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d10),
|
||||
"d10 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d11),
|
||||
"d11 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d12),
|
||||
"d12 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d13),
|
||||
"d13 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d14),
|
||||
"d14 was not restored after return");
|
||||
EXPECT_NONFATAL_FAILURE(CHECK_ABI_NO_UNWIND(abi_test_clobber_d15),
|
||||
"d15 was not restored after return");
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d16);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d18);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d19);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d20);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d21);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d22);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d23);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d24);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d25);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d26);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d27);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d28);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d29);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d30);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_d31);
|
||||
|
||||
// The lower halves of v8-v15 (accessed as d8-d15) must be preserved, but not
|
||||
// the upper halves.
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v8_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v9_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v10_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v11_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v12_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v13_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v14_upper);
|
||||
CHECK_ABI_NO_UNWIND(abi_test_clobber_v15_upper);
|
||||
}
|
||||
#endif // OPENSSL_AARCH64 && SUPPORTS_ABI_TEST
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2025 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <openssl/aes.h>
|
||||
|
||||
#include "../fipsmodule/bcm_interface.h"
|
||||
|
||||
void AES_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
||||
BCM_aes_encrypt(in, out, key);
|
||||
}
|
||||
|
||||
void AES_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
||||
BCM_aes_decrypt(in, out, key);
|
||||
}
|
||||
|
||||
int AES_set_encrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) {
|
||||
if (bits != 128 && bits != 192 && bits != 256) {
|
||||
return -2;
|
||||
}
|
||||
return bcm_success(BCM_aes_set_encrypt_key(key, bits, aeskey)) ? 0 : -1;
|
||||
}
|
||||
|
||||
int AES_set_decrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) {
|
||||
if (bits != 128 && bits != 192 && bits != 256) {
|
||||
return -2;
|
||||
}
|
||||
return bcm_success(BCM_aes_set_decrypt_key(key, bits, aeskey)) ? 0 : -1;
|
||||
}
|
||||
@@ -1,259 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d,
|
||||
ossl_ssize_t len) {
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
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.
|
||||
*out_padding_bits = len == 0 ? 0 : str->flags & 0x07;
|
||||
return len;
|
||||
}
|
||||
|
||||
// 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--;
|
||||
}
|
||||
uint8_t padding_bits = 0;
|
||||
if (len > 0) {
|
||||
uint8_t last = str->data[len - 1];
|
||||
assert(last != 0);
|
||||
for (; padding_bits < 7; padding_bits++) {
|
||||
if (last & (1 << padding_bits)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*out_padding_bits = padding_bits;
|
||||
return len;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_num_bytes(const ASN1_BIT_STRING *str, size_t *out) {
|
||||
uint8_t padding_bits;
|
||||
int len = asn1_bit_string_length(str, &padding_bits);
|
||||
if (padding_bits != 0) {
|
||||
return 0;
|
||||
}
|
||||
*out = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp) {
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t bits;
|
||||
int len = asn1_bit_string_length(a, &bits);
|
||||
if (len > INT_MAX - 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
int ret = 1 + len;
|
||||
if (pp == NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t *p = *pp;
|
||||
*(p++) = bits;
|
||||
OPENSSL_memcpy(p, a->data, len);
|
||||
if (len > 0) {
|
||||
p[len - 1] &= (0xff << bits);
|
||||
}
|
||||
p += len;
|
||||
*pp = p;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int asn1_marshal_bit_string(CBB *out, const ASN1_BIT_STRING *in,
|
||||
CBS_ASN1_TAG tag) {
|
||||
int len = i2c_ASN1_BIT_STRING(in, nullptr);
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
tag = tag == 0 ? CBS_ASN1_BITSTRING : tag;
|
||||
CBB child;
|
||||
uint8_t *ptr;
|
||||
return CBB_add_asn1(out, &child, tag) && //
|
||||
CBB_add_space(&child, &ptr, static_cast<size_t>(len)) && //
|
||||
i2c_ASN1_BIT_STRING(in, &ptr) == len && //
|
||||
CBB_flush(out);
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
const unsigned char **pp, long len) {
|
||||
ASN1_BIT_STRING *ret = NULL;
|
||||
const unsigned char *p;
|
||||
unsigned char *s;
|
||||
int padding;
|
||||
uint8_t padding_mask;
|
||||
|
||||
if (len < 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_BIT_STRING_new()) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = (*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.
|
||||
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
|
||||
ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); // clear
|
||||
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | padding); // set
|
||||
|
||||
if (len > 0) {
|
||||
s = reinterpret_cast<uint8_t *>(OPENSSL_memdup(p, len));
|
||||
if (s == NULL) {
|
||||
goto err;
|
||||
}
|
||||
p += len;
|
||||
} else {
|
||||
s = NULL;
|
||||
}
|
||||
|
||||
ret->length = (int)len;
|
||||
OPENSSL_free(ret->data);
|
||||
ret->data = s;
|
||||
ret->type = V_ASN1_BIT_STRING;
|
||||
if (a != NULL) {
|
||||
(*a) = ret;
|
||||
}
|
||||
*pp = p;
|
||||
return ret;
|
||||
err:
|
||||
if ((ret != NULL) && ((a == NULL) || (*a != ret))) {
|
||||
ASN1_BIT_STRING_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
|
||||
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) {
|
||||
int w, v, iv;
|
||||
unsigned char *c;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
iv = ~v;
|
||||
if (!value) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); // clear, set on write
|
||||
|
||||
if ((a->length < (w + 1)) || (a->data == NULL)) {
|
||||
if (!value) {
|
||||
return 1; // Don't need to set
|
||||
}
|
||||
if (a->data == NULL) {
|
||||
c = (unsigned char *)OPENSSL_malloc(w + 1);
|
||||
} else {
|
||||
c = (unsigned char *)OPENSSL_realloc(a->data, w + 1);
|
||||
}
|
||||
if (c == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (w + 1 - a->length > 0) {
|
||||
OPENSSL_memset(c + a->length, 0, w + 1 - a->length);
|
||||
}
|
||||
a->data = c;
|
||||
a->length = w + 1;
|
||||
}
|
||||
a->data[w] = ((a->data[w]) & iv) | v;
|
||||
while ((a->length > 0) && (a->data[a->length - 1] == 0)) {
|
||||
a->length--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n) {
|
||||
int w, v;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL)) {
|
||||
return 0;
|
||||
}
|
||||
return ((a->data[w] & v) != 0);
|
||||
}
|
||||
|
||||
// Checks if the given bit string contains only bits specified by
|
||||
// the flags vector. Returns 0 if there is at least one bit set in 'a'
|
||||
// which is not specified in 'flags', 1 otherwise.
|
||||
// 'len' is the length of 'flags'.
|
||||
int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
|
||||
int flags_len) {
|
||||
int i, ok;
|
||||
// Check if there is one bit set at all.
|
||||
if (!a || !a->data) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check each byte of the internal representation of the bit string.
|
||||
ok = 1;
|
||||
for (i = 0; i < a->length && ok; ++i) {
|
||||
unsigned char mask = i < flags_len ? ~flags[i] : 0xff;
|
||||
// We are done if there is an unneeded bit set.
|
||||
ok = (a->data[i] & mask) == 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
|
||||
|
||||
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **outp) {
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, 3) || //
|
||||
!CBB_add_asn1_bool(&cbb, a != ASN1_BOOLEAN_FALSE)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
return ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
int val;
|
||||
if (!CBS_get_asn1_bool(&cbs, &val)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
ASN1_BOOLEAN ret = val ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
|
||||
void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) {
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
// Historically, this function did not impose a limit in OpenSSL and is used
|
||||
// to read CRLs, so we leave this without an external bound.
|
||||
if (!BIO_read_asn1(in, &data, &len, INT_MAX)) {
|
||||
return NULL;
|
||||
}
|
||||
const uint8_t *ptr = data;
|
||||
void *ret = ASN1_item_d2i(reinterpret_cast<ASN1_VALUE **>(x), &ptr, len, it);
|
||||
OPENSSL_free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) {
|
||||
BIO *b = BIO_new_fp(in, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
|
||||
return NULL;
|
||||
}
|
||||
void *ret = ASN1_item_d2i_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
// ASN1_ITEM version of dup: this follows the model above except we don't
|
||||
// need to allocate the buffer. At some point this could be rewritten to
|
||||
// directly dup the underlying structure instead of doing and encode and
|
||||
// decode.
|
||||
void *ASN1_item_dup(const ASN1_ITEM *it, void *x) {
|
||||
unsigned char *b = NULL;
|
||||
const unsigned char *p;
|
||||
long i;
|
||||
void *ret;
|
||||
|
||||
if (x == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
i = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
p = b;
|
||||
ret = ASN1_item_d2i(NULL, &p, i, it);
|
||||
OPENSSL_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d) {
|
||||
if (d->type != V_ASN1_GENERALIZEDTIME) {
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, d->data, (size_t)d->length);
|
||||
if (!CBS_parse_generalized_time(&cbs, tm, /*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d) {
|
||||
return asn1_generalizedtime_to_tm(NULL, d);
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) {
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_generalized_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, str, len)) {
|
||||
return 0;
|
||||
}
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time) {
|
||||
return ASN1_GENERALIZEDTIME_adj(s, posix_time, 0, 0);
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time,
|
||||
int offset_day,
|
||||
long offset_sec) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.tm_year < 0 - 1900 || data.tm_year > 9999 - 1900) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TIME_VALUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[16];
|
||||
int ret = snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year + 1900, data.tm_mon + 1, data.tm_mday,
|
||||
data.tm_hour, data.tm_min, data.tm_sec);
|
||||
// |snprintf| must write exactly 15 bytes (plus the NUL) to the buffer.
|
||||
BSSL_CHECK(ret == static_cast<int>(sizeof(buf) - 1));
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
free_s = 1;
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(s, buf, strlen(buf))) {
|
||||
if (free_s) {
|
||||
ASN1_UTCTIME_free(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
return s;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
|
||||
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
|
||||
BIO *b = BIO_new_fp(out, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
|
||||
return 0;
|
||||
}
|
||||
int ret = ASN1_item_i2d_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) {
|
||||
unsigned char *b = NULL;
|
||||
int n = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = BIO_write_all(out, b, n);
|
||||
OPENSSL_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,439 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) {
|
||||
return ASN1_STRING_dup(x);
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) {
|
||||
// Compare signs.
|
||||
int neg = x->type & V_ASN1_NEG;
|
||||
if (neg != (y->type & V_ASN1_NEG)) {
|
||||
return neg ? -1 : 1;
|
||||
}
|
||||
|
||||
int ret = ASN1_STRING_cmp(x, y);
|
||||
if (neg) {
|
||||
// This could be |-ret|, but |ASN1_STRING_cmp| is not forbidden from
|
||||
// returning |INT_MIN|.
|
||||
if (ret < 0) {
|
||||
return 1;
|
||||
} else if (ret > 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// negate_twos_complement negates |len| bytes from |buf| in-place, interpreted
|
||||
// as a signed, big-endian two's complement value.
|
||||
static void negate_twos_complement(uint8_t *buf, size_t len) {
|
||||
uint8_t borrow = 0;
|
||||
for (size_t i = len - 1; i < len; i--) {
|
||||
uint8_t t = buf[i];
|
||||
buf[i] = 0u - borrow - t;
|
||||
borrow |= t != 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int is_all_zeros(const uint8_t *in, size_t len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (in[i] != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_marshal_integer(CBB *out, const ASN1_INTEGER *in, CBS_ASN1_TAG tag) {
|
||||
int len = i2c_ASN1_INTEGER(in, nullptr);
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
tag = tag == 0 ? CBS_ASN1_INTEGER : tag;
|
||||
CBB child;
|
||||
uint8_t *ptr;
|
||||
return CBB_add_asn1(out, &child, tag) && //
|
||||
CBB_add_space(&child, &ptr, static_cast<size_t>(len)) && //
|
||||
i2c_ASN1_INTEGER(in, &ptr) == len && //
|
||||
CBB_flush(out);
|
||||
}
|
||||
|
||||
int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp) {
|
||||
if (in == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// |ASN1_INTEGER|s should be represented minimally, but it is possible to
|
||||
// construct invalid ones. Skip leading zeros so this does not produce an
|
||||
// invalid encoding or break invariants.
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, in->data, in->length);
|
||||
while (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0) {
|
||||
CBS_skip(&cbs, 1);
|
||||
}
|
||||
|
||||
int is_negative = (in->type & V_ASN1_NEG) != 0;
|
||||
size_t pad;
|
||||
CBS copy = cbs;
|
||||
uint8_t msb;
|
||||
if (!CBS_get_u8(©, &msb)) {
|
||||
// Zero is represented as a single byte.
|
||||
is_negative = 0;
|
||||
pad = 1;
|
||||
} else if (is_negative) {
|
||||
// 0x80...01 through 0xff...ff have a two's complement of 0x7f...ff
|
||||
// through 0x00...01 and need an extra byte to be negative.
|
||||
// 0x01...00 through 0x80...00 have a two's complement of 0xfe...ff
|
||||
// through 0x80...00 and can be negated as-is.
|
||||
pad = msb > 0x80 ||
|
||||
(msb == 0x80 && !is_all_zeros(CBS_data(©), CBS_len(©)));
|
||||
} else {
|
||||
// If the high bit is set, the signed representation needs an extra
|
||||
// byte to be positive.
|
||||
pad = (msb & 0x80) != 0;
|
||||
}
|
||||
|
||||
if (CBS_len(&cbs) > INT_MAX - pad) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
int len = (int)(pad + CBS_len(&cbs));
|
||||
assert(len > 0);
|
||||
if (outp == NULL) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if (pad) {
|
||||
(*outp)[0] = 0;
|
||||
}
|
||||
OPENSSL_memcpy(*outp + pad, CBS_data(&cbs), CBS_len(&cbs));
|
||||
if (is_negative) {
|
||||
negate_twos_complement(*outp, len);
|
||||
assert((*outp)[0] >= 0x80);
|
||||
} else {
|
||||
assert((*outp)[0] < 0x80);
|
||||
}
|
||||
*outp += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
|
||||
long len) {
|
||||
// This function can handle lengths up to INT_MAX - 1, but the rest of the
|
||||
// legacy ASN.1 code mixes integer types, so avoid exposing it to
|
||||
// ASN1_INTEGERS with larger lengths.
|
||||
if (len < 0 || len > INT_MAX / 2) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
int is_negative;
|
||||
if (!CBS_is_valid_asn1_integer(&cbs, &is_negative)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_INTEGER_new();
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
// Convert to |ASN1_INTEGER|'s sign-and-magnitude representation. First,
|
||||
// determine the size needed for a minimal result.
|
||||
if (is_negative) {
|
||||
// 0xff00...01 through 0xff7f..ff have a two's complement of 0x00ff...ff
|
||||
// through 0x000100...001 and need one leading zero removed. 0x8000...00
|
||||
// through 0xff00...00 have a two's complement of 0x8000...00 through
|
||||
// 0x0100...00 and will be minimally-encoded as-is.
|
||||
if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0xff &&
|
||||
!is_all_zeros(CBS_data(&cbs) + 1, CBS_len(&cbs) - 1)) {
|
||||
CBS_skip(&cbs, 1);
|
||||
}
|
||||
} else {
|
||||
// Remove the leading zero byte, if any.
|
||||
if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0x00) {
|
||||
CBS_skip(&cbs, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(ret, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (is_negative) {
|
||||
ret->type = V_ASN1_NEG_INTEGER;
|
||||
negate_twos_complement(ret->data, ret->length);
|
||||
} else {
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
}
|
||||
|
||||
// The value should be minimally-encoded.
|
||||
assert(ret->length == 0 || ret->data[0] != 0);
|
||||
// Zero is not negative.
|
||||
assert(!is_negative || ret->length > 0);
|
||||
|
||||
*inp += len;
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (ret != NULL && (out == NULL || *out != ret)) {
|
||||
ASN1_INTEGER_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t v) {
|
||||
if (v >= 0) {
|
||||
return ASN1_INTEGER_set_uint64(a, (uint64_t)v);
|
||||
}
|
||||
|
||||
if (!ASN1_INTEGER_set_uint64(a, 0 - (uint64_t)v)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
a->type = V_ASN1_NEG_INTEGER;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t v) {
|
||||
if (v >= 0) {
|
||||
return ASN1_ENUMERATED_set_uint64(a, (uint64_t)v);
|
||||
}
|
||||
|
||||
if (!ASN1_ENUMERATED_set_uint64(a, 0 - (uint64_t)v)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
a->type = V_ASN1_NEG_ENUMERATED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) {
|
||||
static_assert(sizeof(long) <= sizeof(int64_t), "long fits in int64_t");
|
||||
return ASN1_INTEGER_set_int64(a, v);
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) {
|
||||
static_assert(sizeof(long) <= sizeof(int64_t), "long fits in int64_t");
|
||||
return ASN1_ENUMERATED_set_int64(a, v);
|
||||
}
|
||||
|
||||
static int asn1_string_set_uint64(ASN1_STRING *out, uint64_t v, int type) {
|
||||
uint8_t buf[sizeof(uint64_t)];
|
||||
CRYPTO_store_u64_be(buf, v);
|
||||
size_t leading_zeros;
|
||||
for (leading_zeros = 0; leading_zeros < sizeof(buf); leading_zeros++) {
|
||||
if (buf[leading_zeros] != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(out, buf + leading_zeros, sizeof(buf) - leading_zeros)) {
|
||||
return 0;
|
||||
}
|
||||
out->type = type;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v) {
|
||||
return asn1_string_set_uint64(out, v, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_set_uint64(ASN1_ENUMERATED *out, uint64_t v) {
|
||||
return asn1_string_set_uint64(out, v, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static int asn1_string_get_abs_uint64(uint64_t *out, const ASN1_STRING *a,
|
||||
int type) {
|
||||
if ((a->type & ~V_ASN1_NEG) != type) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
|
||||
return 0;
|
||||
}
|
||||
uint8_t buf[sizeof(uint64_t)] = {0};
|
||||
if (a->length > (int)sizeof(buf)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(buf + sizeof(buf) - a->length, a->data, a->length);
|
||||
*out = CRYPTO_load_u64_be(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int asn1_string_get_uint64(uint64_t *out, const ASN1_STRING *a,
|
||||
int type) {
|
||||
if (!asn1_string_get_abs_uint64(out, a, type)) {
|
||||
return 0;
|
||||
}
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_get_uint64(uint64_t *out, const ASN1_INTEGER *a) {
|
||||
return asn1_string_get_uint64(out, a, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_get_uint64(uint64_t *out, const ASN1_ENUMERATED *a) {
|
||||
return asn1_string_get_uint64(out, a, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static int asn1_string_get_int64(int64_t *out, const ASN1_STRING *a, int type) {
|
||||
uint64_t v;
|
||||
if (!asn1_string_get_abs_uint64(&v, a, type)) {
|
||||
return 0;
|
||||
}
|
||||
int64_t i64;
|
||||
int fits_in_i64;
|
||||
// Check |v != 0| to handle manually-constructed negative zeros.
|
||||
if ((a->type & V_ASN1_NEG) && v != 0) {
|
||||
i64 = (int64_t)(0u - v);
|
||||
fits_in_i64 = i64 < 0;
|
||||
} else {
|
||||
i64 = (int64_t)v;
|
||||
fits_in_i64 = i64 >= 0;
|
||||
}
|
||||
if (!fits_in_i64) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return 0;
|
||||
}
|
||||
*out = i64;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_get_int64(int64_t *out, const ASN1_INTEGER *a) {
|
||||
return asn1_string_get_int64(out, a, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_get_int64(int64_t *out, const ASN1_ENUMERATED *a) {
|
||||
return asn1_string_get_int64(out, a, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static long asn1_string_get_long(const ASN1_STRING *a, int type) {
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t v;
|
||||
if (!asn1_string_get_int64(&v, a, type) || //
|
||||
v < LONG_MIN || v > LONG_MAX) {
|
||||
// This function's return value does not distinguish overflow from -1.
|
||||
ERR_clear_error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (long)v;
|
||||
}
|
||||
|
||||
long ASN1_INTEGER_get(const ASN1_INTEGER *a) {
|
||||
return asn1_string_get_long(a, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a) {
|
||||
return asn1_string_get_long(a, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
|
||||
int type) {
|
||||
ASN1_INTEGER *ret;
|
||||
if (ai == NULL) {
|
||||
ret = ASN1_STRING_type_new(type);
|
||||
} else {
|
||||
ret = ai;
|
||||
}
|
||||
int len;
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (BN_is_negative(bn) && !BN_is_zero(bn)) {
|
||||
ret->type = type | V_ASN1_NEG;
|
||||
} else {
|
||||
ret->type = type;
|
||||
}
|
||||
|
||||
len = BN_num_bytes(bn);
|
||||
if (!ASN1_STRING_set(ret, NULL, len) ||
|
||||
!BN_bn2bin_padded(ret->data, len, bn)) {
|
||||
goto err;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (ret != ai) {
|
||||
ASN1_STRING_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) {
|
||||
return bn_to_asn1_string(bn, ai, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai) {
|
||||
return bn_to_asn1_string(bn, ai, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static BIGNUM *asn1_string_to_bn(const ASN1_STRING *ai, BIGNUM *bn, int type) {
|
||||
if ((ai->type & ~V_ASN1_NEG) != type) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIGNUM *ret;
|
||||
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BN_LIB);
|
||||
} else if (ai->type & V_ASN1_NEG) {
|
||||
BN_set_negative(ret, 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) {
|
||||
return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn) {
|
||||
return asn1_string_to_bn(ai, bn, V_ASN1_ENUMERATED);
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
// These functions take a string in UTF8, ASCII or multibyte form and a mask
|
||||
// of permissible ASN1 string types. It then works out the minimal type
|
||||
// (using the order Printable < IA5 < T61 < BMP < Universal < UTF8) and
|
||||
// creates a string of the correct type with the supplied data. Yes this is
|
||||
// horrible: it has to be :-( The 'ncopy' form checks minimum and maximum
|
||||
// size limits too.
|
||||
|
||||
int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in,
|
||||
ossl_ssize_t len, int inform, unsigned long mask) {
|
||||
return ASN1_mbstring_ncopy(out, in, len, inform, mask, /*minsize=*/0,
|
||||
/*maxsize=*/0);
|
||||
}
|
||||
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_BMPSTRING)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_UNIVERSALSTRING)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_UTF8STRING)
|
||||
|
||||
int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
ossl_ssize_t len, int inform, unsigned long mask,
|
||||
ossl_ssize_t minsize, ossl_ssize_t maxsize) {
|
||||
if (len == -1) {
|
||||
len = strlen((const char *)in);
|
||||
}
|
||||
if (!mask) {
|
||||
mask = DIRSTRING_TYPE;
|
||||
}
|
||||
|
||||
int (*decode_func)(CBS *, uint32_t *);
|
||||
int error;
|
||||
switch (inform) {
|
||||
case MBSTRING_BMP:
|
||||
decode_func = CBS_get_ucs2_be;
|
||||
error = ASN1_R_INVALID_BMPSTRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_UNIV:
|
||||
decode_func = CBS_get_utf32_be;
|
||||
error = ASN1_R_INVALID_UNIVERSALSTRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_UTF8:
|
||||
decode_func = CBS_get_utf8;
|
||||
error = ASN1_R_INVALID_UTF8STRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_ASC:
|
||||
decode_func = CBS_get_latin1;
|
||||
error = ERR_R_INTERNAL_ERROR; // Latin-1 inputs are never invalid.
|
||||
break;
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNKNOWN_FORMAT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check |minsize| and |maxsize| and work out the minimal type, if any.
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, in, len);
|
||||
size_t utf8_len = 0, nchar = 0;
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!decode_func(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, error);
|
||||
return -1;
|
||||
}
|
||||
if (nchar == 0 && (inform == MBSTRING_BMP || inform == MBSTRING_UNIV) &&
|
||||
c == 0xfeff) {
|
||||
// Reject byte-order mark. We could drop it but that would mean
|
||||
// adding ambiguity around whether a BOM was included or not when
|
||||
// matching strings.
|
||||
//
|
||||
// For a little-endian UCS-2 string, the BOM will appear as 0xfffe
|
||||
// and will be rejected as noncharacter, below.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_CHARACTERS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update which output formats are still possible.
|
||||
if ((mask & B_ASN1_PRINTABLESTRING) && !asn1_is_printable(c)) {
|
||||
mask &= ~B_ASN1_PRINTABLESTRING;
|
||||
}
|
||||
if ((mask & B_ASN1_IA5STRING) && (c > 127)) {
|
||||
mask &= ~B_ASN1_IA5STRING;
|
||||
}
|
||||
if ((mask & B_ASN1_T61STRING) && (c > 0xff)) {
|
||||
mask &= ~B_ASN1_T61STRING;
|
||||
}
|
||||
if ((mask & B_ASN1_BMPSTRING) && (c > 0xffff)) {
|
||||
mask &= ~B_ASN1_BMPSTRING;
|
||||
}
|
||||
if (!mask) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_CHARACTERS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nchar++;
|
||||
utf8_len += CBB_get_utf8_len(c);
|
||||
if (maxsize > 0 && nchar > (size_t)maxsize) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
ERR_add_error_dataf("maxsize=%zu", (size_t)maxsize);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (minsize > 0 && nchar < (size_t)minsize) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
ERR_add_error_dataf("minsize=%zu", (size_t)minsize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Now work out output format and string type
|
||||
int str_type;
|
||||
int (*encode_func)(CBB *, uint32_t) = CBB_add_latin1;
|
||||
size_t size_estimate = nchar;
|
||||
int outform = MBSTRING_ASC;
|
||||
if (mask & B_ASN1_PRINTABLESTRING) {
|
||||
str_type = V_ASN1_PRINTABLESTRING;
|
||||
} else if (mask & B_ASN1_IA5STRING) {
|
||||
str_type = V_ASN1_IA5STRING;
|
||||
} else if (mask & B_ASN1_T61STRING) {
|
||||
str_type = V_ASN1_T61STRING;
|
||||
} else if (mask & B_ASN1_BMPSTRING) {
|
||||
str_type = V_ASN1_BMPSTRING;
|
||||
outform = MBSTRING_BMP;
|
||||
encode_func = CBB_add_ucs2_be;
|
||||
size_estimate = 2 * nchar;
|
||||
} else if (mask & B_ASN1_UNIVERSALSTRING) {
|
||||
str_type = V_ASN1_UNIVERSALSTRING;
|
||||
encode_func = CBB_add_utf32_be;
|
||||
size_estimate = 4 * nchar;
|
||||
outform = MBSTRING_UNIV;
|
||||
} else if (mask & B_ASN1_UTF8STRING) {
|
||||
str_type = V_ASN1_UTF8STRING;
|
||||
outform = MBSTRING_UTF8;
|
||||
encode_func = CBB_add_utf8;
|
||||
size_estimate = utf8_len;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_CHARACTERS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!out) {
|
||||
return str_type;
|
||||
}
|
||||
|
||||
int free_dest = 0;
|
||||
ASN1_STRING *dest;
|
||||
if (*out) {
|
||||
dest = *out;
|
||||
} else {
|
||||
free_dest = 1;
|
||||
dest = ASN1_STRING_type_new(str_type);
|
||||
if (!dest) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
CBB cbb;
|
||||
CBB_zero(&cbb);
|
||||
// If both the same type just copy across
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len = 0;
|
||||
if (inform == outform) {
|
||||
if (!ASN1_STRING_set(dest, in, len)) {
|
||||
goto err;
|
||||
}
|
||||
dest->type = str_type;
|
||||
*out = dest;
|
||||
return str_type;
|
||||
}
|
||||
if (!CBB_init(&cbb, size_estimate + 1)) {
|
||||
goto err;
|
||||
}
|
||||
CBS_init(&cbs, in, len);
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!decode_func(&cbs, &c) || !encode_func(&cbb, c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (/* OpenSSL historically NUL-terminated this value with a single byte,
|
||||
* even for |MBSTRING_BMP| and |MBSTRING_UNIV|. */
|
||||
!CBB_add_u8(&cbb, 0) || //
|
||||
!CBB_finish(&cbb, &data, &data_len) || //
|
||||
data_len < 1 || //
|
||||
data_len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
OPENSSL_free(data);
|
||||
goto err;
|
||||
}
|
||||
dest->type = str_type;
|
||||
ASN1_STRING_set0(dest, data, (int)data_len - 1);
|
||||
*out = dest;
|
||||
return str_type;
|
||||
|
||||
err:
|
||||
if (free_dest) {
|
||||
ASN1_STRING_free(dest);
|
||||
}
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int asn1_is_printable(uint32_t value) {
|
||||
if (value > 0x7f) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_isalnum(value) || //
|
||||
value == ' ' || value == '\'' || value == '(' || value == ')' ||
|
||||
value == '+' || value == ',' || value == '-' || value == '.' ||
|
||||
value == '/' || value == ':' || value == '=' || value == '?';
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int i2d_ASN1_OBJECT(const ASN1_OBJECT *in, unsigned char **outp) {
|
||||
if (in == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (in->length <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
CBB cbb, child;
|
||||
if (!CBB_init(&cbb, (size_t)in->length + 2) ||
|
||||
!CBB_add_asn1(&cbb, &child, CBS_ASN1_OBJECT) ||
|
||||
!CBB_add_bytes(&child, in->data, in->length)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
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) {
|
||||
size_t len = strlen(str);
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return -1;
|
||||
}
|
||||
return BIO_write(bp, str, (int)len) == (int)len ? (int)len : -1;
|
||||
}
|
||||
|
||||
int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a) {
|
||||
if (a == NULL || a->data == NULL) {
|
||||
return write_str(bp, "NULL");
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<char *>(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 **out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs, child;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
if (!CBS_get_asn1(&cbs, &child, CBS_ASN1_OBJECT)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint8_t *contents = CBS_data(&child);
|
||||
ASN1_OBJECT *ret = c2i_ASN1_OBJECT(out, &contents, CBS_len(&child));
|
||||
if (ret != NULL) {
|
||||
// |c2i_ASN1_OBJECT| should have consumed the entire input.
|
||||
assert(CBS_data(&cbs) == contents);
|
||||
*inp = CBS_data(&cbs);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
if (!CBS_is_valid_asn1_oid(&cbs)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ret = ASN1_OBJECT_create(NID_undef, *inp, (size_t)len,
|
||||
/*sn=*/NULL, /*ln=*/NULL);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (out != NULL) {
|
||||
ASN1_OBJECT_free(*out);
|
||||
*out = ret;
|
||||
}
|
||||
*inp += len; // All bytes were consumed.
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void) {
|
||||
ASN1_OBJECT *ret;
|
||||
|
||||
ret = (ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret->length = 0;
|
||||
ret->data = NULL;
|
||||
ret->nid = 0;
|
||||
ret->sn = NULL;
|
||||
ret->ln = NULL;
|
||||
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_OBJECT_free(ASN1_OBJECT *a) {
|
||||
if (a == NULL) {
|
||||
return;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
|
||||
OPENSSL_free((void *)a->sn);
|
||||
OPENSSL_free((void *)a->ln);
|
||||
a->sn = a->ln = NULL;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
|
||||
OPENSSL_free((void *)a->data);
|
||||
a->data = NULL;
|
||||
a->length = 0;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) {
|
||||
OPENSSL_free(a);
|
||||
}
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_create(int nid, const unsigned char *data, size_t len,
|
||||
const char *sn, const char *ln) {
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT o;
|
||||
o.sn = sn;
|
||||
o.ln = ln;
|
||||
o.data = data;
|
||||
o.nid = nid;
|
||||
o.length = (int)len;
|
||||
o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
||||
ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
return OBJ_dup(&o);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) {
|
||||
return ASN1_STRING_dup(x);
|
||||
}
|
||||
|
||||
int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
|
||||
const ASN1_OCTET_STRING *b) {
|
||||
return ASN1_STRING_cmp(a, b);
|
||||
}
|
||||
|
||||
int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d,
|
||||
int len) {
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
@@ -1,415 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#define ESC_FLAGS \
|
||||
(ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_QUOTE | ASN1_STRFLGS_ESC_CTRL | \
|
||||
ASN1_STRFLGS_ESC_MSB)
|
||||
|
||||
static int maybe_write(BIO *out, const void *buf, int len) {
|
||||
// If |out| is NULL, ignore the output but report the length.
|
||||
return out == NULL || BIO_write(out, buf, len) == len;
|
||||
}
|
||||
|
||||
static int is_control_character(unsigned char c) { return c < 32 || c == 127; }
|
||||
|
||||
static int do_esc_char(uint32_t c, unsigned long flags, char *do_quotes,
|
||||
BIO *out, int is_first, int is_last) {
|
||||
// |c| is a |uint32_t| because, depending on |ASN1_STRFLGS_UTF8_CONVERT|,
|
||||
// we may be escaping bytes or Unicode codepoints.
|
||||
char buf[16]; // Large enough for "\\W01234567".
|
||||
unsigned char u8 = (unsigned char)c;
|
||||
if (c > 0xffff) {
|
||||
snprintf(buf, sizeof(buf), "\\W%08" PRIX32, c);
|
||||
} else if (c > 0xff) {
|
||||
snprintf(buf, sizeof(buf), "\\U%04" PRIX32, c);
|
||||
} else if ((flags & ASN1_STRFLGS_ESC_MSB) && c > 0x7f) {
|
||||
snprintf(buf, sizeof(buf), "\\%02X", c);
|
||||
} else if ((flags & ASN1_STRFLGS_ESC_CTRL) && is_control_character(c)) {
|
||||
snprintf(buf, sizeof(buf), "\\%02X", c);
|
||||
} else if (flags & ASN1_STRFLGS_ESC_2253) {
|
||||
// See RFC 2253, sections 2.4 and 4.
|
||||
if (c == '\\' || c == '"') {
|
||||
// Quotes and backslashes are always escaped, quoted or not.
|
||||
snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
} else if (c == ',' || c == '+' || c == '<' || c == '>' || c == ';' ||
|
||||
(is_first && (c == ' ' || c == '#')) ||
|
||||
(is_last && (c == ' '))) {
|
||||
if (flags & ASN1_STRFLGS_ESC_QUOTE) {
|
||||
// No need to escape, just tell the caller to quote.
|
||||
if (do_quotes != NULL) {
|
||||
*do_quotes = 1;
|
||||
}
|
||||
return maybe_write(out, &u8, 1) ? 1 : -1;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
} else {
|
||||
return maybe_write(out, &u8, 1) ? 1 : -1;
|
||||
}
|
||||
} else if ((flags & ESC_FLAGS) && c == '\\') {
|
||||
// If any escape flags are set, also escape backslashes.
|
||||
snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
} else {
|
||||
return maybe_write(out, &u8, 1) ? 1 : -1;
|
||||
}
|
||||
|
||||
static_assert(sizeof(buf) < INT_MAX, "len may not fit in int");
|
||||
int len = (int)strlen(buf);
|
||||
return maybe_write(out, buf, len) ? len : -1;
|
||||
}
|
||||
|
||||
// This function sends each character in a buffer to do_esc_char(). It
|
||||
// interprets the content formats and converts to or from UTF8 as
|
||||
// appropriate.
|
||||
|
||||
static int do_buf(const unsigned char *buf, int buflen, int encoding,
|
||||
unsigned long flags, char *quotes, BIO *out) {
|
||||
int (*get_char)(CBS *cbs, uint32_t *out);
|
||||
int get_char_error;
|
||||
switch (encoding) {
|
||||
case MBSTRING_UNIV:
|
||||
get_char = CBS_get_utf32_be;
|
||||
get_char_error = ASN1_R_INVALID_UNIVERSALSTRING;
|
||||
break;
|
||||
case MBSTRING_BMP:
|
||||
get_char = CBS_get_ucs2_be;
|
||||
get_char_error = ASN1_R_INVALID_BMPSTRING;
|
||||
break;
|
||||
case MBSTRING_ASC:
|
||||
get_char = CBS_get_latin1;
|
||||
get_char_error = ERR_R_INTERNAL_ERROR; // Should not be possible.
|
||||
break;
|
||||
case MBSTRING_UTF8:
|
||||
get_char = CBS_get_utf8;
|
||||
get_char_error = ASN1_R_INVALID_UTF8STRING;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, buf, buflen);
|
||||
int outlen = 0;
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
const int is_first = CBS_data(&cbs) == buf;
|
||||
uint32_t c;
|
||||
if (!get_char(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, get_char_error);
|
||||
return -1;
|
||||
}
|
||||
const int is_last = CBS_len(&cbs) == 0;
|
||||
if (flags & ASN1_STRFLGS_UTF8_CONVERT) {
|
||||
uint8_t utf8_buf[6];
|
||||
CBB utf8_cbb;
|
||||
CBB_init_fixed(&utf8_cbb, utf8_buf, sizeof(utf8_buf));
|
||||
if (!CBB_add_utf8(&utf8_cbb, c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
return 1;
|
||||
}
|
||||
size_t utf8_len = CBB_len(&utf8_cbb);
|
||||
for (size_t i = 0; i < utf8_len; i++) {
|
||||
int len = do_esc_char(utf8_buf[i], flags, quotes, out,
|
||||
is_first && i == 0, is_last && i == utf8_len - 1);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
outlen += len;
|
||||
}
|
||||
} else {
|
||||
int len = do_esc_char(c, flags, quotes, out, is_first, is_last);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
outlen += len;
|
||||
}
|
||||
}
|
||||
return outlen;
|
||||
}
|
||||
|
||||
// This function hex dumps a buffer of characters
|
||||
|
||||
static int do_hex_dump(BIO *out, unsigned char *buf, int buflen) {
|
||||
static const char hexdig[] = "0123456789ABCDEF";
|
||||
unsigned char *p, *q;
|
||||
char hextmp[2];
|
||||
if (out) {
|
||||
p = buf;
|
||||
q = buf + buflen;
|
||||
while (p != q) {
|
||||
hextmp[0] = hexdig[*p >> 4];
|
||||
hextmp[1] = hexdig[*p & 0xf];
|
||||
if (!maybe_write(out, hextmp, 2)) {
|
||||
return -1;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return buflen << 1;
|
||||
}
|
||||
|
||||
// "dump" a string. This is done when the type is unknown, or the flags
|
||||
// request it. We can either dump the content octets or the entire DER
|
||||
// encoding. This uses the RFC 2253 #01234 format.
|
||||
|
||||
static int do_dump(unsigned long flags, BIO *out, const ASN1_STRING *str) {
|
||||
if (!maybe_write(out, "#", 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If we don't dump DER encoding just dump content octets
|
||||
if (!(flags & ASN1_STRFLGS_DUMP_DER)) {
|
||||
int outlen = do_hex_dump(out, str->data, str->length);
|
||||
if (outlen < 0) {
|
||||
return -1;
|
||||
}
|
||||
return outlen + 1;
|
||||
}
|
||||
|
||||
// Placing the ASN1_STRING in a temporary ASN1_TYPE allows the DER encoding
|
||||
// to readily obtained.
|
||||
ASN1_TYPE t;
|
||||
OPENSSL_memset(&t, 0, sizeof(ASN1_TYPE));
|
||||
asn1_type_set0_string(&t, (ASN1_STRING *)str);
|
||||
unsigned char *der_buf = NULL;
|
||||
int der_len = i2d_ASN1_TYPE(&t, &der_buf);
|
||||
if (der_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
int outlen = do_hex_dump(out, der_buf, der_len);
|
||||
OPENSSL_free(der_buf);
|
||||
if (outlen < 0) {
|
||||
return -1;
|
||||
}
|
||||
return outlen + 1;
|
||||
}
|
||||
|
||||
// string_type_to_encoding returns the |MBSTRING_*| constant for the encoding
|
||||
// used by the |ASN1_STRING| type |type|, or -1 if |tag| is not a string
|
||||
// type.
|
||||
static int string_type_to_encoding(int type) {
|
||||
// This function is sometimes passed ASN.1 universal types and sometimes
|
||||
// passed |ASN1_STRING| type values
|
||||
switch (type) {
|
||||
case V_ASN1_UTF8STRING:
|
||||
return MBSTRING_UTF8;
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_ISO64STRING:
|
||||
// |MBSTRING_ASC| refers to Latin-1, not ASCII.
|
||||
return MBSTRING_ASC;
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
return MBSTRING_UNIV;
|
||||
case V_ASN1_BMPSTRING:
|
||||
return MBSTRING_BMP;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// This is the main function, print out an ASN1_STRING taking note of various
|
||||
// escape and display options. Returns number of characters written or -1 if
|
||||
// an error occurred.
|
||||
|
||||
int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str,
|
||||
unsigned long flags) {
|
||||
int type = str->type;
|
||||
int outlen = 0;
|
||||
if (flags & ASN1_STRFLGS_SHOW_TYPE) {
|
||||
const char *tagname = ASN1_tag2str(type);
|
||||
outlen += strlen(tagname);
|
||||
if (!maybe_write(out, tagname, outlen) || !maybe_write(out, ":", 1)) {
|
||||
return -1;
|
||||
}
|
||||
outlen++;
|
||||
}
|
||||
|
||||
// Decide what to do with |str|, either dump the contents or display it.
|
||||
int encoding;
|
||||
if (flags & ASN1_STRFLGS_DUMP_ALL) {
|
||||
// Dump everything.
|
||||
encoding = -1;
|
||||
} else if (flags & ASN1_STRFLGS_IGNORE_TYPE) {
|
||||
// Ignore the string type and interpret the contents as Latin-1.
|
||||
encoding = MBSTRING_ASC;
|
||||
} else {
|
||||
encoding = string_type_to_encoding(type);
|
||||
if (encoding == -1 && (flags & ASN1_STRFLGS_DUMP_UNKNOWN) == 0) {
|
||||
encoding = MBSTRING_ASC;
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding == -1) {
|
||||
int len = do_dump(flags, out, str);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
outlen += len;
|
||||
return outlen;
|
||||
}
|
||||
|
||||
// Measure the length.
|
||||
char quotes = 0;
|
||||
int len = do_buf(str->data, str->length, encoding, flags, "es, NULL);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
outlen += len;
|
||||
if (quotes) {
|
||||
outlen += 2;
|
||||
}
|
||||
if (!out) {
|
||||
return outlen;
|
||||
}
|
||||
|
||||
// Encode the value.
|
||||
if ((quotes && !maybe_write(out, "\"", 1)) ||
|
||||
do_buf(str->data, str->length, encoding, flags, NULL, out) < 0 ||
|
||||
(quotes && !maybe_write(out, "\"", 1))) {
|
||||
return -1;
|
||||
}
|
||||
return outlen;
|
||||
}
|
||||
|
||||
int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str,
|
||||
unsigned long flags) {
|
||||
BIO *bio = NULL;
|
||||
if (fp != NULL) {
|
||||
// If |fp| is NULL, this function returns the number of bytes without
|
||||
// writing.
|
||||
bio = BIO_new_fp(fp, BIO_NOCLOSE);
|
||||
if (bio == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
int ret = ASN1_STRING_print_ex(bio, str, flags);
|
||||
BIO_free(bio);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) {
|
||||
if (!in) {
|
||||
return -1;
|
||||
}
|
||||
int mbflag = string_type_to_encoding(in->type);
|
||||
if (mbflag == -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNKNOWN_TAG);
|
||||
return -1;
|
||||
}
|
||||
ASN1_STRING stmp, *str = &stmp;
|
||||
stmp.data = NULL;
|
||||
stmp.length = 0;
|
||||
stmp.flags = 0;
|
||||
int ret =
|
||||
ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
*out = stmp.data;
|
||||
return stmp.length;
|
||||
}
|
||||
|
||||
int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) {
|
||||
int i, n;
|
||||
char buf[80];
|
||||
const char *p;
|
||||
|
||||
if (v == NULL) {
|
||||
return 0;
|
||||
}
|
||||
n = 0;
|
||||
p = (const char *)v->data;
|
||||
for (i = 0; i < v->length; i++) {
|
||||
if ((p[i] > '~') || ((p[i] < ' ') && (p[i] != '\n') && (p[i] != '\r'))) {
|
||||
buf[n] = '.';
|
||||
} else {
|
||||
buf[n] = p[i];
|
||||
}
|
||||
n++;
|
||||
if (n >= 80) {
|
||||
if (BIO_write(bp, buf, n) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
if (n > 0) {
|
||||
if (BIO_write(bp, buf, n) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) {
|
||||
if (tm->type == V_ASN1_UTCTIME) {
|
||||
return ASN1_UTCTIME_print(bp, tm);
|
||||
}
|
||||
if (tm->type == V_ASN1_GENERALIZEDTIME) {
|
||||
return ASN1_GENERALIZEDTIME_print(bp, tm);
|
||||
}
|
||||
BIO_puts(bp, "Bad time value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *const mon[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, tm->data, tm->length);
|
||||
struct tm utc;
|
||||
if (!CBS_parse_generalized_time(&cbs, &utc, /*allow_timezone_offset=*/0)) {
|
||||
BIO_puts(bp, "Bad time value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d GMT", mon[utc.tm_mon],
|
||||
utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec,
|
||||
utc.tm_year + 1900) > 0;
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, tm->data, tm->length);
|
||||
struct tm utc;
|
||||
if (!CBS_parse_utc_time(&cbs, &utc, /*allow_timezone_offset=*/0)) {
|
||||
BIO_puts(bp, "Bad time value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d GMT", mon[utc.tm_mon],
|
||||
utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec,
|
||||
utc.tm_year + 1900) > 0;
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../lhash/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
DEFINE_LHASH_OF(ASN1_STRING_TABLE)
|
||||
|
||||
static LHASH_OF(ASN1_STRING_TABLE) *string_tables = NULL;
|
||||
static CRYPTO_MUTEX string_tables_lock = CRYPTO_MUTEX_INIT;
|
||||
|
||||
void ASN1_STRING_set_default_mask(unsigned long mask) {}
|
||||
|
||||
unsigned long ASN1_STRING_get_default_mask(void) { return B_ASN1_UTF8STRING; }
|
||||
|
||||
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,
|
||||
ossl_ssize_t len, int inform, int nid) {
|
||||
ASN1_STRING *str = NULL;
|
||||
int ret;
|
||||
if (!out) {
|
||||
out = &str;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// Now the tables and helper functions for the string table:
|
||||
|
||||
// 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_email_address 128
|
||||
#define ub_serial_number 64
|
||||
|
||||
// This table must be kept in NID order
|
||||
|
||||
static const ASN1_STRING_TABLE tbl_standard[] = {
|
||||
{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
|
||||
{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
|
||||
{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE,
|
||||
0},
|
||||
{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
|
||||
{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING,
|
||||
STABLE_NO_MASK},
|
||||
{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
|
||||
{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
|
||||
{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}};
|
||||
|
||||
static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) {
|
||||
if (a->nid < b->nid) {
|
||||
return -1;
|
||||
}
|
||||
if (a->nid > b->nid) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int table_cmp_void(const void *a, const void *b) {
|
||||
return table_cmp(reinterpret_cast<const ASN1_STRING_TABLE *>(a),
|
||||
reinterpret_cast<const ASN1_STRING_TABLE *>(b));
|
||||
}
|
||||
|
||||
static uint32_t table_hash(const ASN1_STRING_TABLE *tbl) {
|
||||
return OPENSSL_hash32(&tbl->nid, sizeof(tbl->nid));
|
||||
}
|
||||
|
||||
static const ASN1_STRING_TABLE *asn1_string_table_get(int nid) {
|
||||
ASN1_STRING_TABLE key;
|
||||
key.nid = nid;
|
||||
const ASN1_STRING_TABLE *tbl = reinterpret_cast<ASN1_STRING_TABLE *>(
|
||||
bsearch(&key, tbl_standard, OPENSSL_ARRAY_SIZE(tbl_standard),
|
||||
sizeof(ASN1_STRING_TABLE), table_cmp_void));
|
||||
if (tbl != NULL) {
|
||||
return tbl;
|
||||
}
|
||||
|
||||
CRYPTO_MUTEX_lock_read(&string_tables_lock);
|
||||
if (string_tables != NULL) {
|
||||
tbl = lh_ASN1_STRING_TABLE_retrieve(string_tables, &key);
|
||||
}
|
||||
CRYPTO_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;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
CRYPTO_MUTEX_lock_write(&string_tables_lock);
|
||||
|
||||
ASN1_STRING_TABLE *tbl = NULL;
|
||||
if (string_tables == NULL) {
|
||||
string_tables = lh_ASN1_STRING_TABLE_new(table_hash, table_cmp);
|
||||
if (string_tables == NULL) {
|
||||
goto err;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
tbl = reinterpret_cast<ASN1_STRING_TABLE *>(
|
||||
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_MUTEX_unlock_write(&string_tables_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_STRING_TABLE_cleanup(void) {}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/posix_time.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// This is an implementation of the ASN1 Time structure which is: Time ::=
|
||||
// CHOICE { utcTime UTCTime, generalTime GeneralizedTime } written by Steve
|
||||
// Henson.
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_TIME)
|
||||
|
||||
ASN1_TIME *ASN1_TIME_set_posix(ASN1_TIME *s, int64_t posix_time) {
|
||||
return ASN1_TIME_adj(s, posix_time, 0, 0);
|
||||
}
|
||||
|
||||
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t time) {
|
||||
return ASN1_TIME_adj(s, time, 0, 0);
|
||||
}
|
||||
|
||||
static int fits_in_utc_time(const struct tm *tm) {
|
||||
return 50 <= tm->tm_year && tm->tm_year < 150;
|
||||
}
|
||||
|
||||
ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, int64_t posix_time, int offset_day,
|
||||
long offset_sec) {
|
||||
struct tm tm;
|
||||
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &tm)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ERROR_GETTING_TIME);
|
||||
return NULL;
|
||||
}
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&tm, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (fits_in_utc_time(&tm)) {
|
||||
return ASN1_UTCTIME_adj(s, posix_time, offset_day, offset_sec);
|
||||
}
|
||||
return ASN1_GENERALIZEDTIME_adj(s, posix_time, offset_day, offset_sec);
|
||||
}
|
||||
|
||||
int ASN1_TIME_check(const ASN1_TIME *t) {
|
||||
if (t->type == V_ASN1_GENERALIZEDTIME) {
|
||||
return ASN1_GENERALIZEDTIME_check(t);
|
||||
} else if (t->type == V_ASN1_UTCTIME) {
|
||||
return ASN1_UTCTIME_check(t);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert an ASN1_TIME structure to GeneralizedTime
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *in,
|
||||
ASN1_GENERALIZEDTIME **out) {
|
||||
if (!ASN1_TIME_check(in)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ret = NULL;
|
||||
if (!out || !*out) {
|
||||
if (!(ret = ASN1_GENERALIZEDTIME_new())) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
// If already GeneralizedTime just copy across
|
||||
if (in->type == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!ASN1_STRING_set(ret, in->data, in->length)) {
|
||||
goto err;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Grow the string to accomodate the two-digit century.
|
||||
if (!ASN1_STRING_set(ret, NULL, in->length + 2)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
{
|
||||
char *const out_str = (char *)ret->data;
|
||||
// |ASN1_STRING_set| also allocates an additional byte for a trailing NUL.
|
||||
const size_t out_str_capacity = in->length + 2 + 1;
|
||||
// Work out the century and prepend
|
||||
if (in->data[0] >= '5') {
|
||||
OPENSSL_strlcpy(out_str, "19", out_str_capacity);
|
||||
} else {
|
||||
OPENSSL_strlcpy(out_str, "20", out_str_capacity);
|
||||
}
|
||||
OPENSSL_strlcat(out_str, (const char *)in->data, out_str_capacity);
|
||||
}
|
||||
|
||||
done:
|
||||
if (out != NULL && *out == NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (out == NULL || *out != ret) {
|
||||
ASN1_GENERALIZEDTIME_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) {
|
||||
return ASN1_UTCTIME_set_string(s, str) ||
|
||||
ASN1_GENERALIZEDTIME_set_string(s, str);
|
||||
}
|
||||
|
||||
int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str) {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, strlen(str));
|
||||
int type;
|
||||
struct tm tm;
|
||||
if (CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
type = V_ASN1_UTCTIME;
|
||||
} else if (CBS_parse_generalized_time(&cbs, &tm,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
type = V_ASN1_GENERALIZEDTIME;
|
||||
if (fits_in_utc_time(&tm)) {
|
||||
type = V_ASN1_UTCTIME;
|
||||
CBS_skip(&cbs, 2);
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
return 0;
|
||||
}
|
||||
s->type = type;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t,
|
||||
int allow_timezone_offset) {
|
||||
if (t == NULL) {
|
||||
if (OPENSSL_posix_to_tm(time(NULL), tm)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (t->type == V_ASN1_UTCTIME) {
|
||||
return asn1_utctime_to_tm(tm, t, allow_timezone_offset);
|
||||
} else if (t->type == V_ASN1_GENERALIZEDTIME) {
|
||||
return asn1_generalizedtime_to_tm(tm, t);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_TIME_diff(int *out_days, int *out_seconds, const ASN1_TIME *from,
|
||||
const ASN1_TIME *to) {
|
||||
struct tm tm_from, tm_to;
|
||||
if (!asn1_time_to_tm(&tm_from, from, /*allow_timezone_offset=*/1)) {
|
||||
return 0;
|
||||
}
|
||||
if (!asn1_time_to_tm(&tm_to, to, /*allow_timezone_offset=*/1)) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_gmtime_diff(out_days, out_seconds, &tm_from, &tm_to);
|
||||
}
|
||||
|
||||
int ASN1_TIME_to_posix_nonstandard(const ASN1_TIME *t, int64_t *out_time) {
|
||||
struct tm tm;
|
||||
if (!asn1_time_to_tm(&tm, t, /*allow_timezone_offset=*/1)) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_tm_to_posix(&tm, out_time);
|
||||
}
|
||||
|
||||
// The functions below do *not* permissively allow the use of four digit
|
||||
// timezone offsets in UTC times, as is done elsewhere in the code. They are
|
||||
// both new API, and used internally to X509_cmp_time. This is to discourage the
|
||||
// use of nonstandard times in new code, and to ensure that this code behaves
|
||||
// correctly in X509_cmp_time which historically did its own time validations
|
||||
// slightly different than the many other copies of X.509 time validation
|
||||
// sprinkled through the codebase. The custom checks in X509_cmp_time meant that
|
||||
// it did not allow four digit timezone offsets in UTC times.
|
||||
int ASN1_TIME_to_time_t(const ASN1_TIME *t, time_t *out_time) {
|
||||
struct tm tm;
|
||||
if (!asn1_time_to_tm(&tm, t, /*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_timegm(&tm, out_time);
|
||||
}
|
||||
|
||||
int ASN1_TIME_to_posix(const ASN1_TIME *t, int64_t *out_time) {
|
||||
struct tm tm;
|
||||
if (!asn1_time_to_tm(&tm, t, /*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_tm_to_posix(&tm, out_time);
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_TYPE_get(const ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
case V_ASN1_BOOLEAN:
|
||||
return a->type;
|
||||
case V_ASN1_OBJECT:
|
||||
return a->value.object != NULL ? a->type : 0;
|
||||
default:
|
||||
return a->value.asn1_string != NULL ? a->type : 0;
|
||||
}
|
||||
}
|
||||
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
return NULL;
|
||||
case V_ASN1_BOOLEAN:
|
||||
return a->value.boolean ? (void *)0xff : NULL;
|
||||
case V_ASN1_OBJECT:
|
||||
return a->value.object;
|
||||
default:
|
||||
return a->value.asn1_string;
|
||||
}
|
||||
}
|
||||
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str) {
|
||||
// |ASN1_STRING| types are almost the same as |ASN1_TYPE| types, except that
|
||||
// the negative flag is not reflected into |ASN1_TYPE|.
|
||||
int type = str->type;
|
||||
if (type == V_ASN1_NEG_INTEGER) {
|
||||
type = V_ASN1_INTEGER;
|
||||
} else if (type == V_ASN1_NEG_ENUMERATED) {
|
||||
type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
|
||||
// These types are not |ASN1_STRING| types and use a different
|
||||
// representation when stored in |ASN1_TYPE|.
|
||||
assert(type != V_ASN1_NULL && type != V_ASN1_OBJECT &&
|
||||
type != V_ASN1_BOOLEAN);
|
||||
ASN1_TYPE_set(a, type, str);
|
||||
}
|
||||
|
||||
void asn1_type_cleanup(ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
a->value.ptr = NULL;
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
a->value.boolean = ASN1_BOOLEAN_NONE;
|
||||
break;
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free(a->value.object);
|
||||
a->value.object = NULL;
|
||||
break;
|
||||
default:
|
||||
ASN1_STRING_free(a->value.asn1_string);
|
||||
a->value.asn1_string = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) {
|
||||
asn1_type_cleanup(a);
|
||||
a->type = type;
|
||||
switch (type) {
|
||||
case V_ASN1_NULL:
|
||||
a->value.ptr = NULL;
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
a->value.boolean = value ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
|
||||
break;
|
||||
case V_ASN1_OBJECT:
|
||||
a->value.object = reinterpret_cast<ASN1_OBJECT *>(value);
|
||||
break;
|
||||
default:
|
||||
a->value.asn1_string = reinterpret_cast<ASN1_STRING *>(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) {
|
||||
if (!value || (type == V_ASN1_BOOLEAN)) {
|
||||
void *p = (void *)value;
|
||||
ASN1_TYPE_set(a, type, p);
|
||||
} else if (type == V_ASN1_OBJECT) {
|
||||
ASN1_OBJECT *odup;
|
||||
odup = OBJ_dup(reinterpret_cast<const ASN1_OBJECT *>(value));
|
||||
if (!odup) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, type, odup);
|
||||
} else {
|
||||
ASN1_STRING *sdup;
|
||||
sdup = ASN1_STRING_dup(reinterpret_cast<const ASN1_STRING *>(value));
|
||||
if (!sdup) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, type, sdup);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Returns 0 if they are equal, != 0 otherwise.
|
||||
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b) {
|
||||
int result = -1;
|
||||
|
||||
if (!a || !b || a->type != b->type) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (a->type) {
|
||||
case V_ASN1_OBJECT:
|
||||
result = OBJ_cmp(a->value.object, b->value.object);
|
||||
break;
|
||||
case V_ASN1_NULL:
|
||||
result = 0; // They do not have content.
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
result = a->value.boolean - b->value.boolean;
|
||||
break;
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
case V_ASN1_BIT_STRING:
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_OTHER:
|
||||
default:
|
||||
result = ASN1_STRING_cmp(a->value.asn1_string, b->value.asn1_string);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d,
|
||||
int allow_timezone_offset) {
|
||||
if (d->type != V_ASN1_UTCTIME) {
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, d->data, (size_t)d->length);
|
||||
if (!CBS_parse_utc_time(&cbs, tm, allow_timezone_offset)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_check(const ASN1_UTCTIME *d) {
|
||||
return asn1_utctime_to_tm(NULL, d, /*allow_timezone_offset=*/1);
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) {
|
||||
// Although elsewhere we allow timezone offsets with UTCTime, to be compatible
|
||||
// with some existing misissued certificates, this function is used to
|
||||
// construct new certificates and can be stricter.
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, str, len)) {
|
||||
return 0;
|
||||
}
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, int64_t posix_time) {
|
||||
return ASN1_UTCTIME_adj(s, posix_time, 0, 0);
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time,
|
||||
int offset_day, long offset_sec) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.tm_year < 50 || data.tm_year >= 150) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[14];
|
||||
int ret = snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year % 100, data.tm_mon + 1, data.tm_mday,
|
||||
data.tm_hour, data.tm_min, data.tm_sec);
|
||||
// |snprintf| must write exactly 15 bytes (plus the NUL) to the buffer.
|
||||
BSSL_CHECK(ret == static_cast<int>(sizeof(buf) - 1));
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
free_s = 1;
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(s, buf, strlen(buf))) {
|
||||
if (free_s) {
|
||||
ASN1_UTCTIME_free(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
return s;
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// Cross-module errors from crypto/x509/i2d_pr.c.
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_PUBLIC_KEY_TYPE)
|
||||
|
||||
// Cross-module errors from crypto/x509/algorithm.c.
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, CONTEXT_NOT_INITIALISED)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, DIGEST_AND_KEY_TYPE_NOT_SUPPORTED)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_MESSAGE_DIGEST_ALGORITHM)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_SIGNATURE_ALGORITHM)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, WRONG_PUBLIC_KEY_TYPE)
|
||||
// Cross-module errors from crypto/x509/asn1_gen.c. TODO(davidben): Remove
|
||||
// these once asn1_gen.c is gone.
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, DEPTH_EXCEEDED)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_BITSTRING_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_BOOLEAN)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_HEX)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_IMPLICIT_TAG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_INTEGER)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_NESTED_TAGGING)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_NULL_VALUE)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_OBJECT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_TIME_VALUE)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INTEGER_NOT_ASCII_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_MODIFIER)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_NUMBER)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, LIST_ERROR)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, MISSING_VALUE)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, NOT_ASCII_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, OBJECT_NOT_ASCII_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, SEQUENCE_OR_SET_NEEDS_CONFIG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, TIME_NOT_ASCII_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE)
|
||||
|
||||
// Limit |ASN1_STRING|s to 64 MiB of data. Most of this module, as well as
|
||||
// downstream code, does not correctly handle overflow. We cap string fields
|
||||
// more tightly than strictly necessary to fit in |int|. This is not expected to
|
||||
// impact real world uses of this field.
|
||||
//
|
||||
// In particular, this limit is small enough that the bit count of a BIT STRING
|
||||
// comfortably fits in an |int|, with room for arithmetic.
|
||||
#define ASN1_STRING_MAX (64 * 1024 * 1024)
|
||||
|
||||
static void asn1_put_length(unsigned char **pp, int length);
|
||||
|
||||
int ASN1_get_object(const unsigned char **inp, long *out_len, int *out_tag,
|
||||
int *out_class, long in_len) {
|
||||
if (in_len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
CBS_ASN1_TAG tag;
|
||||
CBS cbs, body;
|
||||
CBS_init(&cbs, *inp, (size_t)in_len);
|
||||
if (!CBS_get_any_asn1(&cbs, &body, &tag) ||
|
||||
// Bound the length to comfortably fit in an int. Lengths in this
|
||||
// module often switch between int and long without overflow checks.
|
||||
CBS_len(&body) > INT_MAX / 2) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
// Convert between tag representations.
|
||||
int tag_class = (tag & CBS_ASN1_CLASS_MASK) >> CBS_ASN1_TAG_SHIFT;
|
||||
int constructed = (tag & CBS_ASN1_CONSTRUCTED) >> CBS_ASN1_TAG_SHIFT;
|
||||
int tag_number = tag & CBS_ASN1_TAG_NUMBER_MASK;
|
||||
|
||||
// To avoid ambiguity with V_ASN1_NEG, impose a limit on universal tags.
|
||||
if (tag_class == V_ASN1_UNIVERSAL && tag_number > V_ASN1_MAX_UNIVERSAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
*inp = CBS_data(&body);
|
||||
*out_len = CBS_len(&body);
|
||||
*out_tag = tag_number;
|
||||
*out_class = tag_class;
|
||||
return constructed;
|
||||
}
|
||||
|
||||
// class 0 is constructed constructed == 2 for indefinite length constructed
|
||||
void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
|
||||
int xclass) {
|
||||
unsigned char *p = *pp;
|
||||
int i, ttag;
|
||||
|
||||
i = (constructed) ? V_ASN1_CONSTRUCTED : 0;
|
||||
i |= (xclass & V_ASN1_PRIVATE);
|
||||
if (tag < 31) {
|
||||
*(p++) = i | (tag & V_ASN1_PRIMITIVE_TAG);
|
||||
} else {
|
||||
*(p++) = i | V_ASN1_PRIMITIVE_TAG;
|
||||
for (i = 0, ttag = tag; ttag > 0; i++) {
|
||||
ttag >>= 7;
|
||||
}
|
||||
ttag = i;
|
||||
while (i-- > 0) {
|
||||
p[i] = tag & 0x7f;
|
||||
if (i != (ttag - 1)) {
|
||||
p[i] |= 0x80;
|
||||
}
|
||||
tag >>= 7;
|
||||
}
|
||||
p += ttag;
|
||||
}
|
||||
if (constructed == 2) {
|
||||
*(p++) = 0x80;
|
||||
} else {
|
||||
asn1_put_length(&p, length);
|
||||
}
|
||||
*pp = p;
|
||||
}
|
||||
|
||||
int ASN1_put_eoc(unsigned char **pp) {
|
||||
// This function is no longer used in the library, but some external code
|
||||
// uses it.
|
||||
unsigned char *p = *pp;
|
||||
*p++ = 0;
|
||||
*p++ = 0;
|
||||
*pp = p;
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void asn1_put_length(unsigned char **pp, int length) {
|
||||
unsigned char *p = *pp;
|
||||
int i, l;
|
||||
if (length <= 127) {
|
||||
*(p++) = (unsigned char)length;
|
||||
} else {
|
||||
l = length;
|
||||
for (i = 0; l > 0; i++) {
|
||||
l >>= 8;
|
||||
}
|
||||
*(p++) = i | 0x80;
|
||||
l = i;
|
||||
while (i-- > 0) {
|
||||
p[i] = length & 0xff;
|
||||
length >>= 8;
|
||||
}
|
||||
p += l;
|
||||
}
|
||||
*pp = p;
|
||||
}
|
||||
|
||||
int ASN1_object_size(int constructed, int length, int tag) {
|
||||
int ret = 1;
|
||||
if (length < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (tag >= 31) {
|
||||
while (tag > 0) {
|
||||
tag >>= 7;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
if (constructed == 2) {
|
||||
ret += 3;
|
||||
} else {
|
||||
ret++;
|
||||
if (length > 127) {
|
||||
int tmplen = length;
|
||||
while (tmplen > 0) {
|
||||
tmplen >>= 8;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret >= INT_MAX - length) {
|
||||
return -1;
|
||||
}
|
||||
return ret + length;
|
||||
}
|
||||
|
||||
int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) {
|
||||
if (str == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (!ASN1_STRING_set(dst, str->data, str->length)) {
|
||||
return 0;
|
||||
}
|
||||
dst->type = str->type;
|
||||
dst->flags = str->flags;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) {
|
||||
ASN1_STRING *ret;
|
||||
if (!str) {
|
||||
return NULL;
|
||||
}
|
||||
ret = ASN1_STRING_new();
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
if (!ASN1_STRING_copy(ret, str)) {
|
||||
ASN1_STRING_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
|
||||
const char *data = reinterpret_cast<const char *>(_data);
|
||||
size_t len;
|
||||
if (len_s < 0) {
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
len = strlen(data);
|
||||
} else {
|
||||
len = (size_t)len_s;
|
||||
}
|
||||
|
||||
static_assert(ASN1_STRING_MAX < INT_MAX, "len will not overflow int");
|
||||
if (len > ASN1_STRING_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (str->length <= (int)len || str->data == NULL) {
|
||||
unsigned char *c = str->data;
|
||||
if (c == NULL) {
|
||||
str->data = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len + 1));
|
||||
} else {
|
||||
str->data = reinterpret_cast<uint8_t *>(OPENSSL_realloc(c, len + 1));
|
||||
}
|
||||
|
||||
if (str->data == NULL) {
|
||||
str->data = c;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
str->length = (int)len;
|
||||
if (data != NULL) {
|
||||
OPENSSL_memcpy(str->data, data, len);
|
||||
// Historically, OpenSSL would NUL-terminate most (but not all)
|
||||
// |ASN1_STRING|s, in case anyone accidentally passed |str->data| into a
|
||||
// function expecting a C string. We retain this behavior for compatibility,
|
||||
// but code must not rely on this. See CVE-2021-3712.
|
||||
str->data[len] = '\0';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) {
|
||||
OPENSSL_free(str->data);
|
||||
str->data = reinterpret_cast<uint8_t *>(data);
|
||||
str->length = len;
|
||||
}
|
||||
|
||||
ASN1_STRING *ASN1_STRING_new(void) {
|
||||
return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
|
||||
}
|
||||
|
||||
ASN1_STRING *ASN1_STRING_type_new(int type) {
|
||||
ASN1_STRING *ret;
|
||||
|
||||
ret = (ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret->length = 0;
|
||||
ret->type = type;
|
||||
ret->data = NULL;
|
||||
ret->flags = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_STRING_free(ASN1_STRING *str) {
|
||||
if (str == NULL) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(str->data);
|
||||
OPENSSL_free(str);
|
||||
}
|
||||
|
||||
int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
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) { return str->length; }
|
||||
|
||||
int ASN1_STRING_type(const ASN1_STRING *str) { return str->type; }
|
||||
|
||||
unsigned char *ASN1_STRING_data(ASN1_STRING *str) { return str->data; }
|
||||
|
||||
const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *str) {
|
||||
return str->data;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
|
||||
const char *ASN1_tag2str(int tag) {
|
||||
static const char *const tag2str[] = {
|
||||
"EOC",
|
||||
"BOOLEAN",
|
||||
"INTEGER",
|
||||
"BIT STRING",
|
||||
"OCTET STRING",
|
||||
"NULL",
|
||||
"OBJECT",
|
||||
"OBJECT DESCRIPTOR",
|
||||
"EXTERNAL",
|
||||
"REAL",
|
||||
"ENUMERATED",
|
||||
"<ASN1 11>",
|
||||
"UTF8STRING",
|
||||
"<ASN1 13>",
|
||||
"<ASN1 14>",
|
||||
"<ASN1 15>",
|
||||
"SEQUENCE",
|
||||
"SET",
|
||||
"NUMERICSTRING",
|
||||
"PRINTABLESTRING",
|
||||
"T61STRING",
|
||||
"VIDEOTEXSTRING",
|
||||
"IA5STRING",
|
||||
"UTCTIME",
|
||||
"GENERALIZEDTIME",
|
||||
"GRAPHICSTRING",
|
||||
"VISIBLESTRING",
|
||||
"GENERALSTRING",
|
||||
"UNIVERSALSTRING",
|
||||
"<ASN1 29>",
|
||||
"BMPSTRING",
|
||||
};
|
||||
|
||||
if ((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) {
|
||||
tag &= ~V_ASN1_NEG;
|
||||
}
|
||||
|
||||
if (tag < 0 || tag > 30) {
|
||||
return "(unknown)";
|
||||
}
|
||||
return tag2str[tag];
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
|
||||
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **out) {
|
||||
uint8_t *new_data = NULL;
|
||||
int len = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(obj), &new_data, it);
|
||||
if (len <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ENCODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_STRING *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_STRING_new();
|
||||
if (ret == NULL) {
|
||||
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 = 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(reinterpret_cast<ASN1_VALUE *>(ret), it);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) {
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
if (BIO_write(bp, "-", 1) != 1) {
|
||||
goto err;
|
||||
}
|
||||
n = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) {
|
||||
return i2a_ASN1_INTEGER(bp, a);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) {
|
||||
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, "0", 1) != 1) {
|
||||
goto err;
|
||||
}
|
||||
n = 1;
|
||||
} 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;
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
// Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Wrapper functions for time functions.
|
||||
|
||||
// OPENSSL_gmtime converts a time_t value in |time| which must be in the range
|
||||
// of year 0000 to 9999 to a broken out time value in |tm|. On success |tm| is
|
||||
// returned. On failure NULL is returned.
|
||||
OPENSSL_EXPORT struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result);
|
||||
|
||||
// OPENSSL_gmtime_adj returns one on success, and updates |tm| by adding
|
||||
// |offset_day| days and |offset_sec| seconds. It returns zero on failure. |tm|
|
||||
// must be in the range of year 0000 to 9999 both before and after the update or
|
||||
// a failure will be returned.
|
||||
OPENSSL_EXPORT int OPENSSL_gmtime_adj(struct tm *tm, int offset_day,
|
||||
int64_t offset_sec);
|
||||
|
||||
// OPENSSL_gmtime_diff calculates the difference between |from| and |to|. It
|
||||
// returns one, and outputs the difference as a number of days and seconds in
|
||||
// |*out_days| and |*out_secs| on success. It returns zero on failure. Both
|
||||
// |from| and |to| must be in the range of year 0000 to 9999 or a failure will
|
||||
// be returned.
|
||||
OPENSSL_EXPORT int OPENSSL_gmtime_diff(int *out_days, int *out_secs,
|
||||
const struct tm *from,
|
||||
const struct tm *to);
|
||||
|
||||
// Internal ASN1 structures and functions: not for application use
|
||||
|
||||
// These are used internally in the ASN1_OBJECT to keep track of
|
||||
// whether the names and data need to be free()ed
|
||||
#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 // internal use
|
||||
#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 // internal use
|
||||
#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 // internal use
|
||||
|
||||
// An asn1_object_st (aka |ASN1_OBJECT|) represents an ASN.1 OBJECT IDENTIFIER.
|
||||
// Note: Mutating an |ASN1_OBJECT| is only permitted when initializing it. The
|
||||
// library maintains a table of static |ASN1_OBJECT|s, which may be referenced
|
||||
// by non-const |ASN1_OBJECT| pointers. Code which receives an |ASN1_OBJECT|
|
||||
// pointer externally must assume it is immutable, even if the pointer is not
|
||||
// const.
|
||||
struct asn1_object_st {
|
||||
const char *sn, *ln;
|
||||
int nid;
|
||||
int length;
|
||||
const unsigned char *data; // data remains const after init
|
||||
int flags; // Should we free this one
|
||||
};
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void);
|
||||
|
||||
// ASN1_ENCODING is used to save the received encoding of an ASN.1 type. This
|
||||
// avoids problems with invalid encodings that break signatures.
|
||||
typedef struct ASN1_ENCODING_st {
|
||||
// enc is the saved DER encoding. Its ownership is determined by |buf|.
|
||||
uint8_t *enc;
|
||||
// len is the length of |enc|. If zero, there is no saved encoding.
|
||||
size_t len;
|
||||
// buf, if non-NULL, is the |CRYPTO_BUFFER| that |enc| points into. If NULL,
|
||||
// |enc| must be released with |OPENSSL_free|.
|
||||
CRYPTO_BUFFER *buf;
|
||||
} ASN1_ENCODING;
|
||||
|
||||
OPENSSL_EXPORT int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d,
|
||||
int allow_timezone_offset);
|
||||
OPENSSL_EXPORT int asn1_generalizedtime_to_tm(struct tm *tm,
|
||||
const ASN1_GENERALIZEDTIME *d);
|
||||
|
||||
int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
|
||||
// ASN1_item_ex_d2i parses |len| bytes from |*in| as a structure of type |it|
|
||||
// and writes the result to |*pval|. If |tag| is non-negative, |it| is
|
||||
// implicitly tagged with the tag specified by |tag| and |aclass|. If |opt| is
|
||||
// non-zero, the value is optional. If |buf| is non-NULL, |*in| must point into
|
||||
// |buf|.
|
||||
//
|
||||
// This function returns one and advances |*in| if an object was successfully
|
||||
// parsed, -1 if an optional value was successfully skipped, and zero on error.
|
||||
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt,
|
||||
CRYPTO_BUFFER *buf);
|
||||
|
||||
// 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);
|
||||
|
||||
void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
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);
|
||||
|
||||
// asn1_enc_save saves |inlen| bytes from |in| as |*pval|'s saved encoding. It
|
||||
// returns one on success and zero on error. If |buf| is non-NULL, |in| must
|
||||
// point into |buf|.
|
||||
int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t inlen,
|
||||
const ASN1_ITEM *it, CRYPTO_BUFFER *buf);
|
||||
|
||||
// asn1_encoding_clear clears the cached encoding in |enc|.
|
||||
void asn1_encoding_clear(ASN1_ENCODING *enc);
|
||||
|
||||
// asn1_type_value_as_pointer returns |a|'s value in pointer form. This is
|
||||
// usually the value object but, for BOOLEAN values, is 0 or 0xff cast to
|
||||
// a pointer.
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
|
||||
|
||||
// asn1_type_set0_string sets |a|'s value to the object represented by |str| and
|
||||
// takes ownership of |str|.
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str);
|
||||
|
||||
// asn1_type_cleanup releases memory associated with |a|'s value, without
|
||||
// freeing |a| itself.
|
||||
void asn1_type_cleanup(ASN1_TYPE *a);
|
||||
|
||||
// asn1_is_printable returns one if |value| is a valid Unicode codepoint for an
|
||||
// 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);
|
||||
|
||||
// asn1_marshal_bit_string marshals |in| as a DER-encoded, ASN.1 BIT STRING and
|
||||
// writes the result to |out|. It returns one on success and zero on error. If
|
||||
// |tag| is non-zero, the tag is replaced with |tag|.
|
||||
int asn1_marshal_bit_string(CBB *out, const ASN1_BIT_STRING *in,
|
||||
CBS_ASN1_TAG tag);
|
||||
|
||||
// asn1_marshal_integer marshals |in| as a DER-encoded, ASN.1 INTEGER and writes
|
||||
// the result to |out|. It returns one on success and zero on error. If |tag| is
|
||||
// non-zero, the tag is replaced with |tag|.
|
||||
int asn1_marshal_integer(CBB *out, const ASN1_INTEGER *in, CBS_ASN1_TAG tag);
|
||||
|
||||
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);
|
||||
|
||||
typedef ASN1_VALUE *ASN1_new_func(void);
|
||||
typedef void ASN1_free_func(ASN1_VALUE *a);
|
||||
typedef ASN1_VALUE *ASN1_d2i_func(ASN1_VALUE **a, const unsigned char **in,
|
||||
long length);
|
||||
typedef int ASN1_i2d_func(ASN1_VALUE *a, unsigned char **in);
|
||||
|
||||
typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int opt, ASN1_TLC *ctx);
|
||||
|
||||
typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it);
|
||||
typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
typedef struct ASN1_EXTERN_FUNCS_st {
|
||||
ASN1_ex_new_func *asn1_ex_new;
|
||||
ASN1_ex_free_func *asn1_ex_free;
|
||||
ASN1_ex_d2i *asn1_ex_d2i;
|
||||
ASN1_ex_i2d *asn1_ex_i2d;
|
||||
} ASN1_EXTERN_FUNCS;
|
||||
|
||||
// ASN1_ANY_AS_STRING is an |ASN1_ITEM| with ASN.1 type ANY and C type
|
||||
// |ASN1_STRING*|. Types which are not represented with |ASN1_STRING|, such as
|
||||
// |ASN1_OBJECT|, are represented with type |V_ASN1_OTHER|.
|
||||
DECLARE_ASN1_ITEM(ASN1_ANY_AS_STRING)
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H
|
||||
@@ -1,241 +0,0 @@
|
||||
// Copyright 2022 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Time conversion to/from POSIX time_t and struct tm, with no support
|
||||
// for time zones other than UTC
|
||||
|
||||
#include <openssl/posix_time.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#define SECS_PER_HOUR (60 * 60)
|
||||
#define SECS_PER_DAY (INT64_C(24) * SECS_PER_HOUR)
|
||||
|
||||
|
||||
// Is a year/month/day combination valid, in the range from year 0000
|
||||
// to 9999?
|
||||
static int is_valid_date(int64_t year, int64_t month, int64_t day) {
|
||||
if (day < 1 || month < 1 || year < 0 || year > 9999) {
|
||||
return 0;
|
||||
}
|
||||
switch (month) {
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
return day > 0 && day <= 31;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
return day > 0 && day <= 30;
|
||||
case 2:
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
|
||||
return day > 0 && day <= 29;
|
||||
} else {
|
||||
return day > 0 && day <= 28;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Is a time valid? Leap seconds of 60 are not considered valid, as
|
||||
// the POSIX time in seconds does not include them.
|
||||
static int is_valid_time(int64_t hours, int64_t minutes, int64_t seconds) {
|
||||
if (hours < 0 || minutes < 0 || seconds < 0 || hours > 23 || minutes > 59 ||
|
||||
seconds > 59) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 0000-01-01 00:00:00 UTC
|
||||
#define MIN_POSIX_TIME INT64_C(-62167219200)
|
||||
// 9999-12-31 23:59:59 UTC
|
||||
#define MAX_POSIX_TIME INT64_C(253402300799)
|
||||
|
||||
// Is an int64 time within our expected range?
|
||||
static int is_valid_posix_time(int64_t time) {
|
||||
return MIN_POSIX_TIME <= time && time <= MAX_POSIX_TIME;
|
||||
}
|
||||
|
||||
// Inspired by algorithms presented in
|
||||
// https://howardhinnant.github.io/date_algorithms.html
|
||||
// (Public Domain)
|
||||
static int posix_time_from_utc(int64_t year, int64_t month, int64_t day,
|
||||
int64_t hours, int64_t minutes, int64_t seconds,
|
||||
int64_t *out_time) {
|
||||
if (!is_valid_date(year, month, day) ||
|
||||
!is_valid_time(hours, minutes, seconds)) {
|
||||
return 0;
|
||||
}
|
||||
if (month <= 2) {
|
||||
year--; // Start years on Mar 1, so leap days always finish a year.
|
||||
}
|
||||
// At this point year will be in the range -1 and 9999.
|
||||
assert(-1 <= year && year <= 9999);
|
||||
int64_t era = (year >= 0 ? year : year - 399) / 400;
|
||||
int64_t year_of_era = year - era * 400;
|
||||
int64_t day_of_year =
|
||||
(153 * (month > 2 ? month - 3 : month + 9) + 2) / 5 + day - 1;
|
||||
int64_t day_of_era =
|
||||
year_of_era * 365 + year_of_era / 4 - year_of_era / 100 + day_of_year;
|
||||
int64_t posix_days = era * 146097 + day_of_era - 719468;
|
||||
*out_time = posix_days * SECS_PER_DAY + hours * SECS_PER_HOUR + minutes * 60 +
|
||||
seconds;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Inspired by algorithms presented in
|
||||
// https://howardhinnant.github.io/date_algorithms.html
|
||||
// (Public Domain)
|
||||
static int utc_from_posix_time(int64_t time, int *out_year, int *out_month,
|
||||
int *out_day, int *out_hours, int *out_minutes,
|
||||
int *out_seconds) {
|
||||
if (!is_valid_posix_time(time)) {
|
||||
return 0;
|
||||
}
|
||||
int64_t days = time / SECS_PER_DAY;
|
||||
int64_t leftover_seconds = time % SECS_PER_DAY;
|
||||
if (leftover_seconds < 0) {
|
||||
days--;
|
||||
leftover_seconds += SECS_PER_DAY;
|
||||
}
|
||||
days += 719468; // Shift to starting epoch of Mar 1 0000.
|
||||
// At this point, days will be in the range -61 and 3652364.
|
||||
assert(-61 <= days && days <= 3652364);
|
||||
int64_t era = (days > 0 ? days : days - 146096) / 146097;
|
||||
int64_t day_of_era = days - era * 146097;
|
||||
int64_t year_of_era = (day_of_era - day_of_era / 1460 + day_of_era / 36524 -
|
||||
day_of_era / 146096) /
|
||||
365;
|
||||
*out_year = (int)(year_of_era + era * 400); // Year starting on Mar 1.
|
||||
int64_t day_of_year =
|
||||
day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100);
|
||||
int64_t month_of_year = (5 * day_of_year + 2) / 153;
|
||||
*out_month =
|
||||
(int)(month_of_year < 10 ? month_of_year + 3 : month_of_year - 9);
|
||||
if (*out_month <= 2) {
|
||||
(*out_year)++; // Adjust year back to Jan 1 start of year.
|
||||
}
|
||||
*out_day = (int)(day_of_year - (153 * month_of_year + 2) / 5 + 1);
|
||||
*out_hours = (int)(leftover_seconds / SECS_PER_HOUR);
|
||||
leftover_seconds %= SECS_PER_HOUR;
|
||||
*out_minutes = (int)(leftover_seconds / 60);
|
||||
*out_seconds = (int)(leftover_seconds % 60);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) {
|
||||
return posix_time_from_utc(tm->tm_year + INT64_C(1900),
|
||||
tm->tm_mon + INT64_C(1), tm->tm_mday, tm->tm_hour,
|
||||
tm->tm_min, tm->tm_sec, out);
|
||||
}
|
||||
|
||||
int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) {
|
||||
struct tm tmp_tm = {};
|
||||
if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon,
|
||||
&tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min,
|
||||
&tmp_tm.tm_sec)) {
|
||||
return 0;
|
||||
}
|
||||
tmp_tm.tm_year -= 1900;
|
||||
tmp_tm.tm_mon -= 1;
|
||||
*out_tm = tmp_tm;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OPENSSL_timegm(const struct tm *tm, time_t *out) {
|
||||
static_assert(
|
||||
sizeof(time_t) == sizeof(int32_t) || sizeof(time_t) == sizeof(int64_t),
|
||||
"time_t is broken");
|
||||
int64_t posix_time;
|
||||
if (!OPENSSL_tm_to_posix(tm, &posix_time)) {
|
||||
return 0;
|
||||
}
|
||||
if (sizeof(time_t) == sizeof(int32_t) &&
|
||||
(posix_time > INT32_MAX || posix_time < INT32_MIN)) {
|
||||
return 0;
|
||||
}
|
||||
*out = (time_t)posix_time;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm) {
|
||||
static_assert(
|
||||
sizeof(time_t) == sizeof(int32_t) || sizeof(time_t) == sizeof(int64_t),
|
||||
"time_t is broken");
|
||||
int64_t posix_time = *time;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, out_tm)) {
|
||||
return NULL;
|
||||
}
|
||||
return out_tm;
|
||||
}
|
||||
|
||||
int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, int64_t offset_sec) {
|
||||
int64_t posix_time;
|
||||
if (!OPENSSL_tm_to_posix(tm, &posix_time)) {
|
||||
return 0;
|
||||
}
|
||||
static_assert(INT_MAX <= INT64_MAX / SECS_PER_DAY,
|
||||
"day offset in seconds cannot overflow");
|
||||
static_assert(MAX_POSIX_TIME <= INT64_MAX - INT_MAX * SECS_PER_DAY,
|
||||
"addition cannot overflow");
|
||||
static_assert(MIN_POSIX_TIME >= INT64_MIN - INT_MIN * SECS_PER_DAY,
|
||||
"addition cannot underflow");
|
||||
posix_time += offset_day * SECS_PER_DAY;
|
||||
if (posix_time > 0 && offset_sec > INT64_MAX - posix_time) {
|
||||
return 0;
|
||||
}
|
||||
if (posix_time < 0 && offset_sec < INT64_MIN - posix_time) {
|
||||
return 0;
|
||||
}
|
||||
posix_time += offset_sec;
|
||||
|
||||
if (!OPENSSL_posix_to_tm(posix_time, tm)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from,
|
||||
const struct tm *to) {
|
||||
int64_t time_to, time_from;
|
||||
if (!OPENSSL_tm_to_posix(to, &time_to) ||
|
||||
!OPENSSL_tm_to_posix(from, &time_from)) {
|
||||
return 0;
|
||||
}
|
||||
// Times are in range, so these calculations can not overflow.
|
||||
static_assert(SECS_PER_DAY <= INT_MAX, "seconds per day does not fit in int");
|
||||
static_assert((MAX_POSIX_TIME - MIN_POSIX_TIME) / SECS_PER_DAY <= INT_MAX,
|
||||
"range of valid POSIX times, in days, does not fit in int");
|
||||
int64_t timediff = time_to - time_from;
|
||||
int64_t daydiff = timediff / SECS_PER_DAY;
|
||||
timediff %= SECS_PER_DAY;
|
||||
*out_secs = (int)timediff;
|
||||
*out_days = (int)daydiff;
|
||||
return 1;
|
||||
}
|
||||
@@ -1,963 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/pool.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
// Constructed types with a recursive definition (such as can be found in PKCS7)
|
||||
// could eventually exceed the stack given malicious input with excessive
|
||||
// recursion. Therefore we limit the stack depth. This is the maximum number of
|
||||
// recursive invocations of asn1_item_embed_d2i().
|
||||
#define ASN1_MAX_CONSTRUCTED_NEST 30
|
||||
|
||||
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
char *cst, const unsigned char **in, long len,
|
||||
int exptag, int expclass, char opt);
|
||||
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth);
|
||||
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
long len, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth);
|
||||
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
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, int tag,
|
||||
int aclass, char opt);
|
||||
static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_ITEM *it, int tag, int aclass,
|
||||
char opt, CRYPTO_BUFFER *buf, int depth);
|
||||
|
||||
unsigned long ASN1_tag2bit(int tag) {
|
||||
switch (tag) {
|
||||
case V_ASN1_BIT_STRING:
|
||||
return B_ASN1_BIT_STRING;
|
||||
case V_ASN1_OCTET_STRING:
|
||||
return B_ASN1_OCTET_STRING;
|
||||
case V_ASN1_UTF8STRING:
|
||||
return B_ASN1_UTF8STRING;
|
||||
case V_ASN1_SEQUENCE:
|
||||
return B_ASN1_SEQUENCE;
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
return B_ASN1_NUMERICSTRING;
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
return B_ASN1_PRINTABLESTRING;
|
||||
case V_ASN1_T61STRING:
|
||||
return B_ASN1_T61STRING;
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
return B_ASN1_VIDEOTEXSTRING;
|
||||
case V_ASN1_IA5STRING:
|
||||
return B_ASN1_IA5STRING;
|
||||
case V_ASN1_UTCTIME:
|
||||
return B_ASN1_UTCTIME;
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
return B_ASN1_GENERALIZEDTIME;
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
return B_ASN1_GRAPHICSTRING;
|
||||
case V_ASN1_ISO64STRING:
|
||||
return B_ASN1_ISO64STRING;
|
||||
case V_ASN1_GENERALSTRING:
|
||||
return B_ASN1_GENERALSTRING;
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
return B_ASN1_UNIVERSALSTRING;
|
||||
case V_ASN1_BMPSTRING:
|
||||
return B_ASN1_BMPSTRING;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int is_supported_universal_type(int tag, int aclass) {
|
||||
if (aclass != V_ASN1_UNIVERSAL) {
|
||||
return 0;
|
||||
}
|
||||
return tag == V_ASN1_OBJECT || tag == V_ASN1_NULL || tag == V_ASN1_BOOLEAN ||
|
||||
tag == V_ASN1_BIT_STRING || tag == V_ASN1_INTEGER ||
|
||||
tag == V_ASN1_ENUMERATED || tag == V_ASN1_OCTET_STRING ||
|
||||
tag == V_ASN1_NUMERICSTRING || tag == V_ASN1_PRINTABLESTRING ||
|
||||
tag == V_ASN1_T61STRING || tag == V_ASN1_VIDEOTEXSTRING ||
|
||||
tag == V_ASN1_IA5STRING || tag == V_ASN1_UTCTIME ||
|
||||
tag == V_ASN1_GENERALIZEDTIME || tag == V_ASN1_GRAPHICSTRING ||
|
||||
tag == V_ASN1_VISIBLESTRING || tag == V_ASN1_GENERALSTRING ||
|
||||
tag == V_ASN1_UNIVERSALSTRING || tag == V_ASN1_BMPSTRING ||
|
||||
tag == V_ASN1_UTF8STRING || tag == V_ASN1_SET ||
|
||||
tag == V_ASN1_SEQUENCE;
|
||||
}
|
||||
|
||||
// Macro to initialize and invalidate the cache
|
||||
|
||||
// Decode an ASN1 item, this currently behaves just like a standard 'd2i'
|
||||
// function. 'in' points to a buffer to read the data from, in future we
|
||||
// will have more advanced versions that can input data a piece at a time and
|
||||
// this will simply be a special case.
|
||||
|
||||
ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it) {
|
||||
ASN1_VALUE *ret = NULL;
|
||||
if (asn1_item_ex_d2i(&ret, in, len, it, /*tag=*/-1, /*aclass=*/0, /*opt=*/0,
|
||||
/*buf=*/NULL, /*depth=*/0) <= 0) {
|
||||
// Clean up, in case the caller left a partial object.
|
||||
//
|
||||
// TODO(davidben): I don't think it can leave one, but the codepaths below
|
||||
// are a bit inconsistent. Revisit this when rewriting this function.
|
||||
ASN1_item_ex_free(&ret, it);
|
||||
}
|
||||
|
||||
// If the caller supplied an output pointer, free the old one and replace it
|
||||
// with |ret|. This differs from OpenSSL slightly in that we don't support
|
||||
// object reuse. We run this on both success and failure. On failure, even
|
||||
// with object reuse, OpenSSL destroys the previous object.
|
||||
if (pval != NULL) {
|
||||
ASN1_item_ex_free(pval, it);
|
||||
*pval = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Decode an item, taking care of IMPLICIT tagging, if any. If 'opt' set and
|
||||
// tag mismatch return -1 to handle OPTIONAL
|
||||
//
|
||||
// TODO(davidben): Historically, all functions in this file had to account for
|
||||
// |*pval| containing an arbitrary existing value. This is no longer the case
|
||||
// because |ASN1_item_d2i| now always starts from NULL. As part of rewriting
|
||||
// this function, take the simplified assumptions into account. Though we must
|
||||
// still account for the internal calls to |ASN1_item_ex_new|.
|
||||
|
||||
static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_ITEM *it, int tag, int aclass,
|
||||
char opt, CRYPTO_BUFFER *buf, int depth) {
|
||||
const ASN1_TEMPLATE *tt, *errtt = NULL;
|
||||
const unsigned char *p = NULL, *q;
|
||||
unsigned char oclass;
|
||||
char cst, isopt;
|
||||
int i;
|
||||
int otag;
|
||||
int ret = 0;
|
||||
ASN1_VALUE **pchptr;
|
||||
if (!pval) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf != NULL) {
|
||||
assert(CRYPTO_BUFFER_data(buf) <= *in &&
|
||||
*in + len <= CRYPTO_BUFFER_data(buf) + CRYPTO_BUFFER_len(buf));
|
||||
}
|
||||
|
||||
// Bound |len| to comfortably fit in an int. Lengths in this module often
|
||||
// switch between int and long without overflow checks.
|
||||
if (len > INT_MAX / 2) {
|
||||
len = INT_MAX / 2;
|
||||
}
|
||||
|
||||
if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_TOO_DEEP);
|
||||
goto err;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
// tagging or OPTIONAL is currently illegal on an item template
|
||||
// because the flags can't get passed down. In practice this
|
||||
// isn't a problem: we include the relevant flags from the item
|
||||
// template in the template itself.
|
||||
if ((tag != -1) || opt) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
return asn1_template_ex_d2i(pval, in, len, it->templates, opt, buf,
|
||||
depth);
|
||||
}
|
||||
return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
// It never makes sense for multi-strings to have implicit tagging, so
|
||||
// if tag != -1, then this looks like an error in the template.
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
p = *in;
|
||||
// Just read in tag and class
|
||||
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, &p, len, -1, 0, 1);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Must be UNIVERSAL class
|
||||
if (oclass != V_ASN1_UNIVERSAL) {
|
||||
// If OPTIONAL, assume this is OK
|
||||
if (opt) {
|
||||
return -1;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
|
||||
goto err;
|
||||
}
|
||||
// Check tag matches bit map
|
||||
if (!(ASN1_tag2bit(otag) & it->utype)) {
|
||||
// If OPTIONAL, assume this is OK
|
||||
if (opt) {
|
||||
return -1;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_WRONG_TAG);
|
||||
goto err;
|
||||
}
|
||||
return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0);
|
||||
|
||||
case ASN1_ITYPE_EXTERN: {
|
||||
// We don't support implicit tagging with external types.
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
const ASN1_EXTERN_FUNCS *ef =
|
||||
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
return ef->asn1_ex_d2i(pval, in, len, it, opt, NULL);
|
||||
}
|
||||
|
||||
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.
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_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;
|
||||
}
|
||||
|
||||
if (*pval) {
|
||||
// Free up and zero CHOICE value if initialised
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
tt = it->templates + i;
|
||||
pchptr = asn1_get_field_ptr(pval, tt);
|
||||
ASN1_template_free(pchptr, tt);
|
||||
asn1_set_choice_selector(pval, -1, it);
|
||||
}
|
||||
} else if (!ASN1_item_ex_new(pval, it)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
// CHOICE type, try each possibility in turn
|
||||
p = *in;
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
||||
pchptr = asn1_get_field_ptr(pval, tt);
|
||||
// We mark field as OPTIONAL so its absence can be recognised.
|
||||
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, buf, depth);
|
||||
// If field not present, try the next one
|
||||
if (ret == -1) {
|
||||
continue;
|
||||
}
|
||||
// If positive return, read OK, break loop
|
||||
if (ret > 0) {
|
||||
break;
|
||||
}
|
||||
// Otherwise must be an ASN1 parsing error
|
||||
errtt = tt;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Did we fall off the end without reading anything?
|
||||
if (i == it->tcount) {
|
||||
// If OPTIONAL, this is OK
|
||||
if (opt) {
|
||||
// Free and zero it
|
||||
ASN1_item_ex_free(pval, it);
|
||||
return -1;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
asn1_set_choice_selector(pval, i, it);
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
|
||||
goto auxerr;
|
||||
}
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
p = *in;
|
||||
|
||||
// If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL
|
||||
if (tag == -1) {
|
||||
tag = V_ASN1_SEQUENCE;
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
// Get SEQUENCE length and update len, p
|
||||
ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, len, tag, aclass, opt);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (!cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!*pval && !ASN1_item_ex_new(pval, it)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_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;
|
||||
}
|
||||
|
||||
// Free up and zero any ADB found
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
||||
if (tt->flags & ASN1_TFLG_ADB_MASK) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 0);
|
||||
if (seqtt == NULL) {
|
||||
continue;
|
||||
}
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
}
|
||||
}
|
||||
|
||||
// Get each field entry
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (seqtt == NULL) {
|
||||
goto err;
|
||||
}
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
// Have we ran out of data?
|
||||
if (!len) {
|
||||
break;
|
||||
}
|
||||
q = p;
|
||||
// This determines the OPTIONAL flag value. The field cannot be
|
||||
// omitted if it is the last of a SEQUENCE and there is still
|
||||
// data to be read. This isn't strictly necessary but it
|
||||
// increases efficiency in some cases.
|
||||
if (i == (it->tcount - 1)) {
|
||||
isopt = 0;
|
||||
} else {
|
||||
isopt = (seqtt->flags & ASN1_TFLG_OPTIONAL) != 0;
|
||||
}
|
||||
// attempt to read in field, allowing each to be OPTIONAL
|
||||
|
||||
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, buf, depth);
|
||||
if (!ret) {
|
||||
errtt = seqtt;
|
||||
goto err;
|
||||
} else if (ret == -1) {
|
||||
// OPTIONAL component absent. Free and zero the field.
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
continue;
|
||||
}
|
||||
// Update length
|
||||
len -= p - q;
|
||||
}
|
||||
|
||||
// Check all data read
|
||||
if (len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// If we get here we've got no more data in the SEQUENCE, however we
|
||||
// may not have read all fields so check all remaining are OPTIONAL
|
||||
// and clear any that are.
|
||||
for (; i < it->tcount; tt++, i++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (seqtt == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
|
||||
ASN1_VALUE **pseqval;
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
} else {
|
||||
errtt = seqtt;
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_FIELD_MISSING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
// Save encoding
|
||||
if (!asn1_enc_save(pval, *in, p - *in, it, buf)) {
|
||||
goto auxerr;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
|
||||
goto auxerr;
|
||||
}
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
auxerr:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
|
||||
err:
|
||||
ASN1_item_ex_free(pval, it);
|
||||
if (errtt) {
|
||||
ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
|
||||
} else {
|
||||
ERR_add_error_data(2, "Type=", it->sname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt,
|
||||
CRYPTO_BUFFER *buf) {
|
||||
return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, buf,
|
||||
/*depth=*/0);
|
||||
}
|
||||
|
||||
// Templates are handled with two separate functions. One handles any
|
||||
// EXPLICIT tag and the other handles the rest.
|
||||
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
long inlen, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth) {
|
||||
int aclass;
|
||||
int ret;
|
||||
long len;
|
||||
const unsigned char *p, *q;
|
||||
if (!val) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t flags = tt->flags;
|
||||
aclass = flags & ASN1_TFLG_TAG_CLASS;
|
||||
|
||||
p = *in;
|
||||
|
||||
// Check if EXPLICIT tag expected
|
||||
if (flags & ASN1_TFLG_EXPTAG) {
|
||||
char cst;
|
||||
// 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, &cst, &p, inlen, tt->tag, aclass,
|
||||
opt);
|
||||
q = p;
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (!cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
|
||||
return 0;
|
||||
}
|
||||
// We've found the field so it can't be OPTIONAL now
|
||||
ret = asn1_template_noexp_d2i(val, &p, len, tt, /*opt=*/0, buf, depth);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
}
|
||||
// We read the field in OK so update length
|
||||
len -= p - q;
|
||||
// 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, buf, depth);
|
||||
}
|
||||
|
||||
*in = p;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
ASN1_template_free(val, tt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
long len, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth) {
|
||||
int aclass;
|
||||
int ret;
|
||||
const unsigned char *p;
|
||||
if (!val) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t flags = tt->flags;
|
||||
aclass = flags & ASN1_TFLG_TAG_CLASS;
|
||||
|
||||
p = *in;
|
||||
|
||||
if (flags & ASN1_TFLG_SK_MASK) {
|
||||
// SET OF, SEQUENCE OF
|
||||
int sktag, skaclass;
|
||||
// First work out expected inner tag value
|
||||
if (flags & ASN1_TFLG_IMPTAG) {
|
||||
sktag = tt->tag;
|
||||
skaclass = aclass;
|
||||
} else {
|
||||
skaclass = V_ASN1_UNIVERSAL;
|
||||
if (flags & ASN1_TFLG_SET_OF) {
|
||||
sktag = V_ASN1_SET;
|
||||
} else {
|
||||
sktag = V_ASN1_SEQUENCE;
|
||||
}
|
||||
}
|
||||
// Get the tag
|
||||
ret =
|
||||
asn1_check_tlen(&len, NULL, NULL, NULL, &p, len, sktag, skaclass, opt);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (!*val) {
|
||||
*val = (ASN1_VALUE *)sk_ASN1_VALUE_new_null();
|
||||
} else {
|
||||
// We've got a valid STACK: free up any items present
|
||||
STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val;
|
||||
ASN1_VALUE *vtmp;
|
||||
while (sk_ASN1_VALUE_num(sktmp) > 0) {
|
||||
vtmp = sk_ASN1_VALUE_pop(sktmp);
|
||||
ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
}
|
||||
|
||||
if (!*val) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Read as many items as we can
|
||||
while (len > 0) {
|
||||
ASN1_VALUE *skfield;
|
||||
const unsigned char *q = p;
|
||||
skfield = NULL;
|
||||
if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item),
|
||||
/*tag=*/-1, /*aclass=*/0, /*opt=*/0, buf, depth)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
len -= p - q;
|
||||
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
|
||||
ASN1_item_ex_free(&skfield, ASN1_ITEM_ptr(tt->item));
|
||||
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,
|
||||
aclass, opt, buf, depth);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// Nothing special
|
||||
ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), /*tag=*/-1,
|
||||
/*aclass=*/0, opt, buf, depth);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*in = p;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
ASN1_template_free(val, tt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long inlen, const ASN1_ITEM *it, int tag,
|
||||
int aclass, char opt) {
|
||||
int ret = 0, utype;
|
||||
long plen;
|
||||
char cst;
|
||||
const unsigned char *p;
|
||||
const unsigned char *cont = NULL;
|
||||
long len;
|
||||
if (!pval) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
|
||||
return 0; // Should never happen
|
||||
}
|
||||
|
||||
assert(it->itype == ASN1_ITYPE_PRIMITIVE || it->itype == ASN1_ITYPE_MSTRING);
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
utype = tag;
|
||||
tag = -1;
|
||||
} else {
|
||||
utype = it->utype;
|
||||
}
|
||||
|
||||
if (utype == V_ASN1_ANY || utype == V_ASN1_ANY_AS_STRING) {
|
||||
// If type is ANY need to figure out type from tag
|
||||
unsigned char oclass;
|
||||
if (tag >= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
|
||||
return 0;
|
||||
}
|
||||
if (opt) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
|
||||
return 0;
|
||||
}
|
||||
const int is_string = utype == V_ASN1_ANY_AS_STRING;
|
||||
p = *in;
|
||||
ret = asn1_check_tlen(&plen, &utype, &oclass, &cst, &p, inlen, -1, 0, 0);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!is_supported_universal_type(utype, oclass)) {
|
||||
utype = V_ASN1_OTHER;
|
||||
}
|
||||
// These three types are not represented as |ASN1_STRING|, so they must be
|
||||
// parsed separately and then treated as an opaque |V_ASN1_OTHER|.
|
||||
if (is_string && (utype == V_ASN1_OBJECT || utype == V_ASN1_NULL ||
|
||||
utype == V_ASN1_BOOLEAN)) {
|
||||
if (cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, p, plen);
|
||||
if (utype == V_ASN1_OBJECT && !CBS_is_valid_asn1_oid(&cbs)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return 0;
|
||||
}
|
||||
if (utype == V_ASN1_NULL && CBS_len(&cbs) != 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
if (utype == V_ASN1_BOOLEAN) {
|
||||
if (CBS_len(&cbs) != 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
uint8_t v = CBS_data(&cbs)[0];
|
||||
if (v != 0 && v != 0xff) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
utype = V_ASN1_OTHER;
|
||||
}
|
||||
}
|
||||
if (tag == -1) {
|
||||
tag = utype;
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
p = *in;
|
||||
// Check header
|
||||
ret = asn1_check_tlen(&plen, NULL, NULL, &cst, &p, inlen, tag, aclass, opt);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
ret = 0;
|
||||
// SEQUENCE, SET and "OTHER" are left in encoded form
|
||||
if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
|
||||
(utype == V_ASN1_OTHER)) {
|
||||
// SEQUENCE and SET must be constructed
|
||||
if (utype != V_ASN1_OTHER && !cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cont = *in;
|
||||
len = p - cont + plen;
|
||||
p += plen;
|
||||
} else if (cst) {
|
||||
// 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;
|
||||
p += plen;
|
||||
}
|
||||
|
||||
// We now have content length and type: translate into a structure
|
||||
if (!asn1_ex_c2i(pval, cont, len, utype, it)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
*in = p;
|
||||
ret = 1;
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Translate ASN1 content octets into a structure
|
||||
|
||||
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
int utype, const ASN1_ITEM *it) {
|
||||
ASN1_VALUE **opval = NULL;
|
||||
ASN1_STRING *stmp;
|
||||
ASN1_TYPE *typ = NULL;
|
||||
int ret = 0;
|
||||
ASN1_INTEGER **tint;
|
||||
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
// If ANY type clear type and set pointer to internal value
|
||||
if (it->utype == V_ASN1_ANY) {
|
||||
if (!*pval) {
|
||||
typ = ASN1_TYPE_new();
|
||||
if (typ == NULL) {
|
||||
goto err;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)typ;
|
||||
} else {
|
||||
typ = (ASN1_TYPE *)*pval;
|
||||
}
|
||||
|
||||
if (utype != typ->type) {
|
||||
ASN1_TYPE_set(typ, utype, NULL);
|
||||
}
|
||||
opval = pval;
|
||||
pval = &typ->value.asn1_value;
|
||||
}
|
||||
|
||||
// If implementing a type that is not represented in |ASN1_STRING|, the
|
||||
// |V_ASN1_ANY_AS_STRING| logic must be modified to redirect it to
|
||||
// |V_ASN1_OTHER|.
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
if (len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)1;
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (len != 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
||||
goto err;
|
||||
} else {
|
||||
ASN1_BOOLEAN *tbool;
|
||||
tbool = (ASN1_BOOLEAN *)pval;
|
||||
*tbool = *cont;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_BIT_STRING:
|
||||
if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
tint = (ASN1_INTEGER **)pval;
|
||||
if (!c2i_ASN1_INTEGER(tint, &cont, len)) {
|
||||
goto err;
|
||||
}
|
||||
// Fixup type to match the expected form
|
||||
(*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
|
||||
break;
|
||||
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_OTHER:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_SEQUENCE: {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, cont, (size_t)len);
|
||||
if (utype == V_ASN1_BMPSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_ucs2_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (utype == V_ASN1_UNIVERSALSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_utf32_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (utype == V_ASN1_UTF8STRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_utf8(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UTF8STRING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (utype == V_ASN1_UTCTIME) {
|
||||
if (!CBS_parse_utc_time(&cbs, NULL, /*allow_timezone_offset=*/1)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (utype == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!CBS_parse_generalized_time(&cbs, NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
// TODO(https://crbug.com/boringssl/427): Check other string types.
|
||||
|
||||
// All based on ASN1_STRING and handled the same
|
||||
if (!*pval) {
|
||||
stmp = ASN1_STRING_type_new(utype);
|
||||
if (!stmp) {
|
||||
goto err;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)stmp;
|
||||
} else {
|
||||
stmp = (ASN1_STRING *)*pval;
|
||||
stmp->type = utype;
|
||||
}
|
||||
if (!ASN1_STRING_set(stmp, cont, len)) {
|
||||
ASN1_STRING_free(stmp);
|
||||
*pval = NULL;
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
// If ASN1_ANY and NULL type fix up value
|
||||
if (typ && (utype == V_ASN1_NULL)) {
|
||||
typ->value.ptr = NULL;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
if (!ret) {
|
||||
ASN1_TYPE_free(typ);
|
||||
if (opval) {
|
||||
*opval = NULL;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Check an ASN1 tag and length: a bit like ASN1_get_object but it
|
||||
// checks the expected tag.
|
||||
|
||||
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
char *cst, const unsigned char **in, long len,
|
||||
int exptag, int expclass, char opt) {
|
||||
int i;
|
||||
int ptag, pclass;
|
||||
long plen;
|
||||
const unsigned char *p;
|
||||
p = *in;
|
||||
|
||||
i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
|
||||
if (i & 0x80) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
|
||||
return 0;
|
||||
}
|
||||
if (exptag >= 0) {
|
||||
if ((exptag != ptag) || (expclass != pclass)) {
|
||||
// If type is OPTIONAL, not an error: indicate missing type.
|
||||
if (opt) {
|
||||
return -1;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (cst) {
|
||||
*cst = i & V_ASN1_CONSTRUCTED;
|
||||
}
|
||||
|
||||
if (olen) {
|
||||
*olen = plen;
|
||||
}
|
||||
|
||||
if (oclass) {
|
||||
*oclass = pclass;
|
||||
}
|
||||
|
||||
if (otag) {
|
||||
*otag = ptag;
|
||||
}
|
||||
|
||||
*in = p;
|
||||
return 1;
|
||||
}
|
||||
@@ -1,661 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#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,
|
||||
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);
|
||||
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt, int tag, int aclass,
|
||||
int optional);
|
||||
|
||||
// Top level i2d equivalents
|
||||
|
||||
int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) {
|
||||
if (out && !*out) {
|
||||
unsigned char *p, *buf;
|
||||
int len = ASN1_item_ex_i2d(&val, NULL, it, /*tag=*/-1, /*aclass=*/0);
|
||||
if (len <= 0) {
|
||||
return len;
|
||||
}
|
||||
buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
|
||||
if (!buf) {
|
||||
return -1;
|
||||
}
|
||||
p = buf;
|
||||
int len2 = ASN1_item_ex_i2d(&val, &p, it, /*tag=*/-1, /*aclass=*/0);
|
||||
if (len2 <= 0) {
|
||||
OPENSSL_free(buf);
|
||||
return len2;
|
||||
}
|
||||
assert(len == len2);
|
||||
*out = buf;
|
||||
return len;
|
||||
}
|
||||
|
||||
return ASN1_item_ex_i2d(&val, out, it, /*tag=*/-1, /*aclass=*/0);
|
||||
}
|
||||
|
||||
// Encode an item, taking care of IMPLICIT tagging (if any). This function
|
||||
// performs the normal item handling: it can be used in external types.
|
||||
|
||||
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;
|
||||
|
||||
// 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);
|
||||
|
||||
// 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) {
|
||||
// This is an |ASN1_ITEM_TEMPLATE|.
|
||||
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,
|
||||
optional);
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass, optional);
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
// It never makes sense for multi-strings to have implicit tagging, so
|
||||
// if tag != -1, then this looks like an error in the template.
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, -1, 0, optional);
|
||||
|
||||
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.
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if (i < 0 || i >= it->tcount) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
|
||||
return -1;
|
||||
}
|
||||
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, /*optional=*/0);
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_EXTERN: {
|
||||
// We don't support implicit tagging with external types.
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
const ASN1_EXTERN_FUNCS *ef =
|
||||
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
int ret = ef->asn1_ex_i2d(pval, out, it);
|
||||
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: {
|
||||
i = asn1_enc_restore(&seqcontlen, out, pval, it);
|
||||
// An error occurred
|
||||
if (i < 0) {
|
||||
return -1;
|
||||
}
|
||||
// We have a valid cached encoding...
|
||||
if (i > 0) {
|
||||
return seqcontlen;
|
||||
}
|
||||
// Otherwise carry on
|
||||
seqcontlen = 0;
|
||||
// If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL
|
||||
if (tag == -1) {
|
||||
tag = V_ASN1_SEQUENCE;
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
// First work out sequence content length
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
int tmplen;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (!seqtt) {
|
||||
return -1;
|
||||
}
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
tmplen =
|
||||
asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, 0, /*optional=*/0);
|
||||
if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen)) {
|
||||
return -1;
|
||||
}
|
||||
seqcontlen += tmplen;
|
||||
}
|
||||
|
||||
seqlen = ASN1_object_size(/*constructed=*/1, seqcontlen, tag);
|
||||
if (!out || seqlen == -1) {
|
||||
return seqlen;
|
||||
}
|
||||
// Output SEQUENCE header
|
||||
ASN1_put_object(out, /*constructed=*/1, seqcontlen, tag, aclass);
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (!seqtt) {
|
||||
return -1;
|
||||
}
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
if (asn1_template_ex_i2d(pseqval, out, seqtt, -1, 0, /*optional=*/0) <
|
||||
0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return seqlen;
|
||||
}
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt, int tag, int iclass,
|
||||
int optional) {
|
||||
int i, ret, ttag, tclass;
|
||||
size_t j;
|
||||
uint32_t 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.
|
||||
if (flags & ASN1_TFLG_TAG_MASK) {
|
||||
// Error if argument and template tagging
|
||||
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;
|
||||
} else if (tag != -1) {
|
||||
// No template tagging, get from arguments
|
||||
ttag = tag;
|
||||
tclass = iclass & ASN1_TFLG_TAG_CLASS;
|
||||
} else {
|
||||
ttag = -1;
|
||||
tclass = 0;
|
||||
}
|
||||
|
||||
// The template may itself by marked as optional, or this may be the template
|
||||
// of an |ASN1_ITEM_TEMPLATE| type which was contained inside an outer
|
||||
// optional template. (They cannot both be true because the
|
||||
// |ASN1_ITEM_TEMPLATE| codepath rejects optional templates.)
|
||||
assert(!optional || (flags & ASN1_TFLG_OPTIONAL) == 0);
|
||||
optional = optional || (flags & ASN1_TFLG_OPTIONAL) != 0;
|
||||
|
||||
// At this point 'ttag' contains the outer tag to use, and 'tclass' is the
|
||||
// class.
|
||||
|
||||
if (flags & ASN1_TFLG_SK_MASK) {
|
||||
// SET OF, SEQUENCE OF
|
||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||
int isset, sktag, skaclass;
|
||||
int skcontlen, sklen;
|
||||
ASN1_VALUE *skitem;
|
||||
|
||||
if (!*pval) {
|
||||
if (optional) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & ASN1_TFLG_SET_OF) {
|
||||
isset = 1;
|
||||
// Historically, types with both bits set were mutated when
|
||||
// serialized to apply the sort. We no longer support this.
|
||||
assert((flags & ASN1_TFLG_SEQUENCE_OF) == 0);
|
||||
} else {
|
||||
isset = 0;
|
||||
}
|
||||
|
||||
// Work out inner tag value: if EXPLICIT or no tagging use underlying
|
||||
// type.
|
||||
if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
|
||||
sktag = ttag;
|
||||
skaclass = tclass;
|
||||
} else {
|
||||
skaclass = V_ASN1_UNIVERSAL;
|
||||
if (isset) {
|
||||
sktag = V_ASN1_SET;
|
||||
} else {
|
||||
sktag = V_ASN1_SEQUENCE;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine total length of items
|
||||
skcontlen = 0;
|
||||
for (j = 0; j < sk_ASN1_VALUE_num(sk); j++) {
|
||||
int tmplen;
|
||||
skitem = sk_ASN1_VALUE_value(sk, j);
|
||||
tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
|
||||
if (tmplen == -1 || (skcontlen > INT_MAX - tmplen)) {
|
||||
return -1;
|
||||
}
|
||||
skcontlen += tmplen;
|
||||
}
|
||||
sklen = ASN1_object_size(/*constructed=*/1, skcontlen, sktag);
|
||||
if (sklen == -1) {
|
||||
return -1;
|
||||
}
|
||||
// If EXPLICIT need length of surrounding tag
|
||||
if (flags & ASN1_TFLG_EXPTAG) {
|
||||
ret = ASN1_object_size(/*constructed=*/1, sklen, ttag);
|
||||
} else {
|
||||
ret = sklen;
|
||||
}
|
||||
|
||||
if (!out || ret == -1) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Now encode this lot...
|
||||
// EXPLICIT tag
|
||||
if (flags & ASN1_TFLG_EXPTAG) {
|
||||
ASN1_put_object(out, /*constructed=*/1, sklen, ttag, tclass);
|
||||
}
|
||||
// SET or SEQUENCE and IMPLICIT tag
|
||||
ASN1_put_object(out, /*constructed=*/1, skcontlen, sktag, skaclass);
|
||||
// And the stuff itself
|
||||
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_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);
|
||||
if (ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Either normal or IMPLICIT tagging
|
||||
return asn1_item_ex_i2d_opt(pval, out, ASN1_ITEM_ptr(tt->item), ttag, tclass,
|
||||
optional);
|
||||
}
|
||||
|
||||
// Temporary structure used to hold DER encoding of items for SET OF
|
||||
|
||||
typedef struct {
|
||||
unsigned char *data;
|
||||
int length;
|
||||
} DER_ENC;
|
||||
|
||||
static int der_cmp(const void *a, const void *b) {
|
||||
const DER_ENC *d1 = reinterpret_cast<const DER_ENC *>(a),
|
||||
*d2 = reinterpret_cast<const DER_ENC *>(b);
|
||||
int cmplen, i;
|
||||
cmplen = (d1->length < d2->length) ? d1->length : d2->length;
|
||||
i = OPENSSL_memcmp(d1->data, d2->data, cmplen);
|
||||
if (i) {
|
||||
return i;
|
||||
}
|
||||
return d1->length - d2->length;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
uint8_t *const buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(skcontlen));
|
||||
DER_ENC *encoded = reinterpret_cast<DER_ENC *>(
|
||||
OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded)));
|
||||
uint8_t *p = buf;
|
||||
if (encoded == NULL || buf == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Encode all the elements into |buf| and populate |encoded|.
|
||||
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 (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;
|
||||
|
||||
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,
|
||||
int optional) {
|
||||
// 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.
|
||||
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) {
|
||||
tag = utype;
|
||||
}
|
||||
|
||||
// Output tag+length followed by content octets
|
||||
if (out) {
|
||||
if (usetag) {
|
||||
ASN1_put_object(out, /*constructed=*/0, len, tag, aclass);
|
||||
}
|
||||
int len2 = asn1_ex_i2c(pval, *out, &omit, &utype, it);
|
||||
if (len2 < 0) {
|
||||
return -1;
|
||||
}
|
||||
assert(len == len2);
|
||||
assert(!omit);
|
||||
*out += len;
|
||||
}
|
||||
|
||||
if (usetag) {
|
||||
return ASN1_object_size(/*constructed=*/0, len, tag);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
// 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;
|
||||
ASN1_OBJECT *otmp;
|
||||
int utype;
|
||||
const unsigned char *cont;
|
||||
unsigned char c;
|
||||
int len;
|
||||
|
||||
assert(it->itype == ASN1_ITYPE_PRIMITIVE || it->itype == ASN1_ITYPE_MSTRING);
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
*out_omit = 0;
|
||||
|
||||
// Handle omitted optional values for all but BOOLEAN, which uses a
|
||||
// non-pointer representation.
|
||||
if (it->itype != ASN1_ITYPE_PRIMITIVE || it->utype != V_ASN1_BOOLEAN) {
|
||||
if (!*pval) {
|
||||
*out_omit = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (it->itype == ASN1_ITYPE_MSTRING || it->utype == V_ASN1_ANY_AS_STRING) {
|
||||
// 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.
|
||||
if (utype == V_ASN1_NEG_INTEGER) {
|
||||
utype = V_ASN1_INTEGER;
|
||||
} else if (utype == V_ASN1_NEG_ENUMERATED) {
|
||||
utype = V_ASN1_ENUMERATED;
|
||||
}
|
||||
*putype = utype;
|
||||
} else if (it->utype == V_ASN1_ANY) {
|
||||
// If ANY set type and pointer to value
|
||||
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 {
|
||||
utype = *putype;
|
||||
}
|
||||
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
otmp = (ASN1_OBJECT *)*pval;
|
||||
cont = otmp->data;
|
||||
len = otmp->length;
|
||||
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:
|
||||
cont = NULL;
|
||||
len = 0;
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
tbool = (ASN1_BOOLEAN *)pval;
|
||||
if (*tbool == ASN1_BOOLEAN_NONE) {
|
||||
*out_omit = 1;
|
||||
return 0;
|
||||
}
|
||||
if (it->utype != V_ASN1_ANY) {
|
||||
// Default handling if value == size field then omit
|
||||
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: {
|
||||
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: {
|
||||
// |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:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
// This is not a valid |ASN1_ITEM| type, but it appears in |ASN1_TYPE|.
|
||||
case V_ASN1_OTHER:
|
||||
// All based on ASN1_STRING and handled the same
|
||||
strtmp = (ASN1_STRING *)*pval;
|
||||
cont = strtmp->data;
|
||||
len = strtmp->length;
|
||||
break;
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
if (cout && len) {
|
||||
OPENSSL_memcpy(cout, cont, len);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// Free up an ASN1 structure
|
||||
|
||||
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) {
|
||||
ASN1_item_ex_free(&val, it);
|
||||
}
|
||||
|
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
if (!pval) {
|
||||
return;
|
||||
}
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
ASN1_template_free(pval, it->templates);
|
||||
} else {
|
||||
ASN1_primitive_free(pval, it);
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
ASN1_primitive_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
if (asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL) == 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
const ASN1_TEMPLATE *tt = it->templates + i;
|
||||
ASN1_VALUE **pchval = asn1_get_field_ptr(pval, tt);
|
||||
ASN1_template_free(pchval, tt);
|
||||
}
|
||||
if (asn1_cb) {
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
}
|
||||
OPENSSL_free(*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_EXTERN: {
|
||||
const ASN1_EXTERN_FUNCS *ef =
|
||||
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
if (ef && ef->asn1_ex_free) {
|
||||
ef->asn1_ex_free(pval, it);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
if (!asn1_refcount_dec_and_test_zero(pval, it)) {
|
||||
return;
|
||||
}
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
if (asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL) == 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
asn1_enc_free(pval, it);
|
||||
// If we free up as normal we will invalidate any ANY DEFINED BY
|
||||
// field and we wont be able to determine the type of the field it
|
||||
// defines. So free up in reverse order.
|
||||
for (int i = it->tcount - 1; i >= 0; i--) {
|
||||
const ASN1_TEMPLATE *seqtt = asn1_do_adb(pval, &it->templates[i], 0);
|
||||
if (!seqtt) {
|
||||
continue;
|
||||
}
|
||||
ASN1_VALUE **pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
}
|
||||
if (asn1_cb) {
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
}
|
||||
OPENSSL_free(*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
if (tt->flags & ASN1_TFLG_SK_MASK) {
|
||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *vtmp = sk_ASN1_VALUE_value(sk, i);
|
||||
ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
sk_ASN1_VALUE_free(sk);
|
||||
*pval = NULL;
|
||||
} else {
|
||||
ASN1_item_ex_free(pval, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of calbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
int utype = it->itype == ASN1_ITYPE_MSTRING ? -1 : it->utype;
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (it) {
|
||||
*(ASN1_BOOLEAN *)pval = (ASN1_BOOLEAN)it->size;
|
||||
} else {
|
||||
*(ASN1_BOOLEAN *)pval = ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
return;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
break;
|
||||
|
||||
case V_ASN1_ANY:
|
||||
if (*pval != NULL) {
|
||||
asn1_type_cleanup((ASN1_TYPE *)*pval);
|
||||
OPENSSL_free(*pval);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1_STRING_free((ASN1_STRING *)*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
*pval = NULL;
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
static int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) {
|
||||
ASN1_VALUE *ret = NULL;
|
||||
if (ASN1_item_ex_new(&ret, it) > 0) {
|
||||
return ret;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate an ASN1 structure
|
||||
|
||||
int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
const ASN1_TEMPLATE *tt = NULL;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
ASN1_VALUE **pseqval;
|
||||
int i;
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
if (ef && ef->asn1_ex_new) {
|
||||
if (!ef->asn1_ex_new(pval, it)) {
|
||||
goto memerr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
if (!ASN1_template_new(pval, it->templates)) {
|
||||
goto memerr;
|
||||
}
|
||||
} else if (!ASN1_primitive_new(pval, it)) {
|
||||
goto memerr;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
if (!ASN1_primitive_new(pval, it)) {
|
||||
goto memerr;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_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) {
|
||||
goto auxerr;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = reinterpret_cast<ASN1_VALUE *>(OPENSSL_zalloc(it->size));
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
asn1_set_choice_selector(pval, -1, it);
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) {
|
||||
goto auxerr2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_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) {
|
||||
goto auxerr;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = reinterpret_cast<ASN1_VALUE *>(OPENSSL_zalloc(it->size));
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
asn1_refcount_set_one(pval, it);
|
||||
asn1_enc_init(pval, it);
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
pseqval = asn1_get_field_ptr(pval, tt);
|
||||
if (!ASN1_template_new(pseqval, tt)) {
|
||||
goto memerr2;
|
||||
}
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) {
|
||||
goto auxerr2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
memerr2:
|
||||
ASN1_item_ex_free(pval, it);
|
||||
memerr:
|
||||
return 0;
|
||||
|
||||
auxerr2:
|
||||
ASN1_item_ex_free(pval, it);
|
||||
auxerr:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
*pval = NULL;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
asn1_template_clear(pval, it->templates);
|
||||
} else {
|
||||
asn1_primitive_clear(pval, it);
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
asn1_primitive_clear(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
|
||||
int ret;
|
||||
if (tt->flags & ASN1_TFLG_OPTIONAL) {
|
||||
asn1_template_clear(pval, tt);
|
||||
return 1;
|
||||
}
|
||||
// If ANY DEFINED BY nothing to do
|
||||
|
||||
if (tt->flags & ASN1_TFLG_ADB_MASK) {
|
||||
*pval = NULL;
|
||||
return 1;
|
||||
}
|
||||
// If SET OF or SEQUENCE OF, its a STACK
|
||||
if (tt->flags & ASN1_TFLG_SK_MASK) {
|
||||
STACK_OF(ASN1_VALUE) *skval;
|
||||
skval = sk_ASN1_VALUE_new_null();
|
||||
if (!skval) {
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)skval;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
// Otherwise pass it back to the item routine
|
||||
ret = ASN1_item_ex_new(pval, it);
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
// If ADB or STACK just NULL the field
|
||||
if (tt->flags & (ASN1_TFLG_ADB_MASK | ASN1_TFLG_SK_MASK)) {
|
||||
*pval = NULL;
|
||||
} else {
|
||||
asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
}
|
||||
|
||||
// NB: could probably combine most of the real XXX_new() behaviour and junk
|
||||
// all the old functions.
|
||||
|
||||
static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
if (!it) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of calbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
int utype;
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
utype = -1;
|
||||
} else {
|
||||
utype = it->utype;
|
||||
}
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
*pval = (ASN1_VALUE *)OBJ_get_undef();
|
||||
return 1;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
*(ASN1_BOOLEAN *)pval = (ASN1_BOOLEAN)it->size;
|
||||
return 1;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
*pval = (ASN1_VALUE *)1;
|
||||
return 1;
|
||||
|
||||
case V_ASN1_ANY: {
|
||||
ASN1_TYPE *typ =
|
||||
reinterpret_cast<ASN1_TYPE *>(OPENSSL_malloc(sizeof(ASN1_TYPE)));
|
||||
if (!typ) {
|
||||
return 0;
|
||||
}
|
||||
typ->value.ptr = NULL;
|
||||
typ->type = -1;
|
||||
*pval = (ASN1_VALUE *)typ;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
*pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
|
||||
break;
|
||||
}
|
||||
if (*pval) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
int utype;
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of calbacks.
|
||||
assert(it == NULL || it->funcs == NULL);
|
||||
if (!it || (it->itype == ASN1_ITYPE_MSTRING)) {
|
||||
utype = -1;
|
||||
} else {
|
||||
utype = it->utype;
|
||||
}
|
||||
if (utype == V_ASN1_BOOLEAN) {
|
||||
*(ASN1_BOOLEAN *)pval = (ASN1_BOOLEAN)it->size;
|
||||
} else {
|
||||
*pval = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
|
||||
IMPLEMENT_ASN1_TYPE(sname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(sname, sname, sname) \
|
||||
sname *sname##_new(void) { return ASN1_STRING_type_new(V_##sname); } \
|
||||
void sname##_free(sname *x) { ASN1_STRING_free(x); }
|
||||
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_NULL)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_NULL)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ANY)
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ANY_AS_STRING)
|
||||
|
||||
// Just swallow an ASN1_SEQUENCE in an ASN1_STRING
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DISPLAYTEXT, DISPLAYTEXT)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_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, ASN1_BOOLEAN_NONE)
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_TRUE)
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_FALSE)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
|
||||
ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0,
|
||||
ASN1_SET_ANY, ASN1_ANY)
|
||||
ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
|
||||
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY,
|
||||
ASN1_SEQUENCE_ANY,
|
||||
ASN1_SEQUENCE_ANY)
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SET_ANY,
|
||||
ASN1_SET_ANY)
|
||||
@@ -1,229 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/pool.h>
|
||||
#include <openssl/thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// Utility functions for manipulating fields and offsets
|
||||
|
||||
// Add 'offset' to 'addr'
|
||||
#define offset2ptr(addr, offset) (void *)(((char *)(addr)) + (offset))
|
||||
|
||||
// Given an ASN1_ITEM CHOICE type return the selector value
|
||||
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
int *sel = reinterpret_cast<int *>(offset2ptr(*pval, it->utype));
|
||||
return *sel;
|
||||
}
|
||||
|
||||
// Given an ASN1_ITEM CHOICE type set the selector value, return old value.
|
||||
int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
|
||||
const ASN1_ITEM *it) {
|
||||
int *sel, ret;
|
||||
sel = reinterpret_cast<int *>(offset2ptr(*pval, it->utype));
|
||||
ret = *sel;
|
||||
*sel = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static CRYPTO_refcount_t *asn1_get_references(ASN1_VALUE **pval,
|
||||
const ASN1_ITEM *it) {
|
||||
if (it->itype != ASN1_ITYPE_SEQUENCE) {
|
||||
return NULL;
|
||||
}
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) {
|
||||
return NULL;
|
||||
}
|
||||
return reinterpret_cast<CRYPTO_refcount_t *>(
|
||||
offset2ptr(*pval, aux->ref_offset));
|
||||
}
|
||||
|
||||
void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
CRYPTO_refcount_t *references = asn1_get_references(pval, it);
|
||||
if (references != NULL) {
|
||||
*references = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
CRYPTO_refcount_t *references = asn1_get_references(pval, it);
|
||||
if (references != NULL) {
|
||||
return CRYPTO_refcount_dec_and_test_zero(references);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) {
|
||||
return NULL;
|
||||
}
|
||||
return reinterpret_cast<ASN1_ENCODING *>(offset2ptr(*pval, aux->enc_offset));
|
||||
}
|
||||
|
||||
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
ASN1_ENCODING *enc = asn1_get_enc_ptr(pval, it);
|
||||
if (enc) {
|
||||
enc->enc = NULL;
|
||||
enc->len = 0;
|
||||
enc->buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
ASN1_ENCODING *enc = asn1_get_enc_ptr(pval, it);
|
||||
if (enc) {
|
||||
asn1_encoding_clear(enc);
|
||||
}
|
||||
}
|
||||
|
||||
int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t in_len,
|
||||
const ASN1_ITEM *it, CRYPTO_BUFFER *buf) {
|
||||
ASN1_ENCODING *enc;
|
||||
enc = asn1_get_enc_ptr(pval, it);
|
||||
if (!enc) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
asn1_encoding_clear(enc);
|
||||
if (buf != NULL) {
|
||||
assert(CRYPTO_BUFFER_data(buf) <= in &&
|
||||
in + in_len <= CRYPTO_BUFFER_data(buf) + CRYPTO_BUFFER_len(buf));
|
||||
CRYPTO_BUFFER_up_ref(buf);
|
||||
enc->buf = buf;
|
||||
enc->enc = (uint8_t *)in;
|
||||
} else {
|
||||
enc->enc = reinterpret_cast<uint8_t *>(OPENSSL_memdup(in, in_len));
|
||||
if (!enc->enc) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
enc->len = in_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void asn1_encoding_clear(ASN1_ENCODING *enc) {
|
||||
if (enc->buf != NULL) {
|
||||
CRYPTO_BUFFER_free(enc->buf);
|
||||
} else {
|
||||
OPENSSL_free(enc->enc);
|
||||
}
|
||||
enc->enc = NULL;
|
||||
enc->len = 0;
|
||||
enc->buf = NULL;
|
||||
}
|
||||
|
||||
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||
const ASN1_ITEM *it) {
|
||||
ASN1_ENCODING *enc = asn1_get_enc_ptr(pval, it);
|
||||
if (!enc || enc->len == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (out) {
|
||||
OPENSSL_memcpy(*out, enc->enc, enc->len);
|
||||
*out += enc->len;
|
||||
}
|
||||
if (len) {
|
||||
*len = enc->len;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Given an ASN1_TEMPLATE get a pointer to a field
|
||||
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
ASN1_VALUE **pvaltmp =
|
||||
reinterpret_cast<ASN1_VALUE **>(offset2ptr(*pval, tt->offset));
|
||||
// NOTE for BOOLEAN types the field is just a plain int so we can't return
|
||||
// int **, so settle for (int *).
|
||||
return pvaltmp;
|
||||
}
|
||||
|
||||
// Handle ANY DEFINED BY template, find the selector, look up the relevant
|
||||
// ASN1_TEMPLATE in the table and return it.
|
||||
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||
int nullerr) {
|
||||
const ASN1_ADB *adb;
|
||||
const ASN1_ADB_TABLE *atbl;
|
||||
ASN1_VALUE **sfld;
|
||||
int i;
|
||||
if (!(tt->flags & ASN1_TFLG_ADB_MASK)) {
|
||||
return tt;
|
||||
}
|
||||
|
||||
// Else ANY DEFINED BY ... get the table
|
||||
adb = ASN1_ADB_ptr(tt->item);
|
||||
|
||||
// Get the selector field
|
||||
sfld = reinterpret_cast<ASN1_VALUE **>(offset2ptr(*pval, adb->offset));
|
||||
|
||||
// Check if NULL
|
||||
int selector;
|
||||
if (*sfld == NULL) {
|
||||
if (!adb->null_tt) {
|
||||
goto err;
|
||||
}
|
||||
return adb->null_tt;
|
||||
}
|
||||
|
||||
// Convert type to a NID:
|
||||
// NB: don't check for NID_undef here because it
|
||||
// might be a legitimate value in the table
|
||||
assert(tt->flags & ASN1_TFLG_ADB_OID);
|
||||
selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
|
||||
|
||||
// Try to find matching entry in table Maybe should check application types
|
||||
// first to allow application override? Might also be useful to have a flag
|
||||
// which indicates table is sorted and we can do a binary search. For now
|
||||
// stick to a linear search.
|
||||
|
||||
for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++) {
|
||||
if (atbl->value == selector) {
|
||||
return &atbl->tt;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: need to search application table too
|
||||
|
||||
// No match, return default type
|
||||
if (!adb->default_tt) {
|
||||
goto err;
|
||||
}
|
||||
return adb->default_tt;
|
||||
|
||||
err:
|
||||
// FIXME: should log the value or OID of unsupported type
|
||||
if (nullerr) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/base64.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// constant_time_lt_args_8 behaves like |constant_time_lt_8| but takes |uint8_t|
|
||||
// arguments for a slightly simpler implementation.
|
||||
static inline uint8_t constant_time_lt_args_8(uint8_t a, uint8_t b) {
|
||||
crypto_word_t aw = a;
|
||||
crypto_word_t bw = b;
|
||||
// |crypto_word_t| is larger than |uint8_t|, so |aw| and |bw| have the same
|
||||
// MSB. |aw| < |bw| iff MSB(|aw| - |bw|) is 1.
|
||||
return constant_time_msb_w(aw - bw);
|
||||
}
|
||||
|
||||
// constant_time_in_range_8 returns |CONSTTIME_TRUE_8| if |min| <= |a| <= |max|
|
||||
// and |CONSTTIME_FALSE_8| otherwise.
|
||||
static inline uint8_t constant_time_in_range_8(uint8_t a, uint8_t min,
|
||||
uint8_t max) {
|
||||
a -= min;
|
||||
return constant_time_lt_args_8(a, max - min + 1);
|
||||
}
|
||||
|
||||
// Encoding.
|
||||
|
||||
static uint8_t conv_bin2ascii(uint8_t a) {
|
||||
// Since PEM is sometimes used to carry private keys, we encode base64 data
|
||||
// itself in constant-time.
|
||||
a &= 0x3f;
|
||||
uint8_t ret = constant_time_select_8(constant_time_eq_8(a, 62), '+', '/');
|
||||
ret =
|
||||
constant_time_select_8(constant_time_lt_args_8(a, 62), a - 52 + '0', ret);
|
||||
ret =
|
||||
constant_time_select_8(constant_time_lt_args_8(a, 52), a - 26 + 'a', ret);
|
||||
ret = constant_time_select_8(constant_time_lt_args_8(a, 26), a + 'A', ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static_assert(sizeof(((EVP_ENCODE_CTX *)(NULL))->data) % 3 == 0,
|
||||
"data length must be a multiple of base64 chunk size");
|
||||
|
||||
int EVP_EncodedLength(size_t *out_len, size_t len) {
|
||||
if (len + 2 < len) {
|
||||
return 0;
|
||||
}
|
||||
len += 2;
|
||||
len /= 3;
|
||||
|
||||
if (((len << 2) >> 2) != len) {
|
||||
return 0;
|
||||
}
|
||||
len <<= 2;
|
||||
|
||||
if (len + 1 < len) {
|
||||
return 0;
|
||||
}
|
||||
len++;
|
||||
|
||||
*out_len = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void) {
|
||||
return reinterpret_cast<EVP_ENCODE_CTX *>(
|
||||
OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX)));
|
||||
}
|
||||
|
||||
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) { OPENSSL_free(ctx); }
|
||||
|
||||
void EVP_EncodeInit(EVP_ENCODE_CTX *ctx) {
|
||||
OPENSSL_memset(ctx, 0, sizeof(EVP_ENCODE_CTX));
|
||||
}
|
||||
|
||||
void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
size_t total = 0;
|
||||
|
||||
*out_len = 0;
|
||||
if (in_len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(ctx->data_used < sizeof(ctx->data));
|
||||
|
||||
if (sizeof(ctx->data) - ctx->data_used > in_len) {
|
||||
OPENSSL_memcpy(&ctx->data[ctx->data_used], in, in_len);
|
||||
ctx->data_used += (unsigned)in_len;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->data_used != 0) {
|
||||
const size_t todo = sizeof(ctx->data) - ctx->data_used;
|
||||
OPENSSL_memcpy(&ctx->data[ctx->data_used], in, todo);
|
||||
in += todo;
|
||||
in_len -= todo;
|
||||
|
||||
size_t encoded = EVP_EncodeBlock(out, ctx->data, sizeof(ctx->data));
|
||||
ctx->data_used = 0;
|
||||
|
||||
out += encoded;
|
||||
*(out++) = '\n';
|
||||
*out = '\0';
|
||||
|
||||
total = encoded + 1;
|
||||
}
|
||||
|
||||
while (in_len >= sizeof(ctx->data)) {
|
||||
size_t encoded = EVP_EncodeBlock(out, in, sizeof(ctx->data));
|
||||
in += sizeof(ctx->data);
|
||||
in_len -= sizeof(ctx->data);
|
||||
|
||||
out += encoded;
|
||||
*(out++) = '\n';
|
||||
*out = '\0';
|
||||
|
||||
if (total + encoded + 1 < total) {
|
||||
*out_len = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
total += encoded + 1;
|
||||
}
|
||||
|
||||
if (in_len != 0) {
|
||||
OPENSSL_memcpy(ctx->data, in, in_len);
|
||||
}
|
||||
|
||||
ctx->data_used = (unsigned)in_len;
|
||||
|
||||
if (total > INT_MAX) {
|
||||
// We cannot signal an error, but we can at least avoid making *out_len
|
||||
// negative.
|
||||
total = 0;
|
||||
}
|
||||
*out_len = (int)total;
|
||||
}
|
||||
|
||||
void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len) {
|
||||
if (ctx->data_used == 0) {
|
||||
*out_len = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t encoded = EVP_EncodeBlock(out, ctx->data, ctx->data_used);
|
||||
out[encoded++] = '\n';
|
||||
out[encoded] = '\0';
|
||||
ctx->data_used = 0;
|
||||
|
||||
// ctx->data_used is bounded by sizeof(ctx->data), so this does not
|
||||
// overflow.
|
||||
assert(encoded <= INT_MAX);
|
||||
*out_len = (int)encoded;
|
||||
}
|
||||
|
||||
size_t EVP_EncodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len) {
|
||||
uint32_t l;
|
||||
size_t remaining = src_len, ret = 0;
|
||||
|
||||
while (remaining) {
|
||||
if (remaining >= 3) {
|
||||
l = (((uint32_t)src[0]) << 16L) | (((uint32_t)src[1]) << 8L) | src[2];
|
||||
*(dst++) = conv_bin2ascii(l >> 18L);
|
||||
*(dst++) = conv_bin2ascii(l >> 12L);
|
||||
*(dst++) = conv_bin2ascii(l >> 6L);
|
||||
*(dst++) = conv_bin2ascii(l);
|
||||
remaining -= 3;
|
||||
} else {
|
||||
l = ((uint32_t)src[0]) << 16L;
|
||||
if (remaining == 2) {
|
||||
l |= ((uint32_t)src[1] << 8L);
|
||||
}
|
||||
|
||||
*(dst++) = conv_bin2ascii(l >> 18L);
|
||||
*(dst++) = conv_bin2ascii(l >> 12L);
|
||||
*(dst++) = (remaining == 1) ? '=' : conv_bin2ascii(l >> 6L);
|
||||
*(dst++) = '=';
|
||||
remaining = 0;
|
||||
}
|
||||
ret += 4;
|
||||
src += 3;
|
||||
}
|
||||
|
||||
*dst = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// Decoding.
|
||||
|
||||
int EVP_DecodedLength(size_t *out_len, size_t len) {
|
||||
if (len % 4 != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_len = (len / 4) * 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void EVP_DecodeInit(EVP_ENCODE_CTX *ctx) {
|
||||
OPENSSL_memset(ctx, 0, sizeof(EVP_ENCODE_CTX));
|
||||
}
|
||||
|
||||
static uint8_t base64_ascii_to_bin(uint8_t a) {
|
||||
// Since PEM is sometimes used to carry private keys, we decode base64 data
|
||||
// itself in constant-time.
|
||||
const uint8_t is_upper = constant_time_in_range_8(a, 'A', 'Z');
|
||||
const uint8_t is_lower = constant_time_in_range_8(a, 'a', 'z');
|
||||
const uint8_t is_digit = constant_time_in_range_8(a, '0', '9');
|
||||
const uint8_t is_plus = constant_time_eq_8(a, '+');
|
||||
const uint8_t is_slash = constant_time_eq_8(a, '/');
|
||||
const uint8_t is_equals = constant_time_eq_8(a, '=');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// base64_decode_quad decodes a single “quad” (i.e. four characters) of base64
|
||||
// data and writes up to three bytes to |out|. It sets |*out_num_bytes| to the
|
||||
// number of bytes written, which will be less than three if the quad ended
|
||||
// with padding. It returns one on success or zero on error.
|
||||
static int base64_decode_quad(uint8_t *out, size_t *out_num_bytes,
|
||||
const uint8_t *in) {
|
||||
const uint8_t a = base64_ascii_to_bin(in[0]);
|
||||
const uint8_t b = base64_ascii_to_bin(in[1]);
|
||||
const uint8_t c = base64_ascii_to_bin(in[2]);
|
||||
const uint8_t d = base64_ascii_to_bin(in[3]);
|
||||
if (a == 0xff || b == 0xff || c == 0xff || d == 0xff) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint32_t v = ((uint32_t)a) << 18 | ((uint32_t)b) << 12 |
|
||||
((uint32_t)c) << 6 | (uint32_t)d;
|
||||
|
||||
const unsigned padding_pattern = (in[0] == '=') << 3 | //
|
||||
(in[1] == '=') << 2 | //
|
||||
(in[2] == '=') << 1 | //
|
||||
(in[3] == '=');
|
||||
|
||||
// In presence of padding, the lowest bits of v are unused. Canonical encoding
|
||||
// (RFC 4648, section 3.5) requires that these bits all be set to zero. Common
|
||||
// PEM parsers accept noncanonical base64, adding to the malleability of the
|
||||
// format. This decoder follows OpenSSL's and Go's PEM parsers and accepts it.
|
||||
switch (padding_pattern) {
|
||||
case 0:
|
||||
// The common case of no padding.
|
||||
*out_num_bytes = 3;
|
||||
out[0] = v >> 16;
|
||||
out[1] = v >> 8;
|
||||
out[2] = v;
|
||||
break;
|
||||
|
||||
case 1: // xxx=
|
||||
*out_num_bytes = 2;
|
||||
out[0] = v >> 16;
|
||||
out[1] = v >> 8;
|
||||
break;
|
||||
|
||||
case 3: // xx==
|
||||
*out_num_bytes = 1;
|
||||
out[0] = v >> 16;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
*out_len = 0;
|
||||
|
||||
if (ctx->error_encountered) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t bytes_out = 0, i;
|
||||
for (i = 0; i < in_len; i++) {
|
||||
const char c = in[i];
|
||||
switch (c) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\r':
|
||||
case '\n':
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctx->eof_seen) {
|
||||
ctx->error_encountered = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->data[ctx->data_used++] = c;
|
||||
if (ctx->data_used == 4) {
|
||||
size_t num_bytes_resulting;
|
||||
if (!base64_decode_quad(out, &num_bytes_resulting, ctx->data)) {
|
||||
ctx->error_encountered = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->data_used = 0;
|
||||
bytes_out += num_bytes_resulting;
|
||||
out += num_bytes_resulting;
|
||||
|
||||
if (num_bytes_resulting < 3) {
|
||||
ctx->eof_seen = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes_out > INT_MAX) {
|
||||
ctx->error_encountered = 1;
|
||||
*out_len = 0;
|
||||
return -1;
|
||||
}
|
||||
*out_len = (int)bytes_out;
|
||||
|
||||
if (ctx->eof_seen) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len) {
|
||||
*out_len = 0;
|
||||
if (ctx->error_encountered || ctx->data_used != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_DecodeBase64(uint8_t *out, size_t *out_len, size_t max_out,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
*out_len = 0;
|
||||
|
||||
if (in_len % 4 != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t max_len;
|
||||
if (!EVP_DecodedLength(&max_len, in_len) || max_out < max_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t i, bytes_out = 0;
|
||||
for (i = 0; i < in_len; i += 4) {
|
||||
size_t num_bytes_resulting;
|
||||
|
||||
if (!base64_decode_quad(out, &num_bytes_resulting, &in[i])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bytes_out += num_bytes_resulting;
|
||||
out += num_bytes_resulting;
|
||||
if (num_bytes_resulting != 3 && i != in_len - 4) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*out_len = bytes_out;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len) {
|
||||
// Trim spaces and tabs from the beginning of the input.
|
||||
while (src_len > 0) {
|
||||
if (src[0] != ' ' && src[0] != '\t') {
|
||||
break;
|
||||
}
|
||||
|
||||
src++;
|
||||
src_len--;
|
||||
}
|
||||
|
||||
// Trim newlines, spaces and tabs from the end of the line.
|
||||
while (src_len > 0) {
|
||||
switch (src[src_len - 1]) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\r':
|
||||
case '\n':
|
||||
src_len--;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
size_t dst_len;
|
||||
if (!EVP_DecodedLength(&dst_len, src_len) || dst_len > INT_MAX ||
|
||||
!EVP_DecodeBase64(dst, &dst_len, dst_len, src, src_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// EVP_DecodeBlock does not take padding into account, so put the
|
||||
// NULs back in... so the caller can strip them back out.
|
||||
while (dst_len % 3 != 0) {
|
||||
dst[dst_len++] = '\0';
|
||||
}
|
||||
assert(dst_len <= INT_MAX);
|
||||
|
||||
return (int)dst_len;
|
||||
}
|
||||
@@ -1,326 +0,0 @@
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <openssl/base64.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../test/test_util.h"
|
||||
|
||||
|
||||
enum encoding_relation {
|
||||
// canonical indicates that the encoding is the expected encoding of the
|
||||
// input.
|
||||
canonical,
|
||||
// valid indicates that the encoding is /a/ valid encoding of the input, but
|
||||
// need not be the canonical one.
|
||||
valid,
|
||||
// invalid indicates that the encoded data is valid.
|
||||
invalid,
|
||||
};
|
||||
|
||||
struct Base64TestVector {
|
||||
enum encoding_relation relation;
|
||||
const char *decoded;
|
||||
const char *encoded;
|
||||
};
|
||||
|
||||
static const Base64TestVector kTestVectors[] = {
|
||||
// Test vectors from RFC 4648, section 10.
|
||||
{canonical, "", ""},
|
||||
{canonical, "f", "Zg==\n"},
|
||||
{canonical, "fo", "Zm8=\n"},
|
||||
{canonical, "foo", "Zm9v\n"},
|
||||
{canonical, "foob", "Zm9vYg==\n"},
|
||||
{canonical, "fooba", "Zm9vYmE=\n"},
|
||||
{canonical, "foobar", "Zm9vYmFy\n"},
|
||||
|
||||
{invalid, "", "Zm9vYmFy=\n"},
|
||||
{invalid, "", "Zm9vYmFy==\n"},
|
||||
{invalid, "", "Zm9vYmFy===\n"},
|
||||
|
||||
// valid non-canonical encodings due to arbitrary whitespace
|
||||
{valid, "foobar", "Zm9vYmFy\n\n"},
|
||||
{valid, "foobar", " Zm9vYmFy\n\n"},
|
||||
{valid, "foobar", " Z m 9 v Y m F y\n\n"},
|
||||
{valid, "foobar", "Zm9vYmFy\r\n"},
|
||||
|
||||
// The following "valid" encodings are arguably invalid, but they are
|
||||
// commonly accepted by parsers, in particular by OpenSSL.
|
||||
{valid, "v", "dv==\n"},
|
||||
{canonical, "w", "dw==\n"},
|
||||
{valid, "w", "dx==\n"},
|
||||
{valid, "w", "d+==\n"},
|
||||
{valid, "w", "d/==\n"},
|
||||
{invalid, "", "d===\n"},
|
||||
{canonical, "w`", "d2A=\n"},
|
||||
{valid, "w`", "d2B=\n"},
|
||||
{valid, "w`", "d2C=\n"},
|
||||
{valid, "w`", "d2D=\n"},
|
||||
{canonical, "wa", "d2E=\n"},
|
||||
|
||||
{invalid, "", "Z"},
|
||||
{invalid, "", "Z\n"},
|
||||
{invalid, "", "ab!c"},
|
||||
{invalid, "", "ab=c"},
|
||||
{invalid, "", "abc"},
|
||||
|
||||
{canonical, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA==\n"},
|
||||
{valid, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA\n==\n"},
|
||||
{valid, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA=\n=\n"},
|
||||
{invalid, "",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA=\n==\n"},
|
||||
{canonical, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4\neHh4eHh"
|
||||
"4eHh4eHh4\n"},
|
||||
{canonical,
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4\neHh4eHh"
|
||||
"4eHh4eHh4eHh4eA==\n"},
|
||||
{valid, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh\n4eHh4eHh"
|
||||
"4eHh4eHh4eHh4eA==\n"},
|
||||
{valid, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e"
|
||||
"Hh4eHh4eHh4eA==\n"},
|
||||
{invalid, "",
|
||||
"eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA=="
|
||||
"\neHh4eHh4eHh4eHh4eHh4eHh4\n"},
|
||||
|
||||
// A '-' has traditionally been treated as the end of the data by OpenSSL
|
||||
// and anything following would be ignored. BoringSSL does not accept this
|
||||
// non-standard extension.
|
||||
{invalid, "", "Zm9vYmFy-anythinggoes"},
|
||||
{invalid, "", "Zm9vYmFy\n-anythinggoes"},
|
||||
|
||||
// CVE-2015-0292
|
||||
{invalid, "",
|
||||
"ZW5jb2RlIG1lCg==========================================================="
|
||||
"=======\n"},
|
||||
};
|
||||
|
||||
class Base64Test : public testing::TestWithParam<Base64TestVector> {};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(All, Base64Test, testing::ValuesIn(kTestVectors));
|
||||
|
||||
// RemoveNewlines returns a copy of |in| with all '\n' characters removed.
|
||||
static std::string RemoveNewlines(const char *in) {
|
||||
std::string ret;
|
||||
const size_t in_len = strlen(in);
|
||||
|
||||
for (size_t i = 0; i < in_len; i++) {
|
||||
if (in[i] != '\n') {
|
||||
ret.push_back(in[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
TEST_P(Base64Test, EncodeBlock) {
|
||||
const Base64TestVector &t = GetParam();
|
||||
if (t.relation != canonical) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t decoded_len = strlen(t.decoded);
|
||||
size_t max_encoded_len;
|
||||
ASSERT_TRUE(EVP_EncodedLength(&max_encoded_len, decoded_len));
|
||||
|
||||
std::vector<uint8_t> out_vec(max_encoded_len);
|
||||
uint8_t *out = out_vec.data();
|
||||
size_t len = EVP_EncodeBlock(out, (const uint8_t *)t.decoded, decoded_len);
|
||||
|
||||
std::string encoded(RemoveNewlines(t.encoded));
|
||||
EXPECT_EQ(Bytes(encoded), Bytes(out, len));
|
||||
}
|
||||
|
||||
TEST_P(Base64Test, DecodeBase64) {
|
||||
const Base64TestVector &t = GetParam();
|
||||
if (t.relation == valid) {
|
||||
// The non-canonical encodings will generally have odd whitespace etc
|
||||
// that |EVP_DecodeBase64| will reject.
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string encoded(RemoveNewlines(t.encoded));
|
||||
std::vector<uint8_t> out_vec(encoded.size());
|
||||
uint8_t *out = out_vec.data();
|
||||
|
||||
size_t len;
|
||||
int ok = EVP_DecodeBase64(out, &len, out_vec.size(),
|
||||
(const uint8_t *)encoded.data(), encoded.size());
|
||||
|
||||
if (t.relation == invalid) {
|
||||
EXPECT_FALSE(ok);
|
||||
} else if (t.relation == canonical) {
|
||||
ASSERT_TRUE(ok);
|
||||
EXPECT_EQ(Bytes(t.decoded), Bytes(out, len));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Base64Test, DecodeBlock) {
|
||||
const Base64TestVector &t = GetParam();
|
||||
if (t.relation != canonical) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string encoded(RemoveNewlines(t.encoded));
|
||||
|
||||
std::vector<uint8_t> out_vec(encoded.size());
|
||||
uint8_t *out = out_vec.data();
|
||||
|
||||
// Test that the padding behavior of the deprecated API is preserved.
|
||||
int ret =
|
||||
EVP_DecodeBlock(out, (const uint8_t *)encoded.data(), encoded.size());
|
||||
ASSERT_GE(ret, 0);
|
||||
// EVP_DecodeBlock should ignore padding.
|
||||
ASSERT_EQ(0, ret % 3);
|
||||
size_t expected_len = strlen(t.decoded);
|
||||
if (expected_len % 3 != 0) {
|
||||
ret -= 3 - (expected_len % 3);
|
||||
}
|
||||
EXPECT_EQ(Bytes(t.decoded), Bytes(out, static_cast<size_t>(ret)));
|
||||
}
|
||||
|
||||
TEST_P(Base64Test, EncodeDecode) {
|
||||
const Base64TestVector &t = GetParam();
|
||||
|
||||
EVP_ENCODE_CTX ctx;
|
||||
const size_t decoded_len = strlen(t.decoded);
|
||||
|
||||
if (t.relation == canonical) {
|
||||
size_t max_encoded_len;
|
||||
ASSERT_TRUE(EVP_EncodedLength(&max_encoded_len, decoded_len));
|
||||
|
||||
// EVP_EncodeUpdate will output new lines every 64 bytes of output so we
|
||||
// need slightly more than |EVP_EncodedLength| returns. */
|
||||
max_encoded_len += (max_encoded_len + 63) >> 6;
|
||||
std::vector<uint8_t> out_vec(max_encoded_len);
|
||||
uint8_t *out = out_vec.data();
|
||||
|
||||
EVP_EncodeInit(&ctx);
|
||||
|
||||
int out_len;
|
||||
EVP_EncodeUpdate(&ctx, out, &out_len,
|
||||
reinterpret_cast<const uint8_t *>(t.decoded),
|
||||
decoded_len);
|
||||
size_t total = out_len;
|
||||
|
||||
EVP_EncodeFinal(&ctx, out + total, &out_len);
|
||||
total += out_len;
|
||||
|
||||
EXPECT_EQ(Bytes(t.encoded), Bytes(out, total));
|
||||
}
|
||||
|
||||
std::vector<uint8_t> out_vec(strlen(t.encoded));
|
||||
uint8_t *out = out_vec.data();
|
||||
|
||||
EVP_DecodeInit(&ctx);
|
||||
int out_len;
|
||||
size_t total = 0;
|
||||
int ret = EVP_DecodeUpdate(&ctx, out, &out_len,
|
||||
reinterpret_cast<const uint8_t *>(t.encoded),
|
||||
strlen(t.encoded));
|
||||
if (ret != -1) {
|
||||
total = out_len;
|
||||
ret = EVP_DecodeFinal(&ctx, out + total, &out_len);
|
||||
total += out_len;
|
||||
}
|
||||
|
||||
switch (t.relation) {
|
||||
case canonical:
|
||||
case valid:
|
||||
ASSERT_NE(-1, ret);
|
||||
EXPECT_EQ(Bytes(t.decoded), Bytes(out, total));
|
||||
break;
|
||||
|
||||
case invalid:
|
||||
EXPECT_EQ(-1, ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Base64Test, DecodeUpdateStreaming) {
|
||||
const Base64TestVector &t = GetParam();
|
||||
if (t.relation == invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t encoded_len = strlen(t.encoded);
|
||||
|
||||
std::vector<uint8_t> out(encoded_len);
|
||||
|
||||
for (size_t chunk_size = 1; chunk_size <= encoded_len; chunk_size++) {
|
||||
SCOPED_TRACE(chunk_size);
|
||||
size_t out_len = 0;
|
||||
EVP_ENCODE_CTX ctx;
|
||||
EVP_DecodeInit(&ctx);
|
||||
|
||||
for (size_t i = 0; i < encoded_len;) {
|
||||
size_t todo = encoded_len - i;
|
||||
if (todo > chunk_size) {
|
||||
todo = chunk_size;
|
||||
}
|
||||
|
||||
int bytes_written;
|
||||
int ret = EVP_DecodeUpdate(
|
||||
&ctx, out.data() + out_len, &bytes_written,
|
||||
reinterpret_cast<const uint8_t *>(t.encoded + i), todo);
|
||||
i += todo;
|
||||
|
||||
switch (ret) {
|
||||
case -1:
|
||||
FAIL() << "EVP_DecodeUpdate failed";
|
||||
case 0:
|
||||
out_len += bytes_written;
|
||||
if (i == encoded_len ||
|
||||
(i + 1 == encoded_len && t.encoded[i] == '\n') ||
|
||||
// If there was an '-' in the input (which means “EOF”) then
|
||||
// this loop will continue to test that |EVP_DecodeUpdate| will
|
||||
// ignore the remainder of the input.
|
||||
strchr(t.encoded, '-') != nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
FAIL()
|
||||
<< "EVP_DecodeUpdate returned zero before end of encoded data.";
|
||||
case 1:
|
||||
out_len += bytes_written;
|
||||
break;
|
||||
default:
|
||||
FAIL() << "Invalid return value " << ret;
|
||||
}
|
||||
}
|
||||
|
||||
int bytes_written;
|
||||
int ret = EVP_DecodeFinal(&ctx, out.data() + out_len, &bytes_written);
|
||||
ASSERT_NE(ret, -1);
|
||||
out_len += bytes_written;
|
||||
|
||||
EXPECT_EQ(Bytes(t.decoded), Bytes(out.data(), out_len));
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
// Copyright 2024 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Provided by libcrypto, called from BCM
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Provided by libcrypto, called from BCM
|
||||
|
||||
// CRYPTO_init_sysrand initializes long-lived resources needed to draw entropy
|
||||
// from the operating system, if the operating system requires initialization.
|
||||
void CRYPTO_init_sysrand(void);
|
||||
|
||||
// CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating
|
||||
// system.
|
||||
void CRYPTO_sysrand(uint8_t *buf, size_t len);
|
||||
|
||||
// CRYPTO_sysrand_if_available fills |len| bytes at |buf| with entropy from the
|
||||
// operating system, or early /dev/urandom data, and returns 1, _if_ the entropy
|
||||
// pool is initialized or if getrandom() is not available and not in FIPS mode.
|
||||
// Otherwise it will not block and will instead fill |buf| with all zeros and
|
||||
// return 0.
|
||||
int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len);
|
||||
|
||||
// CRYPTO_sysrand_for_seed fills |len| bytes at |buf| with entropy from the
|
||||
// operating system. It may draw from the |GRND_RANDOM| pool on Android,
|
||||
// depending on the vendor's configuration.
|
||||
void CRYPTO_sysrand_for_seed(uint8_t *buf, size_t len);
|
||||
|
||||
// RAND_need_entropy is called whenever the BCM module has stopped because it
|
||||
// has run out of entropy.
|
||||
void RAND_need_entropy(size_t bytes_needed);
|
||||
|
||||
// crypto_get_fork_generation returns the fork generation number for the current
|
||||
// process, or zero if not supported on the platform. The fork generation number
|
||||
// is a non-zero, strictly-monotonic counter with the property that, if queried
|
||||
// in an address space and then again in a subsequently forked copy, the forked
|
||||
// address space will observe a greater value.
|
||||
//
|
||||
// This function may be used to clear cached values across a fork. When
|
||||
// initializing a cache, record the fork generation. Before using the cache,
|
||||
// check if the fork generation has changed. If so, drop the cache and update
|
||||
// the save fork generation. Note this logic transparently handles platforms
|
||||
// which always return zero.
|
||||
//
|
||||
// This is not reliably supported on all platforms which implement |fork|, so it
|
||||
// should only be used as a hardening measure.
|
||||
OPENSSL_EXPORT uint64_t CRYPTO_get_fork_generation(void);
|
||||
|
||||
// CRYPTO_fork_detect_force_madv_wipeonfork_for_testing is an internal detail
|
||||
// used for testing purposes.
|
||||
OPENSSL_EXPORT void CRYPTO_fork_detect_force_madv_wipeonfork_for_testing(
|
||||
int on);
|
||||
|
||||
// CRYPTO_get_stderr returns stderr. This function exists to avoid BCM needing
|
||||
// a data dependency on libc.
|
||||
FILE *CRYPTO_get_stderr(void);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
@@ -1,658 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class =
|
||||
CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
|
||||
|
||||
BIO *BIO_new(const BIO_METHOD *method) {
|
||||
BIO *ret = reinterpret_cast<BIO *>(OPENSSL_zalloc(sizeof(BIO)));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->method = method;
|
||||
ret->shutdown = 1;
|
||||
ret->references = 1;
|
||||
CRYPTO_new_ex_data(&ret->ex_data);
|
||||
|
||||
if (method->create != NULL && !method->create(ret)) {
|
||||
OPENSSL_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BIO_free(BIO *bio) {
|
||||
BIO *next_bio;
|
||||
|
||||
for (; bio != NULL; bio = next_bio) {
|
||||
if (!CRYPTO_refcount_dec_and_test_zero(&bio->references)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
next_bio = BIO_pop(bio);
|
||||
|
||||
if (bio->method != NULL && bio->method->destroy != NULL) {
|
||||
bio->method->destroy(bio);
|
||||
}
|
||||
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, bio, &bio->ex_data);
|
||||
OPENSSL_free(bio);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_up_ref(BIO *bio) {
|
||||
CRYPTO_refcount_inc(&bio->references);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BIO_vfree(BIO *bio) { BIO_free(bio); }
|
||||
|
||||
void BIO_free_all(BIO *bio) { BIO_free(bio); }
|
||||
|
||||
int BIO_read(BIO *bio, void *buf, int len) {
|
||||
if (bio == NULL || bio->method == NULL || bio->method->bread == NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
|
||||
return -2;
|
||||
}
|
||||
if (!bio->init) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
|
||||
return -2;
|
||||
}
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int ret = bio->method->bread(bio, reinterpret_cast<char *>(buf), len);
|
||||
if (ret > 0) {
|
||||
bio->num_read += ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BIO_gets(BIO *bio, char *buf, int len) {
|
||||
if (bio == NULL || bio->method == NULL || bio->method->bgets == NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
|
||||
return -2;
|
||||
}
|
||||
if (!bio->init) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
|
||||
return -2;
|
||||
}
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int ret = bio->method->bgets(bio, buf, len);
|
||||
if (ret > 0) {
|
||||
bio->num_read += ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BIO_write(BIO *bio, const void *in, int inl) {
|
||||
if (bio == NULL || bio->method == NULL || bio->method->bwrite == NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
|
||||
return -2;
|
||||
}
|
||||
if (!bio->init) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED);
|
||||
return -2;
|
||||
}
|
||||
if (inl <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int ret = bio->method->bwrite(bio, reinterpret_cast<const char *>(in), inl);
|
||||
if (ret > 0) {
|
||||
bio->num_write += ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BIO_write_all(BIO *bio, const void *data, size_t len) {
|
||||
const uint8_t *data_u8 = reinterpret_cast<const uint8_t *>(data);
|
||||
while (len > 0) {
|
||||
int ret = BIO_write(bio, data_u8, len > INT_MAX ? INT_MAX : (int)len);
|
||||
if (ret <= 0) {
|
||||
return 0;
|
||||
}
|
||||
data_u8 += ret;
|
||||
len -= ret;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_puts(BIO *bio, const char *in) {
|
||||
size_t len = strlen(in);
|
||||
if (len > INT_MAX) {
|
||||
// |BIO_write| and the return value both assume the string fits in |int|.
|
||||
OPENSSL_PUT_ERROR(BIO, ERR_R_OVERFLOW);
|
||||
return -1;
|
||||
}
|
||||
return BIO_write(bio, in, (int)len);
|
||||
}
|
||||
|
||||
int BIO_flush(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_FLUSH, 0, NULL); }
|
||||
|
||||
long BIO_ctrl(BIO *bio, int cmd, long larg, void *parg) {
|
||||
if (bio == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bio->method == NULL || bio->method->ctrl == NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
|
||||
return -2;
|
||||
}
|
||||
|
||||
return bio->method->ctrl(bio, cmd, larg, parg);
|
||||
}
|
||||
|
||||
char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) {
|
||||
char *p = NULL;
|
||||
|
||||
if (BIO_ctrl(b, cmd, larg, (void *)&p) <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) {
|
||||
int i = iarg;
|
||||
|
||||
return BIO_ctrl(b, cmd, larg, (void *)&i);
|
||||
}
|
||||
|
||||
int BIO_reset(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL); }
|
||||
|
||||
int BIO_eof(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_EOF, 0, NULL); }
|
||||
|
||||
void BIO_set_flags(BIO *bio, int flags) { bio->flags |= flags; }
|
||||
|
||||
int BIO_test_flags(const BIO *bio, int flags) { return bio->flags & flags; }
|
||||
|
||||
int BIO_should_read(const BIO *bio) {
|
||||
return BIO_test_flags(bio, BIO_FLAGS_READ);
|
||||
}
|
||||
|
||||
int BIO_should_write(const BIO *bio) {
|
||||
return BIO_test_flags(bio, BIO_FLAGS_WRITE);
|
||||
}
|
||||
|
||||
int BIO_should_retry(const BIO *bio) {
|
||||
return BIO_test_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
||||
}
|
||||
|
||||
int BIO_should_io_special(const BIO *bio) {
|
||||
return BIO_test_flags(bio, BIO_FLAGS_IO_SPECIAL);
|
||||
}
|
||||
|
||||
int BIO_get_retry_reason(const BIO *bio) { return bio->retry_reason; }
|
||||
|
||||
void BIO_set_retry_reason(BIO *bio, int reason) { bio->retry_reason = reason; }
|
||||
|
||||
void BIO_clear_flags(BIO *bio, int flags) { bio->flags &= ~flags; }
|
||||
|
||||
void BIO_set_retry_read(BIO *bio) {
|
||||
bio->flags |= BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY;
|
||||
}
|
||||
|
||||
void BIO_set_retry_write(BIO *bio) {
|
||||
bio->flags |= BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY;
|
||||
}
|
||||
|
||||
static const int kRetryFlags = BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY;
|
||||
|
||||
int BIO_get_retry_flags(BIO *bio) { return bio->flags & kRetryFlags; }
|
||||
|
||||
void BIO_clear_retry_flags(BIO *bio) {
|
||||
bio->flags &= ~kRetryFlags;
|
||||
bio->retry_reason = 0;
|
||||
}
|
||||
|
||||
int BIO_method_type(const BIO *bio) { return bio->method->type; }
|
||||
|
||||
void BIO_copy_next_retry(BIO *bio) {
|
||||
BIO_clear_retry_flags(bio);
|
||||
BIO_set_flags(bio, BIO_get_retry_flags(bio->next_bio));
|
||||
bio->retry_reason = bio->next_bio->retry_reason;
|
||||
}
|
||||
|
||||
long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
|
||||
if (bio == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bio->method == NULL || bio->method->callback_ctrl == NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bio->method->callback_ctrl(bio, cmd, fp);
|
||||
}
|
||||
|
||||
size_t BIO_pending(const BIO *bio) {
|
||||
const long r = BIO_ctrl((BIO *)bio, BIO_CTRL_PENDING, 0, NULL);
|
||||
assert(r >= 0);
|
||||
|
||||
if (r < 0) {
|
||||
return 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
size_t BIO_ctrl_pending(const BIO *bio) { return BIO_pending(bio); }
|
||||
|
||||
size_t BIO_wpending(const BIO *bio) {
|
||||
const long r = BIO_ctrl((BIO *)bio, BIO_CTRL_WPENDING, 0, NULL);
|
||||
assert(r >= 0);
|
||||
|
||||
if (r < 0) {
|
||||
return 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int BIO_set_close(BIO *bio, int close_flag) {
|
||||
return (int)BIO_ctrl(bio, BIO_CTRL_SET_CLOSE, close_flag, NULL);
|
||||
}
|
||||
|
||||
OPENSSL_EXPORT uint64_t BIO_number_read(const BIO *bio) {
|
||||
return bio->num_read;
|
||||
}
|
||||
|
||||
OPENSSL_EXPORT uint64_t BIO_number_written(const BIO *bio) {
|
||||
return bio->num_write;
|
||||
}
|
||||
|
||||
BIO *BIO_push(BIO *bio, BIO *appended_bio) {
|
||||
BIO *last_bio;
|
||||
|
||||
if (bio == NULL) {
|
||||
return bio;
|
||||
}
|
||||
|
||||
last_bio = bio;
|
||||
while (last_bio->next_bio != NULL) {
|
||||
last_bio = last_bio->next_bio;
|
||||
}
|
||||
|
||||
last_bio->next_bio = appended_bio;
|
||||
return bio;
|
||||
}
|
||||
|
||||
BIO *BIO_pop(BIO *bio) {
|
||||
BIO *ret;
|
||||
|
||||
if (bio == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret = bio->next_bio;
|
||||
bio->next_bio = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO *BIO_next(BIO *bio) {
|
||||
if (!bio) {
|
||||
return NULL;
|
||||
}
|
||||
return bio->next_bio;
|
||||
}
|
||||
|
||||
BIO *BIO_find_type(BIO *bio, int type) {
|
||||
int method_type, mask;
|
||||
|
||||
if (!bio) {
|
||||
return NULL;
|
||||
}
|
||||
mask = type & 0xff;
|
||||
|
||||
do {
|
||||
if (bio->method != NULL) {
|
||||
method_type = bio->method->type;
|
||||
|
||||
if (!mask) {
|
||||
if (method_type & type) {
|
||||
return bio;
|
||||
}
|
||||
} else if (method_type == type) {
|
||||
return bio;
|
||||
}
|
||||
}
|
||||
bio = bio->next_bio;
|
||||
} while (bio != NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int BIO_indent(BIO *bio, unsigned indent, unsigned max_indent) {
|
||||
if (indent > max_indent) {
|
||||
indent = max_indent;
|
||||
}
|
||||
|
||||
while (indent--) {
|
||||
if (BIO_puts(bio, " ") != 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int print_bio(const char *str, size_t len, void *bio) {
|
||||
return BIO_write_all((BIO *)bio, str, len);
|
||||
}
|
||||
|
||||
void ERR_print_errors(BIO *bio) { ERR_print_errors_cb(print_bio, bio); }
|
||||
|
||||
// bio_read_all reads everything from |bio| and prepends |prefix| to it. On
|
||||
// success, |*out| is set to an allocated buffer (which should be freed with
|
||||
// |OPENSSL_free|), |*out_len| is set to its length and one is returned. The
|
||||
// buffer will contain |prefix| followed by the contents of |bio|. On failure,
|
||||
// zero is returned.
|
||||
//
|
||||
// The function will fail if the size of the output would equal or exceed
|
||||
// |max_len|.
|
||||
static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
|
||||
const uint8_t *prefix, size_t prefix_len,
|
||||
size_t max_len) {
|
||||
static const size_t kChunkSize = 4096;
|
||||
|
||||
size_t len = prefix_len + kChunkSize;
|
||||
if (len > max_len) {
|
||||
len = max_len;
|
||||
}
|
||||
if (len < prefix_len) {
|
||||
return 0;
|
||||
}
|
||||
*out = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
|
||||
if (*out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(*out, prefix, prefix_len);
|
||||
size_t done = prefix_len;
|
||||
|
||||
for (;;) {
|
||||
if (done == len) {
|
||||
OPENSSL_free(*out);
|
||||
return 0;
|
||||
}
|
||||
size_t todo = len - done;
|
||||
if (todo > INT_MAX) {
|
||||
todo = INT_MAX;
|
||||
}
|
||||
const int n = BIO_read(bio, *out + done, (int)todo);
|
||||
if (n == 0) {
|
||||
*out_len = done;
|
||||
return 1;
|
||||
} else if (n == -1) {
|
||||
OPENSSL_free(*out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
done += n;
|
||||
if (len < max_len && len - done < kChunkSize / 2) {
|
||||
len += kChunkSize;
|
||||
if (len < kChunkSize || len > max_len) {
|
||||
len = max_len;
|
||||
}
|
||||
uint8_t *new_buf =
|
||||
reinterpret_cast<uint8_t *>(OPENSSL_realloc(*out, len));
|
||||
if (new_buf == NULL) {
|
||||
OPENSSL_free(*out);
|
||||
return 0;
|
||||
}
|
||||
*out = new_buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bio_read_full reads |len| bytes |bio| and writes them into |out|. It
|
||||
// tolerates partial reads from |bio| and returns one on success or zero if a
|
||||
// read fails before |len| bytes are read. On failure, it additionally sets
|
||||
// |*out_eof_on_first_read| to whether the error was due to |bio| returning zero
|
||||
// on the first read. |out_eof_on_first_read| may be NULL to discard the value.
|
||||
static int bio_read_full(BIO *bio, uint8_t *out, int *out_eof_on_first_read,
|
||||
size_t len) {
|
||||
int first_read = 1;
|
||||
while (len > 0) {
|
||||
int todo = len <= INT_MAX ? (int)len : INT_MAX;
|
||||
int ret = BIO_read(bio, out, todo);
|
||||
if (ret <= 0) {
|
||||
if (out_eof_on_first_read != NULL) {
|
||||
*out_eof_on_first_read = first_read && ret == 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
out += ret;
|
||||
len -= (size_t)ret;
|
||||
first_read = 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// For compatibility with existing |d2i_*_bio| callers, |BIO_read_asn1| uses
|
||||
// |ERR_LIB_ASN1| errors.
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ASN1_R_DECODE_ERROR)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ASN1_R_HEADER_TOO_LONG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ASN1_R_NOT_ENOUGH_DATA)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, ASN1_R_TOO_LONG)
|
||||
|
||||
int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
|
||||
uint8_t header[6];
|
||||
|
||||
static const size_t kInitialHeaderLen = 2;
|
||||
int eof_on_first_read;
|
||||
if (!bio_read_full(bio, header, &eof_on_first_read, kInitialHeaderLen)) {
|
||||
if (eof_on_first_read) {
|
||||
// Historically, OpenSSL returned |ASN1_R_HEADER_TOO_LONG| when
|
||||
// |d2i_*_bio| could not read anything. CPython conditions on this to
|
||||
// determine if |bio| was empty.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NOT_ENOUGH_DATA);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint8_t tag = header[0];
|
||||
const uint8_t length_byte = header[1];
|
||||
|
||||
if ((tag & 0x1f) == 0x1f) {
|
||||
// Long form tags are not supported.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t len, header_len;
|
||||
if ((length_byte & 0x80) == 0) {
|
||||
// Short form length.
|
||||
len = length_byte;
|
||||
header_len = kInitialHeaderLen;
|
||||
} else {
|
||||
const size_t num_bytes = length_byte & 0x7f;
|
||||
|
||||
if ((tag & 0x20 /* constructed */) != 0 && num_bytes == 0) {
|
||||
// indefinite length.
|
||||
if (!bio_read_all(bio, out, out_len, header, kInitialHeaderLen,
|
||||
max_len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NOT_ENOUGH_DATA);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (num_bytes == 0 || num_bytes > 4) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bio_read_full(bio, header + kInitialHeaderLen, NULL, num_bytes)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NOT_ENOUGH_DATA);
|
||||
return 0;
|
||||
}
|
||||
header_len = kInitialHeaderLen + num_bytes;
|
||||
|
||||
uint32_t len32 = 0;
|
||||
for (unsigned i = 0; i < num_bytes; i++) {
|
||||
len32 <<= 8;
|
||||
len32 |= header[kInitialHeaderLen + i];
|
||||
}
|
||||
|
||||
if (len32 < 128) {
|
||||
// Length should have used short-form encoding.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((len32 >> ((num_bytes - 1) * 8)) == 0) {
|
||||
// Length should have been at least one byte shorter.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = len32;
|
||||
}
|
||||
|
||||
if (len + header_len < len || len + header_len > max_len || len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
len += header_len;
|
||||
*out_len = len;
|
||||
|
||||
*out = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
|
||||
if (*out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(*out, header, header_len);
|
||||
if (!bio_read_full(bio, (*out) + header_len, NULL, len - header_len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NOT_ENOUGH_DATA);
|
||||
OPENSSL_free(*out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BIO_set_retry_special(BIO *bio) {
|
||||
bio->flags |= BIO_FLAGS_READ | BIO_FLAGS_IO_SPECIAL;
|
||||
}
|
||||
|
||||
int BIO_set_write_buffer_size(BIO *bio, int buffer_size) { return 0; }
|
||||
|
||||
static CRYPTO_MUTEX g_index_lock = CRYPTO_MUTEX_INIT;
|
||||
static int g_index = BIO_TYPE_START;
|
||||
|
||||
int BIO_get_new_index(void) {
|
||||
CRYPTO_MUTEX_lock_write(&g_index_lock);
|
||||
// If |g_index| exceeds 255, it will collide with the flags bits.
|
||||
int ret = g_index > 255 ? -1 : g_index++;
|
||||
CRYPTO_MUTEX_unlock_write(&g_index_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO_METHOD *BIO_meth_new(int type, const char *name) {
|
||||
BIO_METHOD *method =
|
||||
reinterpret_cast<BIO_METHOD *>(OPENSSL_zalloc(sizeof(BIO_METHOD)));
|
||||
if (method == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
method->type = type;
|
||||
method->name = name;
|
||||
return method;
|
||||
}
|
||||
|
||||
void BIO_meth_free(BIO_METHOD *method) { OPENSSL_free(method); }
|
||||
|
||||
int BIO_meth_set_create(BIO_METHOD *method, int (*create_func)(BIO *)) {
|
||||
method->create = create_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_destroy(BIO_METHOD *method, int (*destroy_func)(BIO *)) {
|
||||
method->destroy = destroy_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_write(BIO_METHOD *method,
|
||||
int (*write_func)(BIO *, const char *, int)) {
|
||||
method->bwrite = write_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_read(BIO_METHOD *method,
|
||||
int (*read_func)(BIO *, char *, int)) {
|
||||
method->bread = read_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_gets(BIO_METHOD *method,
|
||||
int (*gets_func)(BIO *, char *, int)) {
|
||||
method->bgets = gets_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_ctrl(BIO_METHOD *method,
|
||||
long (*ctrl_func)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BIO_set_data(BIO *bio, void *ptr) { bio->ptr = ptr; }
|
||||
|
||||
void *BIO_get_data(BIO *bio) { return bio->ptr; }
|
||||
|
||||
void BIO_set_init(BIO *bio, int init) { bio->init = init; }
|
||||
|
||||
int BIO_get_init(BIO *bio) { return bio->init; }
|
||||
|
||||
void BIO_set_shutdown(BIO *bio, int shutdown) { bio->shutdown = shutdown; }
|
||||
|
||||
int BIO_get_shutdown(BIO *bio) { return bio->shutdown; }
|
||||
|
||||
int BIO_meth_set_puts(BIO_METHOD *method, int (*puts)(BIO *, const char *)) {
|
||||
// Ignore the parameter. We implement |BIO_puts| using |BIO_write|.
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_get_ex_new_index(long argl, void *argp, //
|
||||
CRYPTO_EX_unused *unused, //
|
||||
CRYPTO_EX_dup *dup_unused, //
|
||||
CRYPTO_EX_free *free_func) {
|
||||
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
|
||||
}
|
||||
|
||||
int BIO_set_ex_data(BIO *bio, int idx, void *data) {
|
||||
return CRYPTO_set_ex_data(&bio->ex_data, idx, data);
|
||||
}
|
||||
|
||||
void *BIO_get_ex_data(const BIO *bio, int idx) {
|
||||
return CRYPTO_get_ex_data(&bio->ex_data, idx);
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/buf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
BIO *BIO_new_mem_buf(const void *buf, ossl_ssize_t len) {
|
||||
BIO *ret;
|
||||
BUF_MEM *b;
|
||||
const size_t size = len < 0 ? strlen((char *)buf) : (size_t)len;
|
||||
|
||||
if (!buf && len != 0) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_NULL_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = BIO_new(BIO_s_mem());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b = (BUF_MEM *)ret->ptr;
|
||||
// BIO_FLAGS_MEM_RDONLY ensures |b->data| is not written to.
|
||||
b->data = reinterpret_cast<char *>(const_cast<void *>(buf));
|
||||
b->length = size;
|
||||
b->max = size;
|
||||
|
||||
ret->flags |= BIO_FLAGS_MEM_RDONLY;
|
||||
|
||||
// |num| is used to store the value that this BIO will return when it runs
|
||||
// out of data. If it's negative then the retry flags will also be set. Since
|
||||
// this is static data, retrying wont help
|
||||
ret->num = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mem_new(BIO *bio) {
|
||||
BUF_MEM *b;
|
||||
|
||||
b = BUF_MEM_new();
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// |shutdown| is used to store the close flag: whether the BIO has ownership
|
||||
// of the BUF_MEM.
|
||||
bio->shutdown = 1;
|
||||
bio->init = 1;
|
||||
bio->num = -1;
|
||||
bio->ptr = (char *)b;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mem_free(BIO *bio) {
|
||||
if (!bio->shutdown || !bio->init || bio->ptr == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
BUF_MEM *b = (BUF_MEM *)bio->ptr;
|
||||
if (bio->flags & BIO_FLAGS_MEM_RDONLY) {
|
||||
b->data = NULL;
|
||||
}
|
||||
BUF_MEM_free(b);
|
||||
bio->ptr = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mem_read(BIO *bio, char *out, int outl) {
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (outl <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
|
||||
int ret = outl;
|
||||
if ((size_t)ret > b->length) {
|
||||
ret = (int)b->length;
|
||||
}
|
||||
|
||||
if (ret > 0) {
|
||||
OPENSSL_memcpy(out, b->data, ret);
|
||||
b->length -= ret;
|
||||
if (bio->flags & BIO_FLAGS_MEM_RDONLY) {
|
||||
b->data += ret;
|
||||
} else {
|
||||
OPENSSL_memmove(b->data, &b->data[ret], b->length);
|
||||
}
|
||||
} else if (b->length == 0) {
|
||||
ret = bio->num;
|
||||
if (ret != 0) {
|
||||
BIO_set_retry_read(bio);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mem_write(BIO *bio, const char *in, int inl) {
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (inl <= 0) {
|
||||
return 0; // Successfully write zero bytes.
|
||||
}
|
||||
|
||||
if (bio->flags & BIO_FLAGS_MEM_RDONLY) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_WRITE_TO_READ_ONLY_BIO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
|
||||
if (!BUF_MEM_append(b, in, inl)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return inl;
|
||||
}
|
||||
|
||||
static int mem_gets(BIO *bio, char *buf, int size) {
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The buffer size includes space for the trailing NUL, so we can read at most
|
||||
// one fewer byte.
|
||||
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
|
||||
int ret = size - 1;
|
||||
if ((size_t)ret > b->length) {
|
||||
ret = (int)b->length;
|
||||
}
|
||||
|
||||
// Stop at the first newline.
|
||||
const char *newline =
|
||||
reinterpret_cast<char *>(OPENSSL_memchr(b->data, '\n', ret));
|
||||
if (newline != NULL) {
|
||||
ret = (int)(newline - b->data + 1);
|
||||
}
|
||||
|
||||
ret = mem_read(bio, buf, ret);
|
||||
if (ret >= 0) {
|
||||
buf[ret] = '\0';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
|
||||
BUF_MEM *b = (BUF_MEM *)bio->ptr;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
if (b->data != NULL) {
|
||||
// For read only case reset to the start again
|
||||
if (bio->flags & BIO_FLAGS_MEM_RDONLY) {
|
||||
b->data -= b->max - b->length;
|
||||
b->length = b->max;
|
||||
} else {
|
||||
OPENSSL_memset(b->data, 0, b->max);
|
||||
b->length = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_EOF:
|
||||
ret = (long)(b->length == 0);
|
||||
break;
|
||||
case BIO_C_SET_BUF_MEM_EOF_RETURN:
|
||||
bio->num = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_INFO:
|
||||
ret = (long)b->length;
|
||||
if (ptr != NULL) {
|
||||
char **pptr = reinterpret_cast<char **>(ptr);
|
||||
*pptr = b->data;
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_BUF_MEM:
|
||||
mem_free(bio);
|
||||
bio->shutdown = (int)num;
|
||||
bio->ptr = ptr;
|
||||
break;
|
||||
case BIO_C_GET_BUF_MEM_PTR:
|
||||
if (ptr != NULL) {
|
||||
BUF_MEM **pptr = reinterpret_cast<BUF_MEM **>(ptr);
|
||||
*pptr = b;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = (long)bio->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
bio->shutdown = (int)num;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0L;
|
||||
break;
|
||||
case BIO_CTRL_PENDING:
|
||||
ret = (long)b->length;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const BIO_METHOD mem_method = {
|
||||
BIO_TYPE_MEM, "memory buffer",
|
||||
mem_write, mem_read,
|
||||
NULL /* puts */, mem_gets,
|
||||
mem_ctrl, mem_new,
|
||||
mem_free, NULL /* callback_ctrl */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_mem(void) { return &mem_method; }
|
||||
|
||||
int BIO_mem_contents(const BIO *bio, const uint8_t **out_contents,
|
||||
size_t *out_len) {
|
||||
const BUF_MEM *b;
|
||||
if (bio->method != &mem_method) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = (BUF_MEM *)bio->ptr;
|
||||
*out_contents = (uint8_t *)b->data;
|
||||
*out_len = b->length;
|
||||
return 1;
|
||||
}
|
||||
|
||||
long BIO_get_mem_data(BIO *bio, char **contents) {
|
||||
return BIO_ctrl(bio, BIO_CTRL_INFO, 0, contents);
|
||||
}
|
||||
|
||||
int BIO_get_mem_ptr(BIO *bio, BUF_MEM **out) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_BUF_MEM_PTR, 0, out);
|
||||
}
|
||||
|
||||
int BIO_set_mem_buf(BIO *bio, BUF_MEM *b, int take_ownership) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_BUF_MEM, take_ownership, b);
|
||||
}
|
||||
|
||||
int BIO_set_mem_eof_return(BIO *bio, int eof_value) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_BUF_MEM_EOF_RETURN, eof_value, NULL);
|
||||
}
|
||||
@@ -1,889 +0,0 @@
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../test/file_util.h"
|
||||
#include "../test/test_util.h"
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
using Socket = int;
|
||||
#define INVALID_SOCKET (-1)
|
||||
static int closesocket(int sock) { return close(sock); }
|
||||
static std::string LastSocketError() { return strerror(errno); }
|
||||
static const int kOpenReadOnlyBinary = O_RDONLY;
|
||||
static const int kOpenReadOnlyText = O_RDONLY;
|
||||
#else
|
||||
using Socket = SOCKET;
|
||||
static std::string LastSocketError() {
|
||||
char buf[DECIMAL_SIZE(int) + 1];
|
||||
snprintf(buf, sizeof(buf), "%d", WSAGetLastError());
|
||||
return buf;
|
||||
}
|
||||
static const int kOpenReadOnlyBinary = _O_RDONLY | _O_BINARY;
|
||||
static const int kOpenReadOnlyText = O_RDONLY | _O_TEXT;
|
||||
#endif
|
||||
|
||||
class OwnedSocket {
|
||||
public:
|
||||
OwnedSocket() = default;
|
||||
explicit OwnedSocket(Socket sock) : sock_(sock) {}
|
||||
OwnedSocket(OwnedSocket &&other) { *this = std::move(other); }
|
||||
~OwnedSocket() { reset(); }
|
||||
OwnedSocket &operator=(OwnedSocket &&other) {
|
||||
reset(other.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool is_valid() const { return sock_ != INVALID_SOCKET; }
|
||||
Socket get() const { return sock_; }
|
||||
Socket release() { return std::exchange(sock_, INVALID_SOCKET); }
|
||||
|
||||
void reset(Socket sock = INVALID_SOCKET) {
|
||||
if (is_valid()) {
|
||||
closesocket(sock_);
|
||||
}
|
||||
|
||||
sock_ = sock;
|
||||
}
|
||||
|
||||
private:
|
||||
Socket sock_ = INVALID_SOCKET;
|
||||
};
|
||||
|
||||
struct SockaddrStorage {
|
||||
int family() const { return storage.ss_family; }
|
||||
|
||||
sockaddr *addr_mut() { return reinterpret_cast<sockaddr *>(&storage); }
|
||||
const sockaddr *addr() const {
|
||||
return reinterpret_cast<const sockaddr *>(&storage);
|
||||
}
|
||||
|
||||
sockaddr_in ToIPv4() const {
|
||||
if (family() != AF_INET || len != sizeof(sockaddr_in)) {
|
||||
abort();
|
||||
}
|
||||
// These APIs were seemingly designed before C's strict aliasing rule, and
|
||||
// C++'s strict union handling. Make a copy so the compiler does not read
|
||||
// this as an aliasing violation.
|
||||
sockaddr_in ret;
|
||||
OPENSSL_memcpy(&ret, &storage, sizeof(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
sockaddr_in6 ToIPv6() const {
|
||||
if (family() != AF_INET6 || len != sizeof(sockaddr_in6)) {
|
||||
abort();
|
||||
}
|
||||
// These APIs were seemingly designed before C's strict aliasing rule, and
|
||||
// C++'s strict union handling. Make a copy so the compiler does not read
|
||||
// this as an aliasing violation.
|
||||
sockaddr_in6 ret;
|
||||
OPENSSL_memcpy(&ret, &storage, sizeof(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
sockaddr_storage storage = {};
|
||||
socklen_t len = sizeof(storage);
|
||||
};
|
||||
|
||||
static OwnedSocket Bind(int family, const sockaddr *addr, socklen_t addr_len) {
|
||||
OwnedSocket sock(socket(family, SOCK_STREAM, 0));
|
||||
if (!sock.is_valid()) {
|
||||
return OwnedSocket();
|
||||
}
|
||||
|
||||
if (bind(sock.get(), addr, addr_len) != 0) {
|
||||
return OwnedSocket();
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
static OwnedSocket ListenLoopback(int backlog) {
|
||||
// Try binding to IPv6.
|
||||
sockaddr_in6 sin6;
|
||||
OPENSSL_memset(&sin6, 0, sizeof(sin6));
|
||||
sin6.sin6_family = AF_INET6;
|
||||
if (inet_pton(AF_INET6, "::1", &sin6.sin6_addr) != 1) {
|
||||
return OwnedSocket();
|
||||
}
|
||||
OwnedSocket sock =
|
||||
Bind(AF_INET6, reinterpret_cast<const sockaddr *>(&sin6), sizeof(sin6));
|
||||
if (!sock.is_valid()) {
|
||||
// Try binding to IPv4.
|
||||
sockaddr_in sin;
|
||||
OPENSSL_memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
if (inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr) != 1) {
|
||||
return OwnedSocket();
|
||||
}
|
||||
sock = Bind(AF_INET, reinterpret_cast<const sockaddr *>(&sin), sizeof(sin));
|
||||
}
|
||||
if (!sock.is_valid()) {
|
||||
return OwnedSocket();
|
||||
}
|
||||
|
||||
if (listen(sock.get(), backlog) != 0) {
|
||||
return OwnedSocket();
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
static bool SocketSetNonBlocking(Socket sock) {
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
u_long arg = 1;
|
||||
return ioctlsocket(sock, FIONBIO, &arg) == 0;
|
||||
#else
|
||||
int flags = fcntl(sock, F_GETFL, 0);
|
||||
if (flags < 0) {
|
||||
return false;
|
||||
}
|
||||
flags |= O_NONBLOCK;
|
||||
return fcntl(sock, F_SETFL, flags) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
enum class WaitType { kRead, kWrite };
|
||||
|
||||
static bool WaitForSocket(Socket sock, WaitType wait_type) {
|
||||
// Use an arbitrary 5 second timeout, so the test doesn't hang indefinitely if
|
||||
// there's an issue.
|
||||
static const int kTimeoutSeconds = 5;
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
fd_set read_set, write_set;
|
||||
FD_ZERO(&read_set);
|
||||
FD_ZERO(&write_set);
|
||||
fd_set *wait_set = wait_type == WaitType::kRead ? &read_set : &write_set;
|
||||
FD_SET(sock, wait_set);
|
||||
timeval timeout;
|
||||
timeout.tv_sec = kTimeoutSeconds;
|
||||
timeout.tv_usec = 0;
|
||||
if (select(0 /* unused on Windows */, &read_set, &write_set, nullptr,
|
||||
&timeout) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return FD_ISSET(sock, wait_set);
|
||||
#else
|
||||
short events = wait_type == WaitType::kRead ? POLLIN : POLLOUT;
|
||||
pollfd fd = {/*fd=*/sock, events, /*revents=*/0};
|
||||
return poll(&fd, 1, kTimeoutSeconds * 1000) == 1 && (fd.revents & events);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(BIOTest, SocketConnect) {
|
||||
static const char kTestMessage[] = "test";
|
||||
OwnedSocket listening_sock = ListenLoopback(/*backlog=*/1);
|
||||
ASSERT_TRUE(listening_sock.is_valid()) << LastSocketError();
|
||||
|
||||
SockaddrStorage addr;
|
||||
ASSERT_EQ(getsockname(listening_sock.get(), addr.addr_mut(), &addr.len), 0)
|
||||
<< LastSocketError();
|
||||
|
||||
char hostname[80];
|
||||
if (addr.family() == AF_INET6) {
|
||||
snprintf(hostname, sizeof(hostname), "[::1]:%d",
|
||||
ntohs(addr.ToIPv6().sin6_port));
|
||||
} else {
|
||||
snprintf(hostname, sizeof(hostname), "127.0.0.1:%d",
|
||||
ntohs(addr.ToIPv4().sin_port));
|
||||
}
|
||||
|
||||
// Connect to it with a connect BIO.
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_connect(hostname));
|
||||
ASSERT_TRUE(bio);
|
||||
|
||||
// Write a test message to the BIO. This is assumed to be smaller than the
|
||||
// transport buffer.
|
||||
ASSERT_EQ(static_cast<int>(sizeof(kTestMessage)),
|
||||
BIO_write(bio.get(), kTestMessage, sizeof(kTestMessage)))
|
||||
<< LastSocketError();
|
||||
|
||||
// Accept the socket.
|
||||
OwnedSocket sock(accept(listening_sock.get(), addr.addr_mut(), &addr.len));
|
||||
ASSERT_TRUE(sock.is_valid()) << LastSocketError();
|
||||
|
||||
// Check the same message is read back out.
|
||||
char buf[sizeof(kTestMessage)];
|
||||
ASSERT_EQ(static_cast<int>(sizeof(kTestMessage)),
|
||||
recv(sock.get(), buf, sizeof(buf), 0))
|
||||
<< LastSocketError();
|
||||
EXPECT_EQ(Bytes(kTestMessage, sizeof(kTestMessage)), Bytes(buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
TEST(BIOTest, SocketNonBlocking) {
|
||||
OwnedSocket listening_sock = ListenLoopback(/*backlog=*/1);
|
||||
ASSERT_TRUE(listening_sock.is_valid()) << LastSocketError();
|
||||
|
||||
// Connect to |listening_sock|.
|
||||
SockaddrStorage addr;
|
||||
ASSERT_EQ(getsockname(listening_sock.get(), addr.addr_mut(), &addr.len), 0)
|
||||
<< LastSocketError();
|
||||
OwnedSocket connect_sock(socket(addr.family(), SOCK_STREAM, 0));
|
||||
ASSERT_TRUE(connect_sock.is_valid()) << LastSocketError();
|
||||
ASSERT_EQ(connect(connect_sock.get(), addr.addr(), addr.len), 0)
|
||||
<< LastSocketError();
|
||||
ASSERT_TRUE(SocketSetNonBlocking(connect_sock.get())) << LastSocketError();
|
||||
bssl::UniquePtr<BIO> connect_bio(
|
||||
BIO_new_socket(connect_sock.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(connect_bio);
|
||||
|
||||
// Make a corresponding accepting socket.
|
||||
OwnedSocket accept_sock(
|
||||
accept(listening_sock.get(), addr.addr_mut(), &addr.len));
|
||||
ASSERT_TRUE(accept_sock.is_valid()) << LastSocketError();
|
||||
ASSERT_TRUE(SocketSetNonBlocking(accept_sock.get())) << LastSocketError();
|
||||
bssl::UniquePtr<BIO> accept_bio(
|
||||
BIO_new_socket(accept_sock.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(accept_bio);
|
||||
|
||||
// Exchange data through the socket.
|
||||
static const char kTestMessage[] = "hello, world";
|
||||
|
||||
// Reading from |accept_bio| should not block.
|
||||
char buf[sizeof(kTestMessage)];
|
||||
int ret = BIO_read(accept_bio.get(), buf, sizeof(buf));
|
||||
EXPECT_EQ(ret, -1);
|
||||
EXPECT_TRUE(BIO_should_read(accept_bio.get())) << LastSocketError();
|
||||
|
||||
// Writing to |connect_bio| should eventually overflow the transport buffers
|
||||
// and also give a retryable error.
|
||||
int bytes_written = 0;
|
||||
for (;;) {
|
||||
ret = BIO_write(connect_bio.get(), kTestMessage, sizeof(kTestMessage));
|
||||
if (ret <= 0) {
|
||||
EXPECT_EQ(ret, -1);
|
||||
EXPECT_TRUE(BIO_should_write(connect_bio.get())) << LastSocketError();
|
||||
break;
|
||||
}
|
||||
bytes_written += ret;
|
||||
}
|
||||
EXPECT_GT(bytes_written, 0);
|
||||
|
||||
// |accept_bio| should readable. Drain it. Note data is not always available
|
||||
// from loopback immediately, notably on macOS, so wait for the socket first.
|
||||
int bytes_read = 0;
|
||||
while (bytes_read < bytes_written) {
|
||||
ASSERT_TRUE(WaitForSocket(accept_sock.get(), WaitType::kRead))
|
||||
<< LastSocketError();
|
||||
ret = BIO_read(accept_bio.get(), buf, sizeof(buf));
|
||||
ASSERT_GT(ret, 0);
|
||||
bytes_read += ret;
|
||||
}
|
||||
|
||||
// |connect_bio| should become writeable again.
|
||||
ASSERT_TRUE(WaitForSocket(accept_sock.get(), WaitType::kWrite))
|
||||
<< LastSocketError();
|
||||
ret = BIO_write(connect_bio.get(), kTestMessage, sizeof(kTestMessage));
|
||||
EXPECT_EQ(static_cast<int>(sizeof(kTestMessage)), ret);
|
||||
|
||||
ASSERT_TRUE(WaitForSocket(accept_sock.get(), WaitType::kRead))
|
||||
<< LastSocketError();
|
||||
ret = BIO_read(accept_bio.get(), buf, sizeof(buf));
|
||||
EXPECT_EQ(static_cast<int>(sizeof(kTestMessage)), ret);
|
||||
EXPECT_EQ(Bytes(buf), Bytes(kTestMessage));
|
||||
|
||||
// Close one socket. We should get an EOF out the other.
|
||||
connect_bio.reset();
|
||||
connect_sock.reset();
|
||||
|
||||
ASSERT_TRUE(WaitForSocket(accept_sock.get(), WaitType::kRead))
|
||||
<< LastSocketError();
|
||||
ret = BIO_read(accept_bio.get(), buf, sizeof(buf));
|
||||
EXPECT_EQ(ret, 0) << LastSocketError();
|
||||
EXPECT_FALSE(BIO_should_read(accept_bio.get()));
|
||||
}
|
||||
|
||||
TEST(BIOTest, Printf) {
|
||||
// Test a short output, a very long one, and various sizes around
|
||||
// 256 (the size of the buffer) to ensure edge cases are correct.
|
||||
static const size_t kLengths[] = {5, 250, 251, 252, 253, 254, 1023};
|
||||
|
||||
bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
|
||||
ASSERT_TRUE(bio);
|
||||
|
||||
for (size_t length : kLengths) {
|
||||
SCOPED_TRACE(length);
|
||||
|
||||
std::string in(length, 'a');
|
||||
|
||||
int ret = BIO_printf(bio.get(), "test %s", in.c_str());
|
||||
ASSERT_GE(ret, 0);
|
||||
EXPECT_EQ(5 + length, static_cast<size_t>(ret));
|
||||
|
||||
const uint8_t *contents;
|
||||
size_t len;
|
||||
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
|
||||
EXPECT_EQ("test " + in, bssl::BytesAsStringView(bssl::Span(contents, len)));
|
||||
|
||||
ASSERT_TRUE(BIO_reset(bio.get()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BIOTest, ReadASN1) {
|
||||
static const size_t kLargeASN1PayloadLen = 8000;
|
||||
|
||||
struct ASN1Test {
|
||||
bool should_succeed;
|
||||
std::vector<uint8_t> input;
|
||||
// suffix_len is the number of zeros to append to |input|.
|
||||
size_t suffix_len;
|
||||
// expected_len, if |should_succeed| is true, is the expected length of the
|
||||
// ASN.1 element.
|
||||
size_t expected_len;
|
||||
size_t max_len;
|
||||
} kASN1Tests[] = {
|
||||
{true, {0x30, 2, 1, 2, 0, 0}, 0, 4, 100},
|
||||
{false /* truncated */, {0x30, 3, 1, 2}, 0, 0, 100},
|
||||
{false /* should be short len */, {0x30, 0x81, 1, 1}, 0, 0, 100},
|
||||
{false /* zero padded */, {0x30, 0x82, 0, 1, 1}, 0, 0, 100},
|
||||
|
||||
// Test a large payload.
|
||||
{true,
|
||||
{0x30, 0x82, kLargeASN1PayloadLen >> 8, kLargeASN1PayloadLen & 0xff},
|
||||
kLargeASN1PayloadLen,
|
||||
4 + kLargeASN1PayloadLen,
|
||||
kLargeASN1PayloadLen * 2},
|
||||
{false /* max_len too short */,
|
||||
{0x30, 0x82, kLargeASN1PayloadLen >> 8, kLargeASN1PayloadLen & 0xff},
|
||||
kLargeASN1PayloadLen,
|
||||
4 + kLargeASN1PayloadLen,
|
||||
3 + kLargeASN1PayloadLen},
|
||||
|
||||
// Test an indefinite-length input.
|
||||
{true,
|
||||
{0x30, 0x80},
|
||||
kLargeASN1PayloadLen + 2,
|
||||
2 + kLargeASN1PayloadLen + 2,
|
||||
kLargeASN1PayloadLen * 2},
|
||||
{false /* max_len too short */,
|
||||
{0x30, 0x80},
|
||||
kLargeASN1PayloadLen + 2,
|
||||
2 + kLargeASN1PayloadLen + 2,
|
||||
2 + kLargeASN1PayloadLen + 1},
|
||||
};
|
||||
|
||||
for (const auto &t : kASN1Tests) {
|
||||
std::vector<uint8_t> input = t.input;
|
||||
input.resize(input.size() + t.suffix_len, 0);
|
||||
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(input.data(), input.size()));
|
||||
ASSERT_TRUE(bio);
|
||||
|
||||
uint8_t *out;
|
||||
size_t out_len;
|
||||
int ok = BIO_read_asn1(bio.get(), &out, &out_len, t.max_len);
|
||||
if (!ok) {
|
||||
out = nullptr;
|
||||
}
|
||||
bssl::UniquePtr<uint8_t> out_storage(out);
|
||||
|
||||
ASSERT_EQ(t.should_succeed, (ok == 1));
|
||||
if (t.should_succeed) {
|
||||
EXPECT_EQ(Bytes(input.data(), t.expected_len), Bytes(out, out_len));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BIOTest, MemReadOnly) {
|
||||
// A memory BIO created from |BIO_new_mem_buf| is a read-only buffer.
|
||||
static const char kData[] = "abcdefghijklmno";
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(kData, strlen(kData)));
|
||||
ASSERT_TRUE(bio);
|
||||
|
||||
// Writing to read-only buffers should fail.
|
||||
EXPECT_EQ(BIO_write(bio.get(), kData, strlen(kData)), -1);
|
||||
|
||||
const uint8_t *contents;
|
||||
size_t len;
|
||||
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
|
||||
EXPECT_EQ(Bytes(contents, len), Bytes(kData));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// Read less than the whole buffer.
|
||||
char buf[6];
|
||||
int ret = BIO_read(bio.get(), buf, sizeof(buf));
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("abcdef"));
|
||||
|
||||
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
|
||||
EXPECT_EQ(Bytes(contents, len), Bytes("ghijklmno"));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
ret = BIO_read(bio.get(), buf, sizeof(buf));
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("ghijkl"));
|
||||
|
||||
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
|
||||
EXPECT_EQ(Bytes(contents, len), Bytes("mno"));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// Read the remainder of the buffer.
|
||||
ret = BIO_read(bio.get(), buf, sizeof(buf));
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("mno"));
|
||||
|
||||
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
|
||||
EXPECT_EQ(Bytes(contents, len), Bytes(""));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 1);
|
||||
|
||||
// By default, reading from a consumed read-only buffer returns EOF.
|
||||
EXPECT_EQ(BIO_read(bio.get(), buf, sizeof(buf)), 0);
|
||||
EXPECT_FALSE(BIO_should_read(bio.get()));
|
||||
|
||||
// A memory BIO can be configured to return an error instead of EOF. This is
|
||||
// error is returned as retryable. (This is not especially useful here. It
|
||||
// makes more sense for a writable BIO.)
|
||||
EXPECT_EQ(BIO_set_mem_eof_return(bio.get(), -1), 1);
|
||||
EXPECT_EQ(BIO_read(bio.get(), buf, sizeof(buf)), -1);
|
||||
EXPECT_TRUE(BIO_should_read(bio.get()));
|
||||
|
||||
// Read exactly the right number of bytes, to test the boundary condition is
|
||||
// correct.
|
||||
bio.reset(BIO_new_mem_buf("abc", 3));
|
||||
ASSERT_TRUE(bio);
|
||||
ret = BIO_read(bio.get(), buf, 3);
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("abc"));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 1);
|
||||
}
|
||||
|
||||
TEST(BIOTest, MemWritable) {
|
||||
// A memory BIO created from |BIO_new| is writable.
|
||||
bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
|
||||
ASSERT_TRUE(bio);
|
||||
|
||||
auto check_bio_contents = [&](Bytes b) {
|
||||
const uint8_t *contents;
|
||||
size_t len;
|
||||
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
|
||||
EXPECT_EQ(Bytes(contents, len), b);
|
||||
|
||||
char *contents_c;
|
||||
long len_l = BIO_get_mem_data(bio.get(), &contents_c);
|
||||
ASSERT_GE(len_l, 0);
|
||||
EXPECT_EQ(Bytes(contents_c, len_l), b);
|
||||
|
||||
BUF_MEM *buf;
|
||||
ASSERT_EQ(BIO_get_mem_ptr(bio.get(), &buf), 1);
|
||||
EXPECT_EQ(Bytes(buf->data, buf->length), b);
|
||||
};
|
||||
|
||||
// It is initially empty.
|
||||
check_bio_contents(Bytes(""));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 1);
|
||||
|
||||
// Reading from it should default to returning a retryable error.
|
||||
char buf[32];
|
||||
EXPECT_EQ(BIO_read(bio.get(), buf, sizeof(buf)), -1);
|
||||
EXPECT_TRUE(BIO_should_read(bio.get()));
|
||||
|
||||
// This can be configured to return an EOF.
|
||||
EXPECT_EQ(BIO_set_mem_eof_return(bio.get(), 0), 1);
|
||||
EXPECT_EQ(BIO_read(bio.get(), buf, sizeof(buf)), 0);
|
||||
EXPECT_FALSE(BIO_should_read(bio.get()));
|
||||
|
||||
// Restore the default. A writable memory |BIO| is typically used in this mode
|
||||
// so additional data can be written when exhausted.
|
||||
EXPECT_EQ(BIO_set_mem_eof_return(bio.get(), -1), 1);
|
||||
|
||||
// Writes append to the buffer.
|
||||
ASSERT_EQ(BIO_write(bio.get(), "abcdef", 6), 6);
|
||||
check_bio_contents(Bytes("abcdef"));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// Writes can include embedded NULs.
|
||||
ASSERT_EQ(BIO_write(bio.get(), "\0ghijk", 6), 6);
|
||||
check_bio_contents(Bytes("abcdef\0ghijk", 12));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// Do a partial read.
|
||||
int ret = BIO_read(bio.get(), buf, 4);
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("abcd"));
|
||||
check_bio_contents(Bytes("ef\0ghijk", 8));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// Reads and writes may alternate.
|
||||
ASSERT_EQ(BIO_write(bio.get(), "lmnopq", 6), 6);
|
||||
check_bio_contents(Bytes("ef\0ghijklmnopq", 14));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// Reads may consume embedded NULs.
|
||||
ret = BIO_read(bio.get(), buf, 4);
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("ef\0g", 4));
|
||||
check_bio_contents(Bytes("hijklmnopq"));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 0);
|
||||
|
||||
// The read buffer exceeds the |BIO|, so we consume everything.
|
||||
ret = BIO_read(bio.get(), buf, sizeof(buf));
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("hijklmnopq"));
|
||||
check_bio_contents(Bytes(""));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 1);
|
||||
|
||||
// The |BIO| is now empty.
|
||||
EXPECT_EQ(BIO_read(bio.get(), buf, sizeof(buf)), -1);
|
||||
EXPECT_TRUE(BIO_should_read(bio.get()));
|
||||
|
||||
// Repeat the above, reading exactly the right number of bytes, to test the
|
||||
// boundary condition is correct.
|
||||
ASSERT_EQ(BIO_write(bio.get(), "abc", 3), 3);
|
||||
ret = BIO_read(bio.get(), buf, 3);
|
||||
EXPECT_EQ(Bytes(buf, ret), Bytes("abc"));
|
||||
EXPECT_EQ(BIO_read(bio.get(), buf, sizeof(buf)), -1);
|
||||
EXPECT_TRUE(BIO_should_read(bio.get()));
|
||||
EXPECT_EQ(BIO_eof(bio.get()), 1);
|
||||
}
|
||||
|
||||
TEST(BIOTest, Gets) {
|
||||
const struct {
|
||||
std::string bio;
|
||||
int gets_len;
|
||||
std::string gets_result;
|
||||
} kGetsTests[] = {
|
||||
// BIO_gets should stop at the first newline. If the buffer is too small,
|
||||
// stop there instead. Note the buffer size
|
||||
// includes a trailing NUL.
|
||||
{"123456789\n123456789", 5, "1234"},
|
||||
{"123456789\n123456789", 9, "12345678"},
|
||||
{"123456789\n123456789", 10, "123456789"},
|
||||
{"123456789\n123456789", 11, "123456789\n"},
|
||||
{"123456789\n123456789", 12, "123456789\n"},
|
||||
{"123456789\n123456789", 256, "123456789\n"},
|
||||
|
||||
// If we run out of buffer, read the whole buffer.
|
||||
{"12345", 5, "1234"},
|
||||
{"12345", 6, "12345"},
|
||||
{"12345", 10, "12345"},
|
||||
|
||||
// NUL bytes do not terminate gets.
|
||||
{std::string("abc\0def\nghi", 11), 256, std::string("abc\0def\n", 8)},
|
||||
|
||||
// An output size of one means we cannot read any bytes. Only the trailing
|
||||
// NUL is included.
|
||||
{"12345", 1, ""},
|
||||
|
||||
// Empty line.
|
||||
{"\nabcdef", 256, "\n"},
|
||||
// Empty BIO.
|
||||
{"", 256, ""},
|
||||
};
|
||||
for (const auto &t : kGetsTests) {
|
||||
SCOPED_TRACE(t.bio);
|
||||
SCOPED_TRACE(t.gets_len);
|
||||
|
||||
auto check_bio_gets = [&](BIO *bio) {
|
||||
std::vector<char> buf(t.gets_len, 'a');
|
||||
int ret = BIO_gets(bio, buf.data(), t.gets_len);
|
||||
ASSERT_GE(ret, 0);
|
||||
// |BIO_gets| should write a NUL terminator, not counted in the return
|
||||
// value.
|
||||
EXPECT_EQ(Bytes(buf.data(), ret + 1),
|
||||
Bytes(t.gets_result.data(), t.gets_result.size() + 1));
|
||||
|
||||
// The remaining data should still be in the BIO.
|
||||
buf.resize(t.bio.size() + 1);
|
||||
ret = BIO_read(bio, buf.data(), static_cast<int>(buf.size()));
|
||||
ASSERT_GE(ret, 0);
|
||||
EXPECT_EQ(Bytes(buf.data(), ret),
|
||||
Bytes(t.bio.substr(t.gets_result.size())));
|
||||
};
|
||||
|
||||
{
|
||||
SCOPED_TRACE("memory");
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(t.bio.data(), t.bio.size()));
|
||||
ASSERT_TRUE(bio);
|
||||
check_bio_gets(bio.get());
|
||||
}
|
||||
|
||||
if (!bssl::SkipTempFileTests()) {
|
||||
bssl::TemporaryFile file;
|
||||
ASSERT_TRUE(file.Init(t.bio));
|
||||
|
||||
// TODO(crbug.com/boringssl/585): If the line has an embedded NUL, file
|
||||
// BIOs do not currently report the answer correctly.
|
||||
if (t.bio.find('\0') == std::string::npos) {
|
||||
SCOPED_TRACE("file");
|
||||
|
||||
// Test |BIO_new_file|.
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_file(file.path().c_str(), "rb"));
|
||||
ASSERT_TRUE(bio);
|
||||
check_bio_gets(bio.get());
|
||||
|
||||
// Test |BIO_read_filename|.
|
||||
bio.reset(BIO_new(BIO_s_file()));
|
||||
ASSERT_TRUE(bio);
|
||||
ASSERT_TRUE(BIO_read_filename(bio.get(), file.path().c_str()));
|
||||
check_bio_gets(bio.get());
|
||||
|
||||
// Test |BIO_NOCLOSE|.
|
||||
bssl::ScopedFILE file_obj = file.Open("rb");
|
||||
ASSERT_TRUE(file_obj);
|
||||
bio.reset(BIO_new_fp(file_obj.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
check_bio_gets(bio.get());
|
||||
|
||||
// Test |BIO_CLOSE|.
|
||||
file_obj = file.Open("rb");
|
||||
ASSERT_TRUE(file_obj);
|
||||
bio.reset(BIO_new_fp(file_obj.get(), BIO_CLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
file_obj.release(); // |BIO_new_fp| took ownership on success.
|
||||
check_bio_gets(bio.get());
|
||||
}
|
||||
|
||||
{
|
||||
SCOPED_TRACE("fd");
|
||||
|
||||
// Test |BIO_NOCLOSE|.
|
||||
bssl::ScopedFD fd = file.OpenFD(kOpenReadOnlyBinary);
|
||||
ASSERT_TRUE(fd.is_valid());
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_fd(fd.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
check_bio_gets(bio.get());
|
||||
|
||||
// Test |BIO_CLOSE|.
|
||||
fd = file.OpenFD(kOpenReadOnlyBinary);
|
||||
ASSERT_TRUE(fd.is_valid());
|
||||
bio.reset(BIO_new_fd(fd.get(), BIO_CLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
fd.release(); // |BIO_new_fd| took ownership on success.
|
||||
check_bio_gets(bio.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Negative and zero lengths should not output anything, even a trailing NUL.
|
||||
bssl::UniquePtr<BIO> bio(BIO_new_mem_buf("12345", -1));
|
||||
ASSERT_TRUE(bio);
|
||||
char c = 'a';
|
||||
EXPECT_EQ(0, BIO_gets(bio.get(), &c, -1));
|
||||
EXPECT_EQ(0, BIO_gets(bio.get(), &c, 0));
|
||||
EXPECT_EQ(c, 'a');
|
||||
}
|
||||
|
||||
// Test that, on Windows, file BIOs correctly handle text vs binary mode.
|
||||
TEST(BIOTest, FileMode) {
|
||||
if (bssl::SkipTempFileTests()) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
bssl::TemporaryFile temp;
|
||||
ASSERT_TRUE(temp.Init("hello\r\nworld"));
|
||||
|
||||
auto expect_file_contents = [](BIO *bio, const std::string &str) {
|
||||
// Read more than expected, to make sure we've reached the end of the file.
|
||||
std::vector<char> buf(str.size() + 100);
|
||||
int len = BIO_read(bio, buf.data(), static_cast<int>(buf.size()));
|
||||
ASSERT_GT(len, 0);
|
||||
EXPECT_EQ(Bytes(buf.data(), len), Bytes(str));
|
||||
};
|
||||
auto expect_binary_mode = [&](BIO *bio) {
|
||||
expect_file_contents(bio, "hello\r\nworld");
|
||||
};
|
||||
auto expect_text_mode = [&](BIO *bio) {
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
expect_file_contents(bio, "hello\nworld");
|
||||
#else
|
||||
expect_file_contents(bio, "hello\r\nworld");
|
||||
#endif
|
||||
};
|
||||
|
||||
// |BIO_read_filename| should open in binary mode.
|
||||
bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_file()));
|
||||
ASSERT_TRUE(bio);
|
||||
ASSERT_TRUE(BIO_read_filename(bio.get(), temp.path().c_str()));
|
||||
expect_binary_mode(bio.get());
|
||||
|
||||
// |BIO_new_file| should use the specified mode.
|
||||
bio.reset(BIO_new_file(temp.path().c_str(), "rb"));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_binary_mode(bio.get());
|
||||
|
||||
bio.reset(BIO_new_file(temp.path().c_str(), "r"));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_text_mode(bio.get());
|
||||
|
||||
// |BIO_new_fp| inherits the file's existing mode by default.
|
||||
bssl::ScopedFILE file = temp.Open("rb");
|
||||
ASSERT_TRUE(file);
|
||||
bio.reset(BIO_new_fp(file.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_binary_mode(bio.get());
|
||||
|
||||
file = temp.Open("r");
|
||||
ASSERT_TRUE(file);
|
||||
bio.reset(BIO_new_fp(file.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_text_mode(bio.get());
|
||||
|
||||
// However, |BIO_FP_TEXT| changes the file to be text mode, no matter how it
|
||||
// was opened.
|
||||
file = temp.Open("rb");
|
||||
ASSERT_TRUE(file);
|
||||
bio.reset(BIO_new_fp(file.get(), BIO_NOCLOSE | BIO_FP_TEXT));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_text_mode(bio.get());
|
||||
|
||||
file = temp.Open("r");
|
||||
ASSERT_TRUE(file);
|
||||
bio.reset(BIO_new_fp(file.get(), BIO_NOCLOSE | BIO_FP_TEXT));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_text_mode(bio.get());
|
||||
|
||||
// |BIO_new_fd| inherits the FD's existing mode.
|
||||
bssl::ScopedFD fd = temp.OpenFD(kOpenReadOnlyBinary);
|
||||
ASSERT_TRUE(fd.is_valid());
|
||||
bio.reset(BIO_new_fd(fd.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_binary_mode(bio.get());
|
||||
|
||||
fd = temp.OpenFD(kOpenReadOnlyText);
|
||||
ASSERT_TRUE(fd.is_valid());
|
||||
bio.reset(BIO_new_fd(fd.get(), BIO_NOCLOSE));
|
||||
ASSERT_TRUE(bio);
|
||||
expect_text_mode(bio.get());
|
||||
}
|
||||
|
||||
// Run through the tests twice, swapping |bio1| and |bio2|, for symmetry.
|
||||
class BIOPairTest : public testing::TestWithParam<bool> {};
|
||||
|
||||
TEST_P(BIOPairTest, TestPair) {
|
||||
BIO *bio1, *bio2;
|
||||
ASSERT_TRUE(BIO_new_bio_pair(&bio1, 10, &bio2, 10));
|
||||
bssl::UniquePtr<BIO> free_bio1(bio1), free_bio2(bio2);
|
||||
|
||||
if (GetParam()) {
|
||||
std::swap(bio1, bio2);
|
||||
}
|
||||
|
||||
// Check initial states.
|
||||
EXPECT_EQ(10u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
EXPECT_EQ(0u, BIO_ctrl_get_read_request(bio1));
|
||||
|
||||
// Data written in one end may be read out the other.
|
||||
uint8_t buf[20];
|
||||
EXPECT_EQ(5, BIO_write(bio1, "12345", 5));
|
||||
EXPECT_EQ(5u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
ASSERT_EQ(5, BIO_read(bio2, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("12345"), Bytes(buf, 5));
|
||||
EXPECT_EQ(10u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
|
||||
// Attempting to write more than 10 bytes will write partially.
|
||||
EXPECT_EQ(10, BIO_write(bio1, "1234567890___", 13));
|
||||
EXPECT_EQ(0u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
EXPECT_EQ(-1, BIO_write(bio1, "z", 1));
|
||||
EXPECT_TRUE(BIO_should_write(bio1));
|
||||
ASSERT_EQ(10, BIO_read(bio2, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("1234567890"), Bytes(buf, 10));
|
||||
EXPECT_EQ(10u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
|
||||
// Unsuccessful reads update the read request.
|
||||
EXPECT_EQ(-1, BIO_read(bio2, buf, 5));
|
||||
EXPECT_TRUE(BIO_should_read(bio2));
|
||||
EXPECT_EQ(5u, BIO_ctrl_get_read_request(bio1));
|
||||
|
||||
// The read request is clamped to the size of the buffer.
|
||||
EXPECT_EQ(-1, BIO_read(bio2, buf, 20));
|
||||
EXPECT_TRUE(BIO_should_read(bio2));
|
||||
EXPECT_EQ(10u, BIO_ctrl_get_read_request(bio1));
|
||||
|
||||
// Data may be written and read in chunks.
|
||||
EXPECT_EQ(5, BIO_write(bio1, "12345", 5));
|
||||
EXPECT_EQ(5u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
EXPECT_EQ(5, BIO_write(bio1, "67890___", 8));
|
||||
EXPECT_EQ(0u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
ASSERT_EQ(3, BIO_read(bio2, buf, 3));
|
||||
EXPECT_EQ(Bytes("123"), Bytes(buf, 3));
|
||||
EXPECT_EQ(3u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
ASSERT_EQ(7, BIO_read(bio2, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("4567890"), Bytes(buf, 7));
|
||||
EXPECT_EQ(10u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
|
||||
// Successful reads reset the read request.
|
||||
EXPECT_EQ(0u, BIO_ctrl_get_read_request(bio1));
|
||||
|
||||
// Test writes and reads starting in the middle of the ring buffer and
|
||||
// wrapping to front.
|
||||
EXPECT_EQ(8, BIO_write(bio1, "abcdefgh", 8));
|
||||
EXPECT_EQ(2u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
ASSERT_EQ(3, BIO_read(bio2, buf, 3));
|
||||
EXPECT_EQ(Bytes("abc"), Bytes(buf, 3));
|
||||
EXPECT_EQ(5u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
EXPECT_EQ(5, BIO_write(bio1, "ijklm___", 8));
|
||||
EXPECT_EQ(0u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
ASSERT_EQ(10, BIO_read(bio2, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("defghijklm"), Bytes(buf, 10));
|
||||
EXPECT_EQ(10u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
|
||||
// Data may flow from both ends in parallel.
|
||||
EXPECT_EQ(5, BIO_write(bio1, "12345", 5));
|
||||
EXPECT_EQ(5, BIO_write(bio2, "67890", 5));
|
||||
ASSERT_EQ(5, BIO_read(bio2, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("12345"), Bytes(buf, 5));
|
||||
ASSERT_EQ(5, BIO_read(bio1, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("67890"), Bytes(buf, 5));
|
||||
|
||||
// Closing the write end causes an EOF on the read half, after draining.
|
||||
EXPECT_EQ(5, BIO_write(bio1, "12345", 5));
|
||||
EXPECT_TRUE(BIO_shutdown_wr(bio1));
|
||||
ASSERT_EQ(5, BIO_read(bio2, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("12345"), Bytes(buf, 5));
|
||||
EXPECT_EQ(0, BIO_read(bio2, buf, sizeof(buf)));
|
||||
|
||||
// A closed write end may not be written to.
|
||||
EXPECT_EQ(0u, BIO_ctrl_get_write_guarantee(bio1));
|
||||
EXPECT_EQ(-1, BIO_write(bio1, "_____", 5));
|
||||
EXPECT_TRUE(ErrorEquals(ERR_get_error(), ERR_LIB_BIO, BIO_R_BROKEN_PIPE));
|
||||
|
||||
// The other end is still functional.
|
||||
EXPECT_EQ(5, BIO_write(bio2, "12345", 5));
|
||||
ASSERT_EQ(5, BIO_read(bio1, buf, sizeof(buf)));
|
||||
EXPECT_EQ(Bytes("12345"), Bytes(buf, 5));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(All, BIOPairTest, testing::Values(false, true));
|
||||
|
||||
} // namespace
|
||||
@@ -1,509 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
enum {
|
||||
BIO_CONN_S_BEFORE,
|
||||
BIO_CONN_S_BLOCKED_CONNECT,
|
||||
BIO_CONN_S_OK,
|
||||
};
|
||||
|
||||
namespace {
|
||||
typedef struct bio_connect_st {
|
||||
int state;
|
||||
|
||||
char *param_hostname;
|
||||
char *param_port;
|
||||
int nbio;
|
||||
|
||||
unsigned short port;
|
||||
|
||||
struct sockaddr_storage them;
|
||||
socklen_t them_length;
|
||||
|
||||
// the file descriptor is kept in bio->num in order to match the socket
|
||||
// BIO.
|
||||
|
||||
// info_callback is called when the connection is initially made
|
||||
// callback(BIO,state,ret); The callback should return 'ret', state is for
|
||||
// compatibility with the SSL info_callback.
|
||||
int (*info_callback)(const BIO *bio, int state, int ret);
|
||||
} BIO_CONNECT;
|
||||
} // namespace
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
static int closesocket(int sock) { return close(sock); }
|
||||
#endif
|
||||
|
||||
// split_host_and_port sets |*out_host| and |*out_port| to the host and port
|
||||
// parsed from |name|. It returns one on success or zero on error. Even when
|
||||
// successful, |*out_port| may be NULL on return if no port was specified.
|
||||
static int split_host_and_port(char **out_host, char **out_port,
|
||||
const char *name) {
|
||||
const char *host, *port = NULL;
|
||||
size_t host_len = 0;
|
||||
|
||||
*out_host = NULL;
|
||||
*out_port = NULL;
|
||||
|
||||
if (name[0] == '[') { // bracketed IPv6 address
|
||||
const char *close = strchr(name, ']');
|
||||
if (close == NULL) {
|
||||
return 0;
|
||||
}
|
||||
host = name + 1;
|
||||
host_len = close - host;
|
||||
if (close[1] == ':') { // [IP]:port
|
||||
port = close + 2;
|
||||
} else if (close[1] != 0) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
const char *colon = strchr(name, ':');
|
||||
if (colon == NULL || strchr(colon + 1, ':') != NULL) { // IPv6 address
|
||||
host = name;
|
||||
host_len = strlen(name);
|
||||
} else { // host:port
|
||||
host = name;
|
||||
host_len = colon - name;
|
||||
port = colon + 1;
|
||||
}
|
||||
}
|
||||
|
||||
*out_host = OPENSSL_strndup(host, host_len);
|
||||
if (*out_host == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (port == NULL) {
|
||||
*out_port = NULL;
|
||||
return 1;
|
||||
}
|
||||
*out_port = OPENSSL_strdup(port);
|
||||
if (*out_port == NULL) {
|
||||
OPENSSL_free(*out_host);
|
||||
*out_host = NULL;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int conn_state(BIO *bio, BIO_CONNECT *c) {
|
||||
int ret = -1, i;
|
||||
int (*cb)(const BIO *, int, int) = NULL;
|
||||
|
||||
if (c->info_callback != NULL) {
|
||||
cb = c->info_callback;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
switch (c->state) {
|
||||
case BIO_CONN_S_BEFORE:
|
||||
// If there's a hostname and a port, assume that both are
|
||||
// exactly what they say. If there is only a hostname, try
|
||||
// (just once) to split it into a hostname and port.
|
||||
|
||||
if (c->param_hostname == NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_NO_HOSTNAME_SPECIFIED);
|
||||
goto exit_loop;
|
||||
}
|
||||
|
||||
if (c->param_port == NULL) {
|
||||
char *host, *port;
|
||||
if (!split_host_and_port(&host, &port, c->param_hostname) ||
|
||||
port == NULL) {
|
||||
OPENSSL_free(host);
|
||||
OPENSSL_free(port);
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_NO_PORT_SPECIFIED);
|
||||
ERR_add_error_data(2, "host=", c->param_hostname);
|
||||
goto exit_loop;
|
||||
}
|
||||
|
||||
OPENSSL_free(c->param_port);
|
||||
c->param_port = port;
|
||||
OPENSSL_free(c->param_hostname);
|
||||
c->param_hostname = host;
|
||||
}
|
||||
|
||||
if (!bio_ip_and_port_to_socket_and_addr(
|
||||
&bio->num, &c->them, &c->them_length, c->param_hostname,
|
||||
c->param_port)) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_UNABLE_TO_CREATE_SOCKET);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":", c->param_port);
|
||||
goto exit_loop;
|
||||
}
|
||||
|
||||
if (c->nbio) {
|
||||
if (!bio_socket_nbio(bio->num, 1)) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_ERROR_SETTING_NBIO);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":",
|
||||
c->param_port);
|
||||
goto exit_loop;
|
||||
}
|
||||
}
|
||||
|
||||
i = 1;
|
||||
ret = setsockopt(bio->num, SOL_SOCKET, SO_KEEPALIVE, (char *)&i,
|
||||
sizeof(i));
|
||||
if (ret < 0) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_KEEPALIVE);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":", c->param_port);
|
||||
goto exit_loop;
|
||||
}
|
||||
|
||||
BIO_clear_retry_flags(bio);
|
||||
ret = connect(bio->num, (struct sockaddr *)&c->them, c->them_length);
|
||||
if (ret < 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_flags(bio, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY));
|
||||
c->state = BIO_CONN_S_BLOCKED_CONNECT;
|
||||
bio->retry_reason = BIO_RR_CONNECT;
|
||||
} else {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_CONNECT_ERROR);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":",
|
||||
c->param_port);
|
||||
}
|
||||
goto exit_loop;
|
||||
} else {
|
||||
c->state = BIO_CONN_S_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_CONN_S_BLOCKED_CONNECT:
|
||||
i = bio_sock_error(bio->num);
|
||||
if (i) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_flags(bio, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY));
|
||||
c->state = BIO_CONN_S_BLOCKED_CONNECT;
|
||||
bio->retry_reason = BIO_RR_CONNECT;
|
||||
ret = -1;
|
||||
} else {
|
||||
BIO_clear_retry_flags(bio);
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_NBIO_CONNECT_ERROR);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":",
|
||||
c->param_port);
|
||||
ret = 0;
|
||||
}
|
||||
goto exit_loop;
|
||||
} else {
|
||||
c->state = BIO_CONN_S_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_CONN_S_OK:
|
||||
ret = 1;
|
||||
goto exit_loop;
|
||||
default:
|
||||
assert(0);
|
||||
goto exit_loop;
|
||||
}
|
||||
|
||||
if (cb != NULL) {
|
||||
ret = cb((BIO *)bio, c->state, ret);
|
||||
if (ret == 0) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit_loop:
|
||||
if (cb != NULL) {
|
||||
ret = cb((BIO *)bio, c->state, ret);
|
||||
}
|
||||
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BIO_CONNECT *BIO_CONNECT_new(void) {
|
||||
BIO_CONNECT *ret =
|
||||
reinterpret_cast<BIO_CONNECT *>(OPENSSL_zalloc(sizeof(BIO_CONNECT)));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret->state = BIO_CONN_S_BEFORE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void BIO_CONNECT_free(BIO_CONNECT *c) {
|
||||
if (c == nullptr) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(c->param_hostname);
|
||||
OPENSSL_free(c->param_port);
|
||||
OPENSSL_free(c);
|
||||
}
|
||||
|
||||
static int conn_new(BIO *bio) {
|
||||
bio->init = 0;
|
||||
bio->num = -1;
|
||||
bio->flags = 0;
|
||||
bio->ptr = BIO_CONNECT_new();
|
||||
return bio->ptr != NULL;
|
||||
}
|
||||
|
||||
static void conn_close_socket(BIO *bio) {
|
||||
BIO_CONNECT *c = (BIO_CONNECT *)bio->ptr;
|
||||
|
||||
if (bio->num == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only do a shutdown if things were established
|
||||
if (c->state == BIO_CONN_S_OK) {
|
||||
shutdown(bio->num, 2);
|
||||
}
|
||||
closesocket(bio->num);
|
||||
bio->num = -1;
|
||||
}
|
||||
|
||||
static int conn_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
conn_close_socket(bio);
|
||||
}
|
||||
|
||||
BIO_CONNECT_free((BIO_CONNECT *)bio->ptr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int conn_read(BIO *bio, char *out, int out_len) {
|
||||
int ret = 0;
|
||||
BIO_CONNECT *data;
|
||||
|
||||
data = (BIO_CONNECT *)bio->ptr;
|
||||
if (data->state != BIO_CONN_S_OK) {
|
||||
ret = conn_state(bio, data);
|
||||
if (ret <= 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
bio_clear_socket_error();
|
||||
ret = (int)recv(bio->num, out, out_len, 0);
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_read(bio);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int conn_write(BIO *bio, const char *in, int in_len) {
|
||||
int ret;
|
||||
BIO_CONNECT *data;
|
||||
|
||||
data = (BIO_CONNECT *)bio->ptr;
|
||||
if (data->state != BIO_CONN_S_OK) {
|
||||
ret = conn_state(bio, data);
|
||||
if (ret <= 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
bio_clear_socket_error();
|
||||
ret = (int)send(bio->num, in, in_len, 0);
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_write(bio);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long conn_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
int *ip;
|
||||
long ret = 1;
|
||||
BIO_CONNECT *data;
|
||||
|
||||
data = (BIO_CONNECT *)bio->ptr;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
ret = 0;
|
||||
data->state = BIO_CONN_S_BEFORE;
|
||||
conn_close_socket(bio);
|
||||
bio->flags = 0;
|
||||
break;
|
||||
case BIO_C_DO_STATE_MACHINE:
|
||||
// use this one to start the connection
|
||||
if (data->state != BIO_CONN_S_OK) {
|
||||
ret = (long)conn_state(bio, data);
|
||||
} else {
|
||||
ret = 1;
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_CONNECT:
|
||||
if (ptr != NULL) {
|
||||
bio->init = 1;
|
||||
if (num == 0) {
|
||||
OPENSSL_free(data->param_hostname);
|
||||
data->param_hostname =
|
||||
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
|
||||
if (data->param_hostname == NULL) {
|
||||
ret = 0;
|
||||
}
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_port);
|
||||
data->param_port =
|
||||
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
|
||||
if (data->param_port == NULL) {
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_NBIO:
|
||||
data->nbio = (int)num;
|
||||
break;
|
||||
case BIO_C_GET_FD:
|
||||
if (bio->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = bio->num;
|
||||
}
|
||||
ret = bio->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = bio->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
bio->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_PENDING:
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
break;
|
||||
case BIO_CTRL_GET_CALLBACK: {
|
||||
int (**fptr)(const BIO *bio, int state, int xret);
|
||||
fptr = reinterpret_cast<decltype(fptr)>(ptr);
|
||||
*fptr = data->info_callback;
|
||||
} break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long conn_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
|
||||
long ret = 1;
|
||||
BIO_CONNECT *data;
|
||||
|
||||
data = (BIO_CONNECT *)bio->ptr;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_SET_CALLBACK:
|
||||
// This is the actual type signature of |fp|. The caller is expected to
|
||||
// cast it to |bio_info_cb| due to the |BIO_callback_ctrl| calling
|
||||
// convention.
|
||||
OPENSSL_MSVC_PRAGMA(warning(push))
|
||||
OPENSSL_MSVC_PRAGMA(warning(disable : 4191))
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic push")
|
||||
OPENSSL_CLANG_PRAGMA(
|
||||
"clang diagnostic ignored \"-Wunknown-warning-option\"")
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wcast-function-type\"")
|
||||
data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic pop")
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO *BIO_new_connect(const char *hostname) {
|
||||
BIO *ret;
|
||||
|
||||
ret = BIO_new(BIO_s_connect());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!BIO_set_conn_hostname(ret, hostname)) {
|
||||
BIO_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_connectp = {
|
||||
BIO_TYPE_CONNECT, "socket connect", conn_write, conn_read,
|
||||
NULL /* puts */, NULL /* gets */, conn_ctrl, conn_new,
|
||||
conn_free, conn_callback_ctrl,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_connect(void) { return &methods_connectp; }
|
||||
|
||||
int BIO_set_conn_hostname(BIO *bio, const char *name) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 0, (void *)name);
|
||||
}
|
||||
|
||||
int BIO_set_conn_port(BIO *bio, const char *port_str) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 1, (void *)port_str);
|
||||
}
|
||||
|
||||
int BIO_set_conn_int_port(BIO *bio, const int *port) {
|
||||
char buf[DECIMAL_SIZE(int) + 1];
|
||||
snprintf(buf, sizeof(buf), "%d", *port);
|
||||
return BIO_set_conn_port(bio, buf);
|
||||
}
|
||||
|
||||
int BIO_set_nbio(BIO *bio, int on) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_NBIO, on, NULL);
|
||||
}
|
||||
|
||||
int BIO_do_connect(BIO *bio) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_DO_STATE_MACHINE, 0, NULL);
|
||||
}
|
||||
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int bio_errno_should_retry(int return_value) {
|
||||
if (return_value != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return
|
||||
#ifdef EWOULDBLOCK
|
||||
errno == EWOULDBLOCK ||
|
||||
#endif
|
||||
#ifdef ENOTCONN
|
||||
errno == ENOTCONN ||
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
errno == EINTR ||
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
errno == EAGAIN ||
|
||||
#endif
|
||||
#ifdef EPROTO
|
||||
errno == EPROTO ||
|
||||
#endif
|
||||
#ifdef EINPROGRESS
|
||||
errno == EINPROGRESS ||
|
||||
#endif
|
||||
#ifdef EALREADY
|
||||
errno == EALREADY ||
|
||||
#endif
|
||||
0;
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_POSIX_IO)
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#define BORINGSSL_CLOSE _close
|
||||
#define BORINGSSL_LSEEK _lseek
|
||||
#define BORINGSSL_READ _read
|
||||
#define BORINGSSL_WRITE _write
|
||||
#else
|
||||
#define BORINGSSL_CLOSE close
|
||||
#define BORINGSSL_LSEEK lseek
|
||||
#define BORINGSSL_READ read
|
||||
#define BORINGSSL_WRITE write
|
||||
#endif
|
||||
|
||||
BIO *BIO_new_fd(int fd, int close_flag) {
|
||||
BIO *ret = BIO_new(BIO_s_fd());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fd(ret, fd, close_flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_new(BIO *bio) {
|
||||
// num is used to store the file descriptor.
|
||||
bio->num = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fd_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
BORINGSSL_CLOSE(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fd_read(BIO *b, char *out, int outl) {
|
||||
int ret = 0;
|
||||
|
||||
ret = (int)BORINGSSL_READ(b->num, out, outl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_write(BIO *b, const char *in, int inl) {
|
||||
int ret = (int)BORINGSSL_WRITE(b->num, in, inl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
int *ip;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
num = 0;
|
||||
[[fallthrough]];
|
||||
case BIO_C_FILE_SEEK:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, num, SEEK_SET);
|
||||
}
|
||||
break;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, 0, SEEK_CUR);
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_FD:
|
||||
fd_free(b);
|
||||
b->num = *((int *)ptr);
|
||||
b->shutdown = (int)num;
|
||||
b->init = 1;
|
||||
break;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = b->num;
|
||||
}
|
||||
return b->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = b->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_PENDING:
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_gets(BIO *bp, char *buf, int size) {
|
||||
if (size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *ptr = buf;
|
||||
char *end = buf + size - 1;
|
||||
while (ptr < end && fd_read(bp, ptr, 1) > 0) {
|
||||
char c = ptr[0];
|
||||
ptr++;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ptr[0] = '\0';
|
||||
|
||||
// The output length is bounded by |size|.
|
||||
return (int)(ptr - buf);
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_fdp = {
|
||||
BIO_TYPE_FD, "file descriptor", fd_write, fd_read, NULL /* puts */,
|
||||
fd_gets, fd_ctrl, fd_new, fd_free, NULL /* callback_ctrl */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_fd(void) { return &methods_fdp; }
|
||||
|
||||
#endif // OPENSSL_NO_POSIX_IO
|
||||
|
||||
int BIO_set_fd(BIO *bio, int fd, int close_flag) {
|
||||
return (int)BIO_int_ctrl(bio, BIO_C_SET_FD, close_flag, fd);
|
||||
}
|
||||
|
||||
int BIO_get_fd(BIO *bio, int *out_fd) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FD, 0, (char *) out_fd);
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(__linux) || defined(__sun) || defined(__hpux)
|
||||
// Following definition aliases fopen to fopen64 on above mentioned
|
||||
// platforms. This makes it possible to open and sequentially access
|
||||
// files larger than 2GB from 32-bit application. It does not allow to
|
||||
// traverse them beyond 2GB with fseek/ftell, but on the other hand *no*
|
||||
// 32-bit platform permits that, not with fseek/ftell. Not to mention
|
||||
// that breaking 2GB limit for seeking would require surgery to *our*
|
||||
// API. But sequential access suffices for practical cases when you
|
||||
// can run into large files, such as fingerprinting, so we can let API
|
||||
// alone. For reference, the list of 32-bit platforms which allow for
|
||||
// sequential access of large files without extra "magic" comprise *BSD,
|
||||
// Darwin, IRIX...
|
||||
#ifndef _FILE_OFFSET_BITS
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#define BIO_FP_READ 0x02
|
||||
#define BIO_FP_WRITE 0x04
|
||||
#define BIO_FP_APPEND 0x08
|
||||
|
||||
#if !defined(OPENSSL_NO_FILESYSTEM)
|
||||
#define fopen_if_available fopen
|
||||
#else
|
||||
static FILE *fopen_if_available(const char *path, const char *mode) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
BIO *BIO_new_file(const char *filename, const char *mode) {
|
||||
BIO *ret;
|
||||
FILE *file;
|
||||
|
||||
file = fopen_if_available(filename, mode);
|
||||
if (file == NULL) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
|
||||
ERR_add_error_data(5, "fopen('", filename, "','", mode, "')");
|
||||
if (errno == ENOENT) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_NO_SUCH_FILE);
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_SYS_LIB);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = BIO_new_fp(file, BIO_CLOSE);
|
||||
if (ret == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO *BIO_new_fp(FILE *stream, int flags) {
|
||||
BIO *ret = BIO_new(BIO_s_file());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO_set_fp(ret, stream, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int file_free(BIO *bio) {
|
||||
if (!bio->shutdown) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (bio->init && bio->ptr != NULL) {
|
||||
fclose(reinterpret_cast<FILE *>(bio->ptr));
|
||||
bio->ptr = NULL;
|
||||
}
|
||||
bio->init = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int file_read(BIO *b, char *out, int outl) {
|
||||
if (!b->init) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ret = fread(out, 1, outl, (FILE *)b->ptr);
|
||||
if (ret == 0 && ferror((FILE *)b->ptr)) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// fread reads at most |outl| bytes, so |ret| fits in an int.
|
||||
return (int)ret;
|
||||
}
|
||||
|
||||
static int file_write(BIO *b, const char *in, int inl) {
|
||||
if (!b->init) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = (int)fwrite(in, inl, 1, (FILE *)b->ptr);
|
||||
if (ret > 0) {
|
||||
ret = inl;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
FILE *fp = (FILE *)b->ptr;
|
||||
FILE **fpp;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
num = 0;
|
||||
[[fallthrough]];
|
||||
case BIO_C_FILE_SEEK:
|
||||
ret = (long)fseek(fp, num, 0);
|
||||
break;
|
||||
case BIO_CTRL_EOF:
|
||||
ret = (long)feof(fp);
|
||||
break;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = ftell(fp);
|
||||
break;
|
||||
case BIO_C_SET_FILE_PTR:
|
||||
file_free(b);
|
||||
static_assert((BIO_CLOSE & BIO_FP_TEXT) == 0,
|
||||
"BIO_CLOSE and BIO_FP_TEXT must not collide");
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
// If |BIO_FP_TEXT| is not set, OpenSSL will switch the file to binary
|
||||
// mode. BoringSSL intentionally diverges here because it means code
|
||||
// tested under POSIX will inadvertently change the state of |FILE|
|
||||
// objects when wrapping them in a |BIO|.
|
||||
if (num & BIO_FP_TEXT) {
|
||||
_setmode(_fileno(reinterpret_cast<FILE *>(ptr)), _O_TEXT);
|
||||
}
|
||||
#endif
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
b->ptr = ptr;
|
||||
b->init = 1;
|
||||
break;
|
||||
case BIO_C_SET_FILENAME:
|
||||
file_free(b);
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
const char *mode;
|
||||
if (num & BIO_FP_APPEND) {
|
||||
if (num & BIO_FP_READ) {
|
||||
mode = "ab+";
|
||||
} else {
|
||||
mode = "ab";
|
||||
}
|
||||
} else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) {
|
||||
mode = "rb+";
|
||||
} else if (num & BIO_FP_WRITE) {
|
||||
mode = "wb";
|
||||
} else if (num & BIO_FP_READ) {
|
||||
mode = "rb";
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
fp = fopen_if_available(reinterpret_cast<const char *>(ptr), mode);
|
||||
if (fp == NULL) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
ERR_add_error_data(5, "fopen('", ptr, "','", mode, "')");
|
||||
OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
b->ptr = fp;
|
||||
b->init = 1;
|
||||
break;
|
||||
case BIO_C_GET_FILE_PTR:
|
||||
// the ptr parameter is actually a FILE ** in this case.
|
||||
if (ptr != NULL) {
|
||||
fpp = (FILE **)ptr;
|
||||
*fpp = (FILE *)b->ptr;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = (long)b->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 0 == fflush((FILE *)b->ptr);
|
||||
break;
|
||||
case BIO_CTRL_WPENDING:
|
||||
case BIO_CTRL_PENDING:
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int file_gets(BIO *bp, char *buf, int size) {
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!fgets(buf, size, (FILE *)bp->ptr)) {
|
||||
buf[0] = 0;
|
||||
// TODO(davidben): This doesn't distinguish error and EOF. This should check
|
||||
// |ferror| as in |file_read|.
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int)strlen(buf);
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_filep = {
|
||||
BIO_TYPE_FILE, "FILE pointer",
|
||||
file_write, file_read,
|
||||
NULL /* puts */, file_gets,
|
||||
file_ctrl, NULL /* create */,
|
||||
file_free, NULL /* callback_ctrl */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_file(void) { return &methods_filep; }
|
||||
|
||||
|
||||
int BIO_get_fp(BIO *bio, FILE **out_file) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FILE_PTR, 0, (char *)out_file);
|
||||
}
|
||||
|
||||
int BIO_set_fp(BIO *bio, FILE *file, int flags) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, flags, (char *)file);
|
||||
}
|
||||
|
||||
int BIO_read_filename(BIO *bio, const char *filename) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILENAME, BIO_CLOSE | BIO_FP_READ,
|
||||
(char *)filename);
|
||||
}
|
||||
|
||||
int BIO_write_filename(BIO *bio, const char *filename) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILENAME, BIO_CLOSE | BIO_FP_WRITE,
|
||||
(char *)filename);
|
||||
}
|
||||
|
||||
int BIO_append_filename(BIO *bio, const char *filename) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILENAME, BIO_CLOSE | BIO_FP_APPEND,
|
||||
(char *)filename);
|
||||
}
|
||||
|
||||
int BIO_rw_filename(BIO *bio, const char *filename) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILENAME,
|
||||
BIO_CLOSE | BIO_FP_READ | BIO_FP_WRITE,
|
||||
(char *)filename);
|
||||
}
|
||||
|
||||
long BIO_tell(BIO *bio) { return BIO_ctrl(bio, BIO_C_FILE_TELL, 0, NULL); }
|
||||
|
||||
long BIO_seek(BIO *bio, long offset) {
|
||||
return BIO_ctrl(bio, BIO_C_FILE_SEEK, offset, NULL);
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
namespace {
|
||||
// hexdump_ctx contains the state of a hexdump.
|
||||
struct hexdump_ctx {
|
||||
BIO *bio;
|
||||
char right_chars[18]; // the contents of the right-hand side, ASCII dump.
|
||||
unsigned used; // number of bytes in the current line.
|
||||
size_t n; // number of bytes total.
|
||||
unsigned indent;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static void hexbyte(char *out, uint8_t b) {
|
||||
static const char hextable[] = "0123456789abcdef";
|
||||
out[0] = hextable[b >> 4];
|
||||
out[1] = hextable[b & 0x0f];
|
||||
}
|
||||
|
||||
static char to_char(uint8_t b) {
|
||||
if (b < 32 || b > 126) {
|
||||
return '.';
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// hexdump_write adds |len| bytes of |data| to the current hex dump described by
|
||||
// |ctx|.
|
||||
static int hexdump_write(struct hexdump_ctx *ctx, const uint8_t *data,
|
||||
size_t len) {
|
||||
char buf[10];
|
||||
unsigned l;
|
||||
|
||||
// Output lines look like:
|
||||
// 00000010 2e 2f 30 31 32 33 34 35 36 37 38 ... 3c 3d // |./0123456789:;<=|
|
||||
// ^ offset ^ extra space ^ ASCII of line
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (ctx->used == 0) {
|
||||
// The beginning of a line.
|
||||
BIO_indent(ctx->bio, ctx->indent, UINT_MAX);
|
||||
|
||||
hexbyte(&buf[0], ctx->n >> 24);
|
||||
hexbyte(&buf[2], ctx->n >> 16);
|
||||
hexbyte(&buf[4], ctx->n >> 8);
|
||||
hexbyte(&buf[6], ctx->n);
|
||||
buf[8] = buf[9] = ' ';
|
||||
if (BIO_write(ctx->bio, buf, 10) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
hexbyte(buf, data[i]);
|
||||
buf[2] = ' ';
|
||||
l = 3;
|
||||
if (ctx->used == 7) {
|
||||
// There's an additional space after the 8th byte.
|
||||
buf[3] = ' ';
|
||||
l = 4;
|
||||
} else if (ctx->used == 15) {
|
||||
// At the end of the line there's an extra space and the bar for the
|
||||
// right column.
|
||||
buf[3] = ' ';
|
||||
buf[4] = '|';
|
||||
l = 5;
|
||||
}
|
||||
|
||||
if (BIO_write(ctx->bio, buf, l) < 0) {
|
||||
return 0;
|
||||
}
|
||||
ctx->right_chars[ctx->used] = to_char(data[i]);
|
||||
ctx->used++;
|
||||
ctx->n++;
|
||||
if (ctx->used == 16) {
|
||||
ctx->right_chars[16] = '|';
|
||||
ctx->right_chars[17] = '\n';
|
||||
if (BIO_write(ctx->bio, ctx->right_chars, sizeof(ctx->right_chars)) < 0) {
|
||||
return 0;
|
||||
}
|
||||
ctx->used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// finish flushes any buffered data in |ctx|.
|
||||
static int finish(struct hexdump_ctx *ctx) {
|
||||
// See the comments in |hexdump| for the details of this format.
|
||||
const unsigned n_bytes = ctx->used;
|
||||
unsigned l;
|
||||
char buf[5];
|
||||
|
||||
if (n_bytes == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
OPENSSL_memset(buf, ' ', 4);
|
||||
buf[4] = '|';
|
||||
|
||||
for (; ctx->used < 16; ctx->used++) {
|
||||
l = 3;
|
||||
if (ctx->used == 7) {
|
||||
l = 4;
|
||||
} else if (ctx->used == 15) {
|
||||
l = 5;
|
||||
}
|
||||
if (BIO_write(ctx->bio, buf, l) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->right_chars[n_bytes] = '|';
|
||||
ctx->right_chars[n_bytes + 1] = '\n';
|
||||
if (BIO_write(ctx->bio, ctx->right_chars, n_bytes + 2) < 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_hexdump(BIO *bio, const uint8_t *data, size_t len, unsigned indent) {
|
||||
struct hexdump_ctx ctx;
|
||||
OPENSSL_memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.bio = bio;
|
||||
ctx.indent = indent;
|
||||
|
||||
if (!hexdump_write(&ctx, data, len) || !finish(&ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_BIO_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BIO_INTERNAL_H
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#if defined(OPENSSL_PNACL)
|
||||
// newlib uses u_short in socket.h without defining it.
|
||||
typedef unsigned short u_short;
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_SOCK
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
// bio_ip_and_port_to_socket_and_addr creates a socket and fills in |*out_addr|
|
||||
// and |*out_addr_length| with the correct values for connecting to |hostname|
|
||||
// on |port_str|. It returns one on success or zero on error.
|
||||
int bio_ip_and_port_to_socket_and_addr(int *out_sock,
|
||||
struct sockaddr_storage *out_addr,
|
||||
socklen_t *out_addr_length,
|
||||
const char *hostname,
|
||||
const char *port_str);
|
||||
|
||||
// bio_socket_nbio sets whether |sock| is non-blocking. It returns one on
|
||||
// success and zero otherwise.
|
||||
int bio_socket_nbio(int sock, int on);
|
||||
|
||||
// bio_clear_socket_error clears the last system socket error.
|
||||
//
|
||||
// TODO(fork): remove all callers of this.
|
||||
void bio_clear_socket_error(void);
|
||||
|
||||
// bio_sock_error returns the last socket error on |sock|.
|
||||
int bio_sock_error(int sock);
|
||||
|
||||
// bio_socket_should_retry returns non-zero if |return_value| indicates an error
|
||||
// and the last socket error indicates that it's non-fatal.
|
||||
int bio_socket_should_retry(int return_value);
|
||||
|
||||
#endif // !OPENSSL_NO_SOCK
|
||||
|
||||
// bio_errno_should_retry returns non-zero if |return_value| indicates an error
|
||||
// and |errno| indicates that it's non-fatal.
|
||||
int bio_errno_should_retry(int return_value);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BIO_INTERNAL_H
|
||||
@@ -1,446 +0,0 @@
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
namespace {
|
||||
struct bio_bio_st {
|
||||
BIO *peer; // NULL if buf == NULL.
|
||||
// If peer != NULL, then peer->ptr is also a bio_bio_st,
|
||||
// and its "peer" member points back to us.
|
||||
// peer != NULL iff init != 0 in the BIO.
|
||||
|
||||
// This is for what we write (i.e. reading uses peer's struct):
|
||||
int closed; // valid iff peer != NULL
|
||||
size_t len; // valid iff buf != NULL; 0 if peer == NULL
|
||||
size_t offset; // valid iff buf != NULL; 0 if len == 0
|
||||
size_t size;
|
||||
uint8_t *buf; // "size" elements (if != NULL)
|
||||
|
||||
size_t request; // valid iff peer != NULL; 0 if len != 0,
|
||||
// otherwise set by peer to number of bytes
|
||||
// it (unsuccessfully) tried to read,
|
||||
// never more than buffer space (size-len) warrants.
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static int bio_new(BIO *bio) {
|
||||
struct bio_bio_st *b =
|
||||
reinterpret_cast<bio_bio_st *>(OPENSSL_zalloc(sizeof *b));
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b->size = 17 * 1024; // enough for one TLS record (just a default)
|
||||
bio->ptr = b;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void bio_destroy_pair(BIO *bio) {
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
BIO *peer_bio;
|
||||
struct bio_bio_st *peer_b;
|
||||
|
||||
if (b == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
peer_bio = b->peer;
|
||||
if (peer_bio == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
peer_b = reinterpret_cast<bio_bio_st *>(peer_bio->ptr);
|
||||
|
||||
assert(peer_b != NULL);
|
||||
assert(peer_b->peer == bio);
|
||||
|
||||
peer_b->peer = NULL;
|
||||
peer_bio->init = 0;
|
||||
assert(peer_b->buf != NULL);
|
||||
peer_b->len = 0;
|
||||
peer_b->offset = 0;
|
||||
|
||||
b->peer = NULL;
|
||||
bio->init = 0;
|
||||
assert(b->buf != NULL);
|
||||
b->len = 0;
|
||||
b->offset = 0;
|
||||
}
|
||||
|
||||
static int bio_free(BIO *bio) {
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
|
||||
assert(b != NULL);
|
||||
|
||||
if (b->peer) {
|
||||
bio_destroy_pair(bio);
|
||||
}
|
||||
|
||||
OPENSSL_free(b->buf);
|
||||
OPENSSL_free(b);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bio_read(BIO *bio, char *buf, int size_) {
|
||||
size_t size = size_;
|
||||
size_t rest;
|
||||
struct bio_bio_st *b, *peer_b;
|
||||
|
||||
BIO_clear_retry_flags(bio);
|
||||
|
||||
if (!bio->init) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
assert(b != NULL);
|
||||
assert(b->peer != NULL);
|
||||
peer_b = reinterpret_cast<bio_bio_st *>(b->peer->ptr);
|
||||
assert(peer_b != NULL);
|
||||
assert(peer_b->buf != NULL);
|
||||
|
||||
peer_b->request = 0; // will be set in "retry_read" situation
|
||||
|
||||
if (buf == NULL || size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (peer_b->len == 0) {
|
||||
if (peer_b->closed) {
|
||||
return 0; // writer has closed, and no data is left
|
||||
} else {
|
||||
BIO_set_retry_read(bio); // buffer is empty
|
||||
if (size <= peer_b->size) {
|
||||
peer_b->request = size;
|
||||
} else {
|
||||
// don't ask for more than the peer can
|
||||
// deliver in one write
|
||||
peer_b->request = peer_b->size;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// we can read
|
||||
if (peer_b->len < size) {
|
||||
size = peer_b->len;
|
||||
}
|
||||
|
||||
// now read "size" bytes
|
||||
rest = size;
|
||||
|
||||
assert(rest > 0);
|
||||
// one or two iterations
|
||||
do {
|
||||
size_t chunk;
|
||||
|
||||
assert(rest <= peer_b->len);
|
||||
if (peer_b->offset + rest <= peer_b->size) {
|
||||
chunk = rest;
|
||||
} else {
|
||||
// wrap around ring buffer
|
||||
chunk = peer_b->size - peer_b->offset;
|
||||
}
|
||||
assert(peer_b->offset + chunk <= peer_b->size);
|
||||
|
||||
OPENSSL_memcpy(buf, peer_b->buf + peer_b->offset, chunk);
|
||||
|
||||
peer_b->len -= chunk;
|
||||
if (peer_b->len) {
|
||||
peer_b->offset += chunk;
|
||||
assert(peer_b->offset <= peer_b->size);
|
||||
if (peer_b->offset == peer_b->size) {
|
||||
peer_b->offset = 0;
|
||||
}
|
||||
buf += chunk;
|
||||
} else {
|
||||
// buffer now empty, no need to advance "buf"
|
||||
assert(chunk == rest);
|
||||
peer_b->offset = 0;
|
||||
}
|
||||
rest -= chunk;
|
||||
} while (rest);
|
||||
|
||||
// |size| is bounded by the buffer size, which fits in |int|.
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
static int bio_write(BIO *bio, const char *buf, int num_) {
|
||||
size_t num = num_;
|
||||
size_t rest;
|
||||
struct bio_bio_st *b;
|
||||
|
||||
BIO_clear_retry_flags(bio);
|
||||
|
||||
if (!bio->init || buf == NULL || num == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
assert(b != NULL);
|
||||
assert(b->peer != NULL);
|
||||
assert(b->buf != NULL);
|
||||
|
||||
b->request = 0;
|
||||
if (b->closed) {
|
||||
// we already closed
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_BROKEN_PIPE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(b->len <= b->size);
|
||||
|
||||
if (b->len == b->size) {
|
||||
BIO_set_retry_write(bio); // buffer is full
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we can write
|
||||
if (num > b->size - b->len) {
|
||||
num = b->size - b->len;
|
||||
}
|
||||
|
||||
// now write "num" bytes
|
||||
rest = num;
|
||||
|
||||
assert(rest > 0);
|
||||
// one or two iterations
|
||||
do {
|
||||
size_t write_offset;
|
||||
size_t chunk;
|
||||
|
||||
assert(b->len + rest <= b->size);
|
||||
|
||||
write_offset = b->offset + b->len;
|
||||
if (write_offset >= b->size) {
|
||||
write_offset -= b->size;
|
||||
}
|
||||
// b->buf[write_offset] is the first byte we can write to.
|
||||
|
||||
if (write_offset + rest <= b->size) {
|
||||
chunk = rest;
|
||||
} else {
|
||||
// wrap around ring buffer
|
||||
chunk = b->size - write_offset;
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(b->buf + write_offset, buf, chunk);
|
||||
|
||||
b->len += chunk;
|
||||
|
||||
assert(b->len <= b->size);
|
||||
|
||||
rest -= chunk;
|
||||
buf += chunk;
|
||||
} while (rest);
|
||||
|
||||
// |num| is bounded by the buffer size, which fits in |int|.
|
||||
return (int)num;
|
||||
}
|
||||
|
||||
static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
|
||||
size_t writebuf2_len) {
|
||||
struct bio_bio_st *b1, *b2;
|
||||
|
||||
assert(bio1 != NULL);
|
||||
assert(bio2 != NULL);
|
||||
|
||||
b1 = reinterpret_cast<bio_bio_st *>(bio1->ptr);
|
||||
b2 = reinterpret_cast<bio_bio_st *>(bio2->ptr);
|
||||
|
||||
if (b1->peer != NULL || b2->peer != NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_IN_USE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (b1->buf == NULL) {
|
||||
if (writebuf1_len) {
|
||||
b1->size = writebuf1_len;
|
||||
}
|
||||
b1->buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(b1->size));
|
||||
if (b1->buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
b1->len = 0;
|
||||
b1->offset = 0;
|
||||
}
|
||||
|
||||
if (b2->buf == NULL) {
|
||||
if (writebuf2_len) {
|
||||
b2->size = writebuf2_len;
|
||||
}
|
||||
b2->buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(b2->size));
|
||||
if (b2->buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
b2->len = 0;
|
||||
b2->offset = 0;
|
||||
}
|
||||
|
||||
b1->peer = bio2;
|
||||
b1->closed = 0;
|
||||
b1->request = 0;
|
||||
b2->peer = bio1;
|
||||
b2->closed = 0;
|
||||
b2->request = 0;
|
||||
|
||||
bio1->init = 1;
|
||||
bio2->init = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
long ret;
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
|
||||
assert(b != NULL);
|
||||
|
||||
switch (cmd) {
|
||||
// Specific control codes first:
|
||||
case BIO_C_GET_WRITE_BUF_SIZE:
|
||||
ret = (long)b->size;
|
||||
break;
|
||||
|
||||
case BIO_C_GET_WRITE_GUARANTEE:
|
||||
// How many bytes can the caller feed to the next write
|
||||
// without having to keep any?
|
||||
if (b->peer == NULL || b->closed) {
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = (long)b->size - b->len;
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_C_GET_READ_REQUEST:
|
||||
// If the peer unsuccessfully tried to read, how many bytes
|
||||
// were requested? (As with BIO_CTRL_PENDING, that number
|
||||
// can usually be treated as boolean.)
|
||||
ret = (long)b->request;
|
||||
break;
|
||||
|
||||
case BIO_C_RESET_READ_REQUEST:
|
||||
// Reset request. (Can be useful after read attempts
|
||||
// at the other side that are meant to be non-blocking,
|
||||
// e.g. when probing SSL_read to see if any data is
|
||||
// available.)
|
||||
b->request = 0;
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
case BIO_C_SHUTDOWN_WR:
|
||||
// similar to shutdown(..., SHUT_WR)
|
||||
b->closed = 1;
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
|
||||
// Standard control codes:
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = bio->shutdown;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
bio->shutdown = (int)num;
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_PENDING:
|
||||
if (b->peer != NULL) {
|
||||
struct bio_bio_st *peer_b =
|
||||
reinterpret_cast<bio_bio_st *>(b->peer->ptr);
|
||||
ret = (long)peer_b->len;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
if (b->buf != NULL) {
|
||||
ret = (long)b->len;
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_EOF: {
|
||||
BIO *other_bio = reinterpret_cast<BIO *>(ptr);
|
||||
|
||||
if (other_bio) {
|
||||
struct bio_bio_st *other_b =
|
||||
reinterpret_cast<bio_bio_st *>(other_bio->ptr);
|
||||
assert(other_b != NULL);
|
||||
ret = other_b->len == 0 && other_b->closed;
|
||||
} else {
|
||||
ret = 1;
|
||||
}
|
||||
} break;
|
||||
|
||||
default:
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static const BIO_METHOD methods_biop = {
|
||||
BIO_TYPE_BIO, "BIO pair", bio_write, bio_read, NULL /* puts */,
|
||||
NULL /* gets */, bio_ctrl, bio_new, bio_free, NULL /* callback_ctrl */,
|
||||
};
|
||||
|
||||
static const BIO_METHOD *bio_s_bio(void) { return &methods_biop; }
|
||||
|
||||
int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1_len, BIO **bio2_p,
|
||||
size_t writebuf2_len) {
|
||||
BIO *bio1 = BIO_new(bio_s_bio());
|
||||
BIO *bio2 = BIO_new(bio_s_bio());
|
||||
if (bio1 == NULL || bio2 == NULL ||
|
||||
!bio_make_pair(bio1, bio2, writebuf1_len, writebuf2_len)) {
|
||||
BIO_free(bio1);
|
||||
BIO_free(bio2);
|
||||
*bio1_p = NULL;
|
||||
*bio2_p = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*bio1_p = bio1;
|
||||
*bio2_p = bio2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t BIO_ctrl_get_read_request(BIO *bio) {
|
||||
return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
|
||||
}
|
||||
|
||||
size_t BIO_ctrl_get_write_guarantee(BIO *bio) {
|
||||
return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
|
||||
}
|
||||
|
||||
int BIO_shutdown_wr(BIO *bio) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SHUTDOWN_WR, 0, NULL);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
int BIO_printf(BIO *bio, const char *format, ...) {
|
||||
va_list args;
|
||||
char buf[256], *out, out_malloced = 0;
|
||||
int out_len, ret;
|
||||
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(buf, sizeof(buf), format, args);
|
||||
va_end(args);
|
||||
if (out_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((size_t)out_len >= sizeof(buf)) {
|
||||
const size_t requested_len = (size_t)out_len;
|
||||
// The output was truncated. Note that vsnprintf's return value does not
|
||||
// include a trailing NUL, but the buffer must be sized for it.
|
||||
out = reinterpret_cast<char *>(OPENSSL_malloc(requested_len + 1));
|
||||
out_malloced = 1;
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(out, requested_len + 1, format, args);
|
||||
va_end(args);
|
||||
assert(out_len == (int)requested_len);
|
||||
} else {
|
||||
out = buf;
|
||||
}
|
||||
|
||||
ret = BIO_write(bio, out, out_len);
|
||||
if (out_malloced) {
|
||||
OPENSSL_free(out);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
OPENSSL_MSVC_PRAGMA(comment(lib, "Ws2_32.lib"))
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
static int closesocket(int sock) {
|
||||
return close(sock);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sock_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
closesocket(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
bio->flags = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sock_read(BIO *b, char *out, int outl) {
|
||||
if (out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bio_clear_socket_error();
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int ret = recv(b->num, out, outl, 0);
|
||||
#else
|
||||
int ret = (int)read(b->num, out, outl);
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sock_write(BIO *b, const char *in, int inl) {
|
||||
bio_clear_socket_error();
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int ret = send(b->num, in, inl, 0);
|
||||
#else
|
||||
int ret = (int)write(b->num, in, inl);
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
int *ip;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_C_SET_FD:
|
||||
sock_free(b);
|
||||
b->num = *((int *)ptr);
|
||||
b->shutdown = (int)num;
|
||||
b->init = 1;
|
||||
break;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = b->num;
|
||||
}
|
||||
ret = b->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = b->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_sockp = {
|
||||
BIO_TYPE_SOCKET, "socket",
|
||||
sock_write, sock_read,
|
||||
NULL /* puts */, NULL /* gets, */,
|
||||
sock_ctrl, NULL /* create */,
|
||||
sock_free, NULL /* callback_ctrl */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_socket(void) { return &methods_sockp; }
|
||||
|
||||
BIO *BIO_new_socket(int fd, int close_flag) {
|
||||
BIO *ret;
|
||||
|
||||
ret = BIO_new(BIO_s_socket());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fd(ret, fd, close_flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -1,131 +0,0 @@
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(__linux__)
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
int bio_ip_and_port_to_socket_and_addr(int *out_sock,
|
||||
struct sockaddr_storage *out_addr,
|
||||
socklen_t *out_addr_length,
|
||||
const char *hostname,
|
||||
const char *port_str) {
|
||||
struct addrinfo hint, *result, *cur;
|
||||
int ret;
|
||||
|
||||
*out_sock = -1;
|
||||
|
||||
OPENSSL_memset(&hint, 0, sizeof(hint));
|
||||
hint.ai_family = AF_UNSPEC;
|
||||
hint.ai_socktype = SOCK_STREAM;
|
||||
|
||||
ret = getaddrinfo(hostname, port_str, &hint, &result);
|
||||
if (ret != 0) {
|
||||
OPENSSL_PUT_ERROR(SYS, 0);
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
ERR_add_error_data(1, gai_strerrorA(ret));
|
||||
#else
|
||||
ERR_add_error_data(1, gai_strerror(ret));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
for (cur = result; cur; cur = cur->ai_next) {
|
||||
if ((size_t) cur->ai_addrlen > sizeof(struct sockaddr_storage)) {
|
||||
continue;
|
||||
}
|
||||
OPENSSL_memset(out_addr, 0, sizeof(struct sockaddr_storage));
|
||||
OPENSSL_memcpy(out_addr, cur->ai_addr, cur->ai_addrlen);
|
||||
*out_addr_length = cur->ai_addrlen;
|
||||
|
||||
*out_sock = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
|
||||
if (*out_sock < 0) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
freeaddrinfo(result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bio_socket_nbio(int sock, int on) {
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
u_long arg = on;
|
||||
|
||||
return 0 == ioctlsocket(sock, FIONBIO, &arg);
|
||||
#else
|
||||
int flags = fcntl(sock, F_GETFL, 0);
|
||||
if (flags < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (!on) {
|
||||
flags &= ~O_NONBLOCK;
|
||||
} else {
|
||||
flags |= O_NONBLOCK;
|
||||
}
|
||||
return fcntl(sock, F_SETFL, flags) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void bio_clear_socket_error(void) {}
|
||||
|
||||
int bio_sock_error(int sock) {
|
||||
int error;
|
||||
socklen_t error_size = sizeof(error);
|
||||
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&error, &error_size) < 0) {
|
||||
return 1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
int bio_socket_should_retry(int return_value) {
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
return return_value == -1 && WSAGetLastError() == WSAEWOULDBLOCK;
|
||||
#else
|
||||
// On POSIX platforms, sockets and fds are the same.
|
||||
return bio_errno_should_retry(return_value);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -1,169 +0,0 @@
|
||||
// Copyright 2021 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/blake2.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.6
|
||||
static const uint64_t kIV[8] = {
|
||||
UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b),
|
||||
UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1),
|
||||
UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f),
|
||||
UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179),
|
||||
};
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.7
|
||||
static const uint8_t kSigma[10 * 16] = {
|
||||
// clang-format off
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
||||
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
||||
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
||||
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
||||
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
||||
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
||||
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
||||
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
||||
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
// 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] = CRYPTO_rotr_u64(v[d] ^ v[a], 32);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 24);
|
||||
v[a] = v[a] + v[b] + y;
|
||||
v[d] = CRYPTO_rotr_u64(v[d] ^ v[a], 16);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 63);
|
||||
}
|
||||
|
||||
static uint64_t blake2b_load(const uint8_t block[BLAKE2B_CBLOCK], size_t i) {
|
||||
return CRYPTO_load_u64_le(block + 8 * i);
|
||||
}
|
||||
|
||||
static void blake2b_transform(BLAKE2B_CTX *b2b,
|
||||
const uint8_t block[BLAKE2B_CBLOCK],
|
||||
size_t num_bytes, int is_final_block) {
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.2
|
||||
uint64_t v[16];
|
||||
static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), "");
|
||||
OPENSSL_memcpy(v, b2b->h, sizeof(b2b->h));
|
||||
OPENSSL_memcpy(&v[8], kIV, sizeof(kIV));
|
||||
|
||||
b2b->t_low += num_bytes;
|
||||
if (b2b->t_low < num_bytes) {
|
||||
b2b->t_high++;
|
||||
}
|
||||
v[12] ^= b2b->t_low;
|
||||
v[13] ^= b2b->t_high;
|
||||
|
||||
if (is_final_block) {
|
||||
v[14] = ~v[14];
|
||||
}
|
||||
|
||||
for (int round = 0; round < 12; round++) {
|
||||
const uint8_t *const s = &kSigma[16 * (round % 10)];
|
||||
blake2b_mix(v, 0, 4, 8, 12, blake2b_load(block, s[0]),
|
||||
blake2b_load(block, s[1]));
|
||||
blake2b_mix(v, 1, 5, 9, 13, blake2b_load(block, s[2]),
|
||||
blake2b_load(block, s[3]));
|
||||
blake2b_mix(v, 2, 6, 10, 14, blake2b_load(block, s[4]),
|
||||
blake2b_load(block, s[5]));
|
||||
blake2b_mix(v, 3, 7, 11, 15, blake2b_load(block, s[6]),
|
||||
blake2b_load(block, s[7]));
|
||||
blake2b_mix(v, 0, 5, 10, 15, blake2b_load(block, s[8]),
|
||||
blake2b_load(block, s[9]));
|
||||
blake2b_mix(v, 1, 6, 11, 12, blake2b_load(block, s[10]),
|
||||
blake2b_load(block, s[11]));
|
||||
blake2b_mix(v, 2, 7, 8, 13, blake2b_load(block, s[12]),
|
||||
blake2b_load(block, s[13]));
|
||||
blake2b_mix(v, 3, 4, 9, 14, blake2b_load(block, s[14]),
|
||||
blake2b_load(block, s[15]));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(b2b->h); i++) {
|
||||
b2b->h[i] ^= v[i];
|
||||
b2b->h[i] ^= v[i + 8];
|
||||
}
|
||||
}
|
||||
|
||||
void BLAKE2B256_Init(BLAKE2B_CTX *b2b) {
|
||||
OPENSSL_memset(b2b, 0, sizeof(BLAKE2B_CTX));
|
||||
|
||||
static_assert(sizeof(kIV) == sizeof(b2b->h), "");
|
||||
OPENSSL_memcpy(&b2b->h, kIV, sizeof(kIV));
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.5
|
||||
b2b->h[0] ^= 0x01010000 | BLAKE2B256_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *in_data, size_t len) {
|
||||
if (len == 0) {
|
||||
// Work around a C language bug. See https://crbug.com/1019588.
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t *data = reinterpret_cast<const uint8_t *>(in_data);
|
||||
size_t todo = sizeof(b2b->block) - b2b->block_used;
|
||||
if (todo > len) {
|
||||
todo = len;
|
||||
}
|
||||
OPENSSL_memcpy(&b2b->block[b2b->block_used], data, todo);
|
||||
b2b->block_used += todo;
|
||||
data += todo;
|
||||
len -= todo;
|
||||
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
|
||||
// More input remains therefore we must have filled |b2b->block|.
|
||||
assert(b2b->block_used == BLAKE2B_CBLOCK);
|
||||
blake2b_transform(b2b, b2b->block, BLAKE2B_CBLOCK,
|
||||
/*is_final_block=*/0);
|
||||
b2b->block_used = 0;
|
||||
|
||||
while (len > BLAKE2B_CBLOCK) {
|
||||
blake2b_transform(b2b, data, BLAKE2B_CBLOCK, /*is_final_block=*/0);
|
||||
data += BLAKE2B_CBLOCK;
|
||||
len -= BLAKE2B_CBLOCK;
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(b2b->block, data, len);
|
||||
b2b->block_used = len;
|
||||
}
|
||||
|
||||
void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH], BLAKE2B_CTX *b2b) {
|
||||
OPENSSL_memset(&b2b->block[b2b->block_used], 0,
|
||||
sizeof(b2b->block) - b2b->block_used);
|
||||
blake2b_transform(b2b, b2b->block, b2b->block_used,
|
||||
/*is_final_block=*/1);
|
||||
static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), "");
|
||||
memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
void BLAKE2B256(const uint8_t *data, size_t len,
|
||||
uint8_t out[BLAKE2B256_DIGEST_LENGTH]) {
|
||||
BLAKE2B_CTX ctx;
|
||||
BLAKE2B256_Init(&ctx);
|
||||
BLAKE2B256_Update(&ctx, data, len);
|
||||
BLAKE2B256_Final(out, &ctx);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright 2021 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/blake2.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../test/file_test.h"
|
||||
#include "../test/test_util.h"
|
||||
|
||||
TEST(BLAKE2B256Test, ABC) {
|
||||
// https://tools.ietf.org/html/rfc7693#appendix-A, except updated for the
|
||||
// 256-bit hash output.
|
||||
const uint8_t kExpected[] = {
|
||||
0xbd, 0xdd, 0x81, 0x3c, 0x63, 0x42, 0x39, 0x72, 0x31, 0x71, 0xef,
|
||||
0x3f, 0xee, 0x98, 0x57, 0x9b, 0x94, 0x96, 0x4e, 0x3b, 0xb1, 0xcb,
|
||||
0x3e, 0x42, 0x72, 0x62, 0xc8, 0xc0, 0x68, 0xd5, 0x23, 0x19,
|
||||
};
|
||||
|
||||
uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
|
||||
BLAKE2B256((const uint8_t *)"abc", 3, digest);
|
||||
EXPECT_EQ(Bytes(kExpected), Bytes(digest));
|
||||
}
|
||||
|
||||
TEST(BLAKE2B256Test, TestVectors) {
|
||||
FileTestGTest("crypto/blake2/blake2b256_tests.txt", [](FileTest *t) {
|
||||
std::vector<uint8_t> msg, expected;
|
||||
ASSERT_TRUE(t->GetBytes(&msg, "IN"));
|
||||
ASSERT_TRUE(t->GetBytes(&expected, "HASH"));
|
||||
|
||||
uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
|
||||
BLAKE2B256(msg.data(), msg.size(), digest);
|
||||
EXPECT_EQ(Bytes(digest), Bytes(expected)) << msg.size();
|
||||
|
||||
OPENSSL_memset(digest, 0, sizeof(digest));
|
||||
BLAKE2B_CTX b2b;
|
||||
BLAKE2B256_Init(&b2b);
|
||||
for (uint8_t b : msg) {
|
||||
BLAKE2B256_Update(&b2b, &b, 1);
|
||||
}
|
||||
BLAKE2B256_Final(digest, &b2b);
|
||||
EXPECT_EQ(Bytes(digest), Bytes(expected)) << msg.size();
|
||||
});
|
||||
}
|
||||
@@ -1,820 +0,0 @@
|
||||
# Copyright 2021 The BoringSSL Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Generated by the following Go program.
|
||||
#
|
||||
# package main
|
||||
#
|
||||
# import (
|
||||
# "fmt"
|
||||
# "golang.org/x/crypto/blake2b"
|
||||
# )
|
||||
#
|
||||
# func main() {
|
||||
# var buf [256]byte
|
||||
# for i := range buf {
|
||||
# buf[i] = byte(i)
|
||||
# }
|
||||
#
|
||||
# for i := 0; i < 256; i++ {
|
||||
# h, err := blake2b.New256(nil)
|
||||
# if err != nil {
|
||||
# panic(err)
|
||||
# }
|
||||
# h.Write(buf[:i])
|
||||
# fmt.Printf("IN: %x\n", buf[:i])
|
||||
# fmt.Printf("HASH: %x\n", h.Sum(nil))
|
||||
# fmt.Printf("\n")
|
||||
# }
|
||||
# }
|
||||
|
||||
IN:
|
||||
HASH: 0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8
|
||||
|
||||
IN: 00
|
||||
HASH: 03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314
|
||||
|
||||
IN: 0001
|
||||
HASH: 01cf79da4945c370c68b265ef70641aaa65eaa8f5953e3900d97724c2c5aa095
|
||||
|
||||
IN: 000102
|
||||
HASH: 3d8c3d594928271f44aad7a04b177154806867bcf918e1549c0bc16f9da2b09b
|
||||
|
||||
IN: 00010203
|
||||
HASH: e1eae5a8adae652ec9af9677346a9d60eced61e3a0a69bfacf518db31f86e36b
|
||||
|
||||
IN: 0001020304
|
||||
HASH: 663694ac6520bdce7caab1cf3929ffe78cb2fea67a3dfc8559753a9f512a0c85
|
||||
|
||||
IN: 000102030405
|
||||
HASH: 274327d0e2a207844988fac0b39e071422e3f621913d69a5cfef23b38601a56f
|
||||
|
||||
IN: 00010203040506
|
||||
HASH: 9df14b7248764a869197c35e392d2a6d6fdc5b79d597297920fd3f1491b442d2
|
||||
|
||||
IN: 0001020304050607
|
||||
HASH: 77065d25b622a8251094d869edf6b4e9ba0708a8db1f239cb68e4eeb45851621
|
||||
|
||||
IN: 000102030405060708
|
||||
HASH: 8660231b62ce1d61fc8be93bd6acdb43ff61a7ab4cc9494f0cc803362360b07b
|
||||
|
||||
IN: 00010203040506070809
|
||||
HASH: 8b57a796a5d07cb04cc1614dfc2acb3f73edc712d7f433619ca3bbe66bb15f49
|
||||
|
||||
IN: 000102030405060708090a
|
||||
HASH: cc932bee351be391849c87925f2e00a83051419dc310b288d4304d4adea3d0e0
|
||||
|
||||
IN: 000102030405060708090a0b
|
||||
HASH: 99bd72c73bea193f7040ac279bd656cdec7fd35e097a657b6c03b4fa967223ed
|
||||
|
||||
IN: 000102030405060708090a0b0c
|
||||
HASH: 695e93b723e0a08e8dd8dd4656389363519564daf4cde5fe95a6a0ca71d3705e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d
|
||||
HASH: 4cce7128e4f659ba41ee163c45280d468163adc8c76c4937a0bbfa0cf3bdeae7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e
|
||||
HASH: 929cec40e9e746e771c6ad05cfcf37641254ef5e802fa71a02f8982f525f2b00
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f
|
||||
HASH: c7cb5d1a1a214f1d833a21fe6c7b2420e417c2f220784cbe90072975131bc367
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f10
|
||||
HASH: ced0cd609f3c8ff85b9cec93bba556dbe3caa996ac5beb629d4512473d6b31ae
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f1011
|
||||
HASH: 584c9cb4da3be635d86e803c9eebccfd27fbed4aae27b0207ce3c934a0043aa4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112
|
||||
HASH: 9b508680d1f75d5f1e5306fbfaf7e88621cebf39f7f5cbf9e2dbb7ebb88504d4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f10111213
|
||||
HASH: 5d597f201ead11daa0687185c579efd702e288d5bd72b6b21238a4ecb52d288a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f1011121314
|
||||
HASH: 85b8afd95165d04681ab948f2f0545c47a8d11d9d1866cb7ecc88bc31a634891
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415
|
||||
HASH: 93c541c87fb52d506b1b262e49ed71689a15b745e8f3e003893c8c59cfc669fe
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f10111213141516
|
||||
HASH: 395d6a5e3b41b6151411b9b22f07fcbae6c7c30df59c10ca2dfcfe333ac8e3fb
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f1011121314151617
|
||||
HASH: 8d71aeb3137041d31ed42466ea5fdca2ec7a35c7701d142ccb813f8c614ceca2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718
|
||||
HASH: 3b0b9b4027203daeb62f4ff868ac6cdd78a5cbbf7664725421a613794702f4f4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f10111213141516171819
|
||||
HASH: 7384c8812f6803d8649bed21a3acbbf36239bbd17274d249369dd65e6329fd84
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a
|
||||
HASH: 3890962f7d604fe0fcade7d8fc03c7e6285da2035bac5a9362c1d68a353d5350
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b
|
||||
HASH: 9dc0b41d6a6a6c194d04336eb383ac7f4ea537700d5926346dfb1379e9453460
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c
|
||||
HASH: bd78e1c368d70b968e194dca2c6fbda605a67d5e52824289e058c93eee073ef5
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
|
||||
HASH: 4cc3e428d63dc132471d3135d406f8d6e30d2480d571bffbd64957bbb090f582
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e
|
||||
HASH: 9adf65b53153b1caec84cd717e00e01c2000d0569704ce38d065180adee5d964
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
|
||||
HASH: cb2f5160fc1f7e05a55ef49d340b48da2e5a78099d53393351cd579dd42503d6
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
|
||||
HASH: b7634fe13c7aca3914ee896e22cfabc9da5b4f13e72a2ccbecb6d44bbda95bcc
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021
|
||||
HASH: 9badddebf24552cb1f66d32990476594e5249a729254f7b5c840728a42749a45
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122
|
||||
HASH: 13891b823d3a2cfe0d1a5e60fe89d8c091524f994cdc3241c4da19c4bb3c2c6b
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223
|
||||
HASH: c1b7eb8d130d705c5fa9ee8061076a3151f2e36e42d9c9289d85065b9ab343dd
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324
|
||||
HASH: ee6a288c4fcae34572fc6dba3e0b7d698bef65dcc63bf28ebd74207a2065718a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425
|
||||
HASH: 1b5ad5f31e4061f423ee11e3de88fef05dfed9393c268fd360d05fe4465fe40a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526
|
||||
HASH: 87c40636d0ee94687fdf020e3d165f4e45f21d62fa04aa2b9103a8187da6e64a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324252627
|
||||
HASH: 70a3082dfc7582b9d252939a474338db1f94a6dcc7724709377797d17ff51ac5
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728
|
||||
HASH: 109036d1dece657ac6471f7f7ed33846986fdcb9dae8a73ea0881607e5e45f13
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526272829
|
||||
HASH: deda4f3e98e58392adaee3c2e7b91d172551c50945a8ae9e9e1ad10c2ae510a8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a
|
||||
HASH: 2a82cabbbb09956d212d182cfaf7cde2f55fa33f96e3a1ab19fccfdb668ce2f2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b
|
||||
HASH: 4a21b38c69f755c016ebb4a66eb76b4f9d4087a02fc8c3c257c1183efebda824
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c
|
||||
HASH: d3ecaa4853a092755c3692cac3fea5d9ccfaca2d32b59ccae151705333359e79
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d
|
||||
HASH: 0ab5250248686afe6eca3f3ed89e061c0b3ae2a13454b907bbdb643a72b25a66
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e
|
||||
HASH: 2fb57ab5fc0927e8301b6933325530e90fa7a94eaea95bad7c3f2f1052032900
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f
|
||||
HASH: 48de881e6c1dc35253d9c8d56e773743640f097bb7274b80ec090f1b33d1dc2e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30
|
||||
HASH: 71745158a70425e25a8446122dda82fcfeb6bfcb593b25d79c539c6b989c526d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031
|
||||
HASH: 45d3d95f04f304be5a61ef38357bd01e61f9bb7f8c9979458d846d9899436167
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132
|
||||
HASH: d5afebad633b7d595e6c8482d8c9a429091f58acbd84725adbac12e8be80ada9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233
|
||||
HASH: 06bbb3b17ea95e7e00ac21b8632f84615f11456fabcda9d99cbf079e3134cfe5
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334
|
||||
HASH: 02b8e881b5f78b451995f07116af3549066cbce498497f546a9772981779d908
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435
|
||||
HASH: 370c5efe99822c30460a123467e8f151f012065ba3639bc0407ed3b3609e5d56
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536
|
||||
HASH: ace7db9e8f298e823b7b265bbcd004577e0029256c48684b2d7a7cdfcbff5e47
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637
|
||||
HASH: a6c1d35f74218e57b4dbd4ed467b41981208666738ffa0d9dc53d3de96be702a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738
|
||||
HASH: 25e44457f063ae4ea799502c38d66eeefb46f520b4fc9a298df9826c9d62eea9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536373839
|
||||
HASH: 1b35b64cf659d6d7d0ca933c9a52fb0e67fba76a304fadb7c47dd8ff6b6ff0fa
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a
|
||||
HASH: a72de68ff63bbe9ccfaccfa6859af660bb413f9e5d0200106100919c10301ef8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b
|
||||
HASH: cfe37ab9c02bf84afa7a734a10317150479b791a27efc374dd669f4ef67a801d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c
|
||||
HASH: a55a2c06f3db74c95b33d1e962da18772c3601eb13fe0b86a78667b2b9f9df86
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d
|
||||
HASH: 1b8a9195724ac01ad7da4a76c2545d2f3dc223a0242537050d7395f588748079
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e
|
||||
HASH: 29e41a64fbdd2fd27612228623c0702222bf367451e7324287f181cb3dcf7237
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f
|
||||
HASH: 10d8e6d534b00939843fe9dcc4dae48cdf008f6b8b2b82b156f5404d874887f5
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40
|
||||
HASH: 84c04ab082c8ae24206561f77397704b627892089a05887a2a1996472bcfe15d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041
|
||||
HASH: 2b684baba4a7245e38c3263d85b5524a51baa8ca18444af1b5958596bc30d424
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142
|
||||
HASH: 1d59fa9501213440975a0b27e4b52eea7274f8794ec35b8ee4824f7b00897ed7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243
|
||||
HASH: 60669608711b9df3715b631b474d5206179a81d054ef5494612899728b55e103
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344
|
||||
HASH: 46060cb9dc6be177bafe5425c4f84f9143b71cfc75dd958e15ff7a26cc92859b
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445
|
||||
HASH: e7f909c8e018bc36b59a8e7848d16c05d6bdb0ebb91fb9baf54cc328192cc362
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243444546
|
||||
HASH: 7a9f75439c68869a6595eb63c61db2bc213d3ef067ec0cb3f25e02e554fce2a9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344454647
|
||||
HASH: adb39b3e53a791dfd32eca83191eb82fdef4321ac504539b257c3376da240aca
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748
|
||||
HASH: 240ca19b3671dcc5ef174331fb0dd24b845dfcd01b0fbe52fa72a29bcaef1373
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243444546474849
|
||||
HASH: ebae0805fd52d3e9f5f29aeb33b6be8cab0f28e668990d3cb95444d9ef90b932
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a
|
||||
HASH: ea7c3c052928f0fa3b8d86b19c87dee905e8a4b26a0a23b3c8e8dc7255ea82d6
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b
|
||||
HASH: 4ad32c1f2d18c8b7dc29d1526d7c751b89b86882fb12aa3cc9c6eddb7991d266
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c
|
||||
HASH: c61f81c3e6b899d0501b05df1de32099a7b0e878689dc2a3fd5583de90a74164
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d
|
||||
HASH: 068a8a0b96076a2773a8e00e00e57eef4fb26886b521285a6c747130850792d7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e
|
||||
HASH: efab0151162523b18147cba89679bdab2d9b670f5ae222a34c360c094af1d441
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f
|
||||
HASH: 066de1009daca2b8390a9dc734bce547ac4e3cc4531645bb8b9cbc0070941d88
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50
|
||||
HASH: 9fbb33b95e79c5c1683ab09a6abff6612fffb4458543dc8bbc7723a6dc2bf2ed
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051
|
||||
HASH: 88fea89237618cfc0270cbcd08e7ffdaa8933607c0dbccb8dd075b84fba83b11
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152
|
||||
HASH: b1960beaa4fed01453679c7d6cf78d25442bdf92ae51be479dab18e1b2b922d3
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253
|
||||
HASH: a7d6821a97bc57cf6b5e25953c689439beda79364c903a3e64b6671dc9eceb2f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051525354
|
||||
HASH: 90ca93ecd3e0e7c839e4fc0f2e4748954a89b2c7338e55fc18a53ccd08abed2e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455
|
||||
HASH: 58fe5f45b9915a5b177f4256b51ce5781662352a2dd620a946b8755213fbd61f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556
|
||||
HASH: d109c8ec77e2253b5e7c761f59b184815e46b06cc5132a92511a93dead6315c2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051525354555657
|
||||
HASH: fd9664ecb814785c8474188706e6ab0952925f9b9d8e351665ced12e84d92fad
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758
|
||||
HASH: 81342700c48f41ec5b54180d560e73e5ad6782717b2d3320b42280be11f0873e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556575859
|
||||
HASH: 523cf9a356076fe8c3538bdd752bc43712c7d28f29499aaae7812f1e4167840e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a
|
||||
HASH: 9706d70e28a9e99db15974b1c01635868a62c6567eb40903adae58d417b882f2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b
|
||||
HASH: 2216f01255ff24422e18d906c64506924940451e09d4ec17e4dbc8ea6d14ef59
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c
|
||||
HASH: 64ad22e77fc9f8a03ad6e06a067add9f0e0360d4533014fa286ccdf40dceb231
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d
|
||||
HASH: 9908418a2bb564ab9607d2f863b841dd4fe47ee370dde05a9368e400f7f9904b
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e
|
||||
HASH: 981a7989084e74f6d5fd8870321e860991729eed88e60d85ab5fdaa769be6fd2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f
|
||||
HASH: 6528ea458efd23391e968e0dd3a40202ac94e3854d1a4642cbbe0d13a15cb849
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60
|
||||
HASH: 767fdcd43cf16cbf980fd560dfc55f67be20510f9a0c8fcd5c749da8ef23fd7b
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061
|
||||
HASH: 90afc4e366bcee748591d93ba9f7c2e05a1fda261b58d094f8f0450c8a31ffb8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162
|
||||
HASH: 660f9f5d430bf89f5946fd4649ad41f806937641c808a80da70660f53179a941
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263
|
||||
HASH: 5ac86383dec1db602fdbc2c978c3fe1bf4328fea1e1b495b68be2c3b67ba033b
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364
|
||||
HASH: 7c15cdf3705457eb6b8edd79fb75bf568692ccb778f85fa2e1d462f48ee55c4f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465
|
||||
HASH: a8df989766fc245edbb4b7268afb7380e4ea3f7123802b72ae2adb938211c9f9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566
|
||||
HASH: 707aa875c6162027ac2829894c0be750f5ee8fe8a64465080025f708dc200f0e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364656667
|
||||
HASH: 6efd41538fec50459b6c2583ade5754c86617580eef3071d38723aaf743f93c7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768
|
||||
HASH: 5c22d6a56a4fbdb85aa70994b4e118224bb6db2afd017a98c2b992ce26ea8925
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566676869
|
||||
HASH: a4a9739a1c83135bab3334990b470164ed81f633d7fe79722b3ac6e65dadd38e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a
|
||||
HASH: f1ac1ad3348ea6c949fde09cbee706ea0aecf3a93fc51a8a7e2bdb8cd7400b01
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b
|
||||
HASH: 492d9eae92f27ecce118d3fd8df63158cf709ed5069502263b8be1c105196ea3
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c
|
||||
HASH: 8691c32810f3220c0df76816af0a73b3fade2594cbcc711b855e2cd81dbdec95
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d
|
||||
HASH: cab341f7059d974cbc620bc423b02f58b5e1a899f416b0858ae1a736d4681162
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e
|
||||
HASH: e08b3d16f0a3b663f319da999db897488d1677048a38fa7b4f1f783e4f1974e6
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f
|
||||
HASH: d5587e0b33166a320dd69417adb01cb1129aff5506a2f655574cf2e264636bdb
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70
|
||||
HASH: 5a69194c22af2b7040a8488738f96c901ae215965d611a572932464261539fc8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071
|
||||
HASH: d8e7d58cd37acad505940843a8bb046971c43e4d0593c6bb946b07926644f78f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172
|
||||
HASH: 46b07cc026b633e6245661813d5aca2bcc295d0b8ab01f27f517b4f2823d0b3e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273
|
||||
HASH: fc169b3e5480e72057d828702f9da4f08d141a178eb8adef03ca0708c1a10df7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727374
|
||||
HASH: ae3e241c1c394190fbac7fccb3df0d0bc317c6e1a15993330e9b648c80264066
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475
|
||||
HASH: f430aeef864823d8c8b448f2d25452ea3ed7abe2966adc8c42636b69d0a1bad9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273747576
|
||||
HASH: b0d6518afa4e3590746aa5fd1e58f7ec06a347981177737ad6631b22c53b6617
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727374757677
|
||||
HASH: 16684ddd272dfc18dd40c16a7f57cecca70df0a96c4a066b97646953e7c7691a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778
|
||||
HASH: e8208de0982f3d8e9ac258eb26eb3f130ced7331797b625d6b65ba4ba2064c9c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273747576777879
|
||||
HASH: 8ecd4bdc226fb29dd486cd77b566723e44c77194ba7a000734736dbb76f61c7c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a
|
||||
HASH: 153d5c1d5edb08f51f6353b6b7bdd48a9bba14068923b8991be59346a4f932f7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b
|
||||
HASH: 60e555a694396b48273d2d778709c208c0757cd15697a43cf0c2115599c80e68
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c
|
||||
HASH: 7a4a15b47029005972a6b814d5e7f2c86c616bd98e6a06bd95cbed2f47400c67
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d
|
||||
HASH: 3de5adb8e3bf8dfabb41afe53c58fad23427a148755148011b5c12b88aba3dc0
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e
|
||||
HASH: f2fe67ff342e21b8f45e8f2e0bcd1d9243245d50ee6c78042e9c491388791c72
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f
|
||||
HASH: c3582f71ebb2be66fa5dd750f80baae97554f3b015663c8be377cfcb2488c1d1
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80
|
||||
HASH: f7f3c46ba2564ff4c4c162da1f5b605f9f1c4aa6a20652a9f9a337c1a2f5b9c9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081
|
||||
HASH: d3b11b4cbe513ec7b6f4bb5ff0c411de405a8641cf221493447a35927ca3aea7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182
|
||||
HASH: 62323574c7cdaaca448fcbc7091ae4af3e04decb0d3c7c55636baa0a99c88699
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283
|
||||
HASH: 89b7d0203387e0332622ca84a879bddbcff155a213997560fc05428e79e06891
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384
|
||||
HASH: be5cce3e365fbbb139f68a3da3367e42aa8bd79b15f5252f7c08c3c8f0dcab27
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485
|
||||
HASH: 7ae7702bc025692f2ea5ab0c2eb6552c7975a57c5acb93ff115d303f341a579c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283848586
|
||||
HASH: f7c4efacc0a4cb5836f170ea0bf5dc5ce36fe2d88e76a9f259eaab71aef0ff13
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384858687
|
||||
HASH: 6a35d3dadc62dfe7819519f92181b2f8d38f5e0ed3d51a22cf8a133ab628d6f4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788
|
||||
HASH: bacecc2948c41beb73c815ca7cee6c7dbf2e4219190936edac5e4680500dd4d2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283848586878889
|
||||
HASH: 2dce89f76f4f37472ae6374b0825a9cd61619a995c7f49733f62b606a7ce905a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a
|
||||
HASH: 7b65e63a0d17d68c798b5d5631f17c35faff70dbe90006589ca89277dbeeafc0
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b
|
||||
HASH: 9477e374453099d2f8679e1d9b167b5f1c4e3cc66f32bdd9a3748a10876a27b3
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c
|
||||
HASH: 448437adad41878e6529fcc2fad9bbdb13697b6cbb2669fc8150d3aa7e0418b8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d
|
||||
HASH: ce4936743020825f508ca72c8355c88224a52c348a21567e65526ff8f82632fd
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e
|
||||
HASH: 556a195bf23cba5c3193fbbe472f1cd5478ea4cad2dc6d6a193102a2abd0fac4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f
|
||||
HASH: e15dc6238e2e58e9ea212b0d7abfd700da3ae5120d4d601341ce9e424a7c5828
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90
|
||||
HASH: a22022450276c5018d51cd321e0e195a0add003e33ecaa97028d6974b5712187
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091
|
||||
HASH: 044cabb79e57da22b772249c332bfb43c5d1c9b683d1b2d2b75f4c5e6773a216
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192
|
||||
HASH: 766e1167593896bdc8793fb7ccdb1d35dc430aaeafe1e7a96aba870416587e7e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293
|
||||
HASH: e19d72ca8438477db71e1bfa48924c4e75ee4f84c7aa9b0911521c60a2ba6440
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091929394
|
||||
HASH: 512ee7aa89497a761f0798c29a1dd37d1d86f1c0870519a0aab69d265df118c0
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495
|
||||
HASH: 80c199310a2ab7af6a808f6d68843136c30e9228a766618632d4e1210edf365c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293949596
|
||||
HASH: 43fdffd19c692b6ef87c103cad9b80fb86919e6ecdcb73364d260da29a5f28d3
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091929394959697
|
||||
HASH: 1d1dc1909a6a8e552a0f8964601102d0edc89f5a02d3acced71826bbc5ca37af
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798
|
||||
HASH: fa77dac317e8c531246e14265ed42a87ade6fc3ce351652e6ad9290f8a157617
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293949596979899
|
||||
HASH: 5bbc0f8b1a52732ed548e600865ae53360f0642a5674ecc7c6185f2cdeeb6601
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a
|
||||
HASH: 89c5fcbaf3a61d6fa4fa33c3eca8761ebab3c3467aba7d255394a0e70811ef3f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b
|
||||
HASH: 9b3ecec85fa5ba5e0f1542085fff46bb2262163979879c9565294b2c56842a28
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c
|
||||
HASH: 4e301b852d473b5d12271209bdc350b4ec615c99cb07bdc2b379f86679b465bb
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d
|
||||
HASH: b306fbbb65eedbd07aea67a6490db9158a768d8223772d9414b124fe184098ba
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e
|
||||
HASH: de9fc91112ba62a5b732d4b708d6cc27a4b77d88e8f9c50db361c6f27295b46c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f
|
||||
HASH: f3aac26dc5197ea8dc068d6bfc9e3ee2217d908df5115fd236ba31828637ab7a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0
|
||||
HASH: 3a0126ec4db7bd8c0c44e5197a84465c9c97c45f9d1fb8ab256eb5681dc25000
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1
|
||||
HASH: 7b6b55e2623a8eb6d70fa0913012e3db03cea4a6ddc0f5b875673a225f95d86e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2
|
||||
HASH: be3ed738f221b53726d8a54ab7171189d77700bca86a2c614f5fefbca37eb5b0
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3
|
||||
HASH: c90bcb90aea0ab6a2331ecc17f4e68507b544910f3561d20a41916d8abb421db
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4
|
||||
HASH: 72f18a50776c9efbbb1d360342235bf28ab259648dbc08480390333314e02672
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5
|
||||
HASH: 2f1c635728444b5189540cf99d92a77057aed5a8c6fd7deadbbf9d86815cf5f9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6
|
||||
HASH: c372e87d3540fb30e7316af85b65378384de4664a04e51b30ada778e3a226d85
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7
|
||||
HASH: d244f4ce129ef1c84eb40d30da099a2d65682e025e132b94f630fa3fdbda05af
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8
|
||||
HASH: 930a3e1f69ef7bcf3b9a81c1feb9758f60f9086b331fc170e6fa20b2a5738540
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9
|
||||
HASH: 84c3e0415a9d4da972a4fd9ee82d63b00099a2620889bc274ecb8606912cf92f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aa
|
||||
HASH: 6d0d4cde9886218e9240a0c956836ea3939b558b8da0b309ca686f3c631f4942
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaab
|
||||
HASH: 86e476f2f8bacabc996360a0d6d57f0e045c9d3085ffe06d2305601c30d2340c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabac
|
||||
HASH: 6ca5fcf07d2d4b1449924c8c84ad2c2e432a1f923dd365d81d9fde3c4985724f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacad
|
||||
HASH: 9a7e1a3b1e01f24fce4d115eb98e2bb9eef349cf0d40493b8ab33727c9a1ccc8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadae
|
||||
HASH: 165509739c09ec3486143b0c7c009d5b588736aff2813a2dbbfd733d5840ef98
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf
|
||||
HASH: ad191a623337f01563824b493bd735bee26833e9224d971a67b453d6e113d96a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0
|
||||
HASH: f99e6d680bcbc6bb384290a5f966b18d4db38951abe695c6444c319058bb8904
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1
|
||||
HASH: 20e7e81e12c9ad28b7d65d3917051c327031f334a2f82b1f746cbcd7dc41f87d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2
|
||||
HASH: 14675c8fe5cbe514491f7093aad58e9dcf8dd33ab22f3a8bca1ca5130d5e5bea
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3
|
||||
HASH: e105be1caf056cf599b91423df3cc1fb2808e0c6a50da68fc9db5693d1e0a9dc
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4
|
||||
HASH: 8fcade674361487f88d58330acb439a4b3e717341615ba691370becf4905e057
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5
|
||||
HASH: 70251dcdf7c899bddd4bc745597b998506c34bebc5de115d4fe85af2aa420171
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6
|
||||
HASH: d987826931a47b9ff871a0f2a8f10bbb659598da57d8abf81714b48a475a1356
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7
|
||||
HASH: fea31b338415f503dcb3708d68f377c4267e96345158e7b88d24ec8c232ef2b7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8
|
||||
HASH: 3f2084debfeafa75d0c078bed7eda160459a3792a440c3718fb5c14c118e3263
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9
|
||||
HASH: e55583bd588fb053f040c541db36603e4959a7421d6281fca88454720da34c17
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9ba
|
||||
HASH: 0f433de1bbca62440be5d1ceaec8138a2154b374921d17e2d6493f85529a5ee2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babb
|
||||
HASH: 39cc27d72466d2d63f70f28c59950a0665005b4bc8cfaaa662aeeaf34a19601f
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbc
|
||||
HASH: e7a556efdac11394b6058496b06dad0eb7315cae4cbd509e77e496c85f202aa4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbd
|
||||
HASH: b90cf1fd5dbee8a9c18764962bff431dc560e113073828d839e11929d7d602ff
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbe
|
||||
HASH: 62b227effe8222299e757a065f1b64ab73fe6d2aac5d762303db956bc82b78ce
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf
|
||||
HASH: 7b8f54247422c43a6d36977260e195d06e1dbba44c392b3fe76dcf4a96c433d5
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0
|
||||
HASH: d1400c9e8c7758b19e29c38e356ebc7abe8c0887741b845426821c7f74ebd35e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1
|
||||
HASH: 9c557316ebd1e9cde622271e48f654553067c08d58986190bd3108d8bf54f130
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2
|
||||
HASH: f005478fb35b7a389377b35fb6193aab0e9f3c4138127d0905e488a3e5ed1bd6
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3
|
||||
HASH: f62114d69c3bfa8493061f44df01566e3a932e83b050b94eca7a1f7f189d6471
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4
|
||||
HASH: fd915ae6a50c06ba3917bb6d001a4b84c2ff8a906813ba78e80b043a91e7d1d6
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5
|
||||
HASH: 2176a39525e6a57ceed2f28eda5179172ec4f5a15be41b6cece8ab140ff1194c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6
|
||||
HASH: bb831d2653af40b4e8a1048309c1f058d21334aa20c78dc63b8eb74a56fbde3c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7
|
||||
HASH: 63c3d97a9f8894d5e043a707b0fee7f7ec4c049a23bbf1079df20b4165f9e22d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8
|
||||
HASH: 3e53214e700694863284e7dc8dec3b98c1eaf97add0c1431e3bd321d6742a586
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9
|
||||
HASH: cb4e69b8adacdcb20dd2d79655117de489030ecc86c210a268b9985126ca9df3
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9ca
|
||||
HASH: 33eb4a42f46198eb7b52f8fd556fee08430872d3ad16fc3fca466a2d63cc4932
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacb
|
||||
HASH: 4fb1c07cd6e6ed8dbfac72210f3ff9707293dad1f8a4aa19f0ac8ff6c80f3ce9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcc
|
||||
HASH: 22349aa35acbcffa6c84ab0e0231199d8353adde248ca1ff91010234886c94de
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccd
|
||||
HASH: 4ddf8cb3d4e80c9971a9ab171f9bc29fa4fd23eceed01e3bc297892de389d6f7
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdce
|
||||
HASH: 69be23136e4af5f52bb333deb3f32f76610b9fd9dac9ede75b2ef0491bf218ab
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecf
|
||||
HASH: 0b5ce2869ebbbc91bcc4d2e9560bcc21f4da20fffc96cd4eec422b795641c808
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0
|
||||
HASH: 82c17ce6066f792df2dce06eacd03ab4d202185a0a531e4af9a1a2d7b2d43def
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1
|
||||
HASH: 97b1b2e7e7aa6a9d1821ee2ad6c8062af397072eb9a8547c75817d0f0ad1659e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2
|
||||
HASH: 5aa4d29af9903050d5d329d4d7f3a657ccd038543da764ed931560f799690a50
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3
|
||||
HASH: c78b17ff5ea603a809668bc06dbd99b78561b37ff615f6f5e5b86165a442ec2c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4
|
||||
HASH: 2d1f5fb13901a205b158c5dc01bf54a5bfa9914c6b19ab66f501da64975e3a4d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5
|
||||
HASH: ef7d3f61c537cac2a217cc214cd9d3e80f4adaac8431768f9db88a6571d3a57d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6
|
||||
HASH: b23a6eb1184e297b5e9ec2e3aeeaec3c8de411dc614f2979de285ce4d3802e18
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7
|
||||
HASH: 6598f5924005cd92e779a5525636fb061a1cfe4e7afe97d468eb3106817d6c7a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8
|
||||
HASH: f0aec1c2872dff14f3592c5f7e83c0dc4d299f94a7cfb247d0a4b95b9b0fc077
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9
|
||||
HASH: 709da24c1ca042c055a3cff57280d72f2b50094bbf029d9aed1dcca3288022c8
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9da
|
||||
HASH: afb0abb463999cc9ab124c95993d62e839bf7409d91d1c377912a895523c3125
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadb
|
||||
HASH: 049eb53d4bc939e817c9572a5f0def95e4e38b4614969d866e738e3ae6e24936
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdc
|
||||
HASH: 1f9df26fb5219482437297326737c0558eb557da4eb6374805dd9a30f842aae4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdd
|
||||
HASH: 11151481e2199be550f9ae696cbd9ddc9be9686dbc77b619c005d0fb5aef9b89
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcddde
|
||||
HASH: 0767c2de1353f58b416e3fa492173c9c39792de46a34c6153d5878ba01e5f07d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf
|
||||
HASH: 46d743927ec8ad5e403c9e20405200481961e7335e90c4ea9c5ad35b77f3681c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0
|
||||
HASH: d5ffd30325257614674de0b40f7b2ded3a287f48ae229b02c91dd2be28404171
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1
|
||||
HASH: c36f10f2463b839f4bbe7130c8f3abf29a56608bdf767199faccadecc8245631
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2
|
||||
HASH: 4265605e9d5b02fc438c15823bdd01cbcec073d57ad7a699d0126312fdbe4322
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3
|
||||
HASH: 829f989b205831d3c5c002ebf8cea1b5fba3daf966539e3b421b6c2c768f7554
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4
|
||||
HASH: 406a227d2d1767e0cf417d6bf7ca58a262c79460f421b9c155513714187d10d2
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5
|
||||
HASH: adf7d0028e41121e47aef77dca9de82fef7fe4f4c82f2d6df253adb4e756f2ec
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6
|
||||
HASH: b9a11305f92002de551314de53739b1c7e31c257149aee21f3a5ba4af068215d
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7
|
||||
HASH: 49f9abbe9007e85091827b49256730f552e4a2170a7b6f9cc461483bd8ae0d52
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8
|
||||
HASH: 98ebce2d0b548d9fb99fbd63d842c119f2ce671317cd080ee036fa69457fccda
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9
|
||||
HASH: 779042d9184c626289868dc73662e71f413c1df4fecd2f08b0edf40bd8d520f4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9ea
|
||||
HASH: f8ad01320e4bbab09282a97511598384089a447f9a6a8fa298b65a82f1731806
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaeb
|
||||
HASH: 1d799e024fd1627cc0395c68bec456631153bffaeb625cda58411b9cbe137b34
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebec
|
||||
HASH: a9ba7072400dac24052ef744ca60c8273d743af357c851a7016cafd599225672
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebeced
|
||||
HASH: b02147bf83730cc51219f660fe93c63a7463c765395b6721bb842e3ef230e6f5
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedee
|
||||
HASH: b642374d57afa89053dcb7f6e1e72680fb96e3f28adaaf5aed89ab4cfc78214a
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeef
|
||||
HASH: 546b4be370ba614a1761fe8cef8c023d6a7f968981e23a1e8e1168b25cce2efa
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0
|
||||
HASH: 72dab9724f6e174d48e6b8caf489747995d649828a1b1d7a6e8527d9a01523a4
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1
|
||||
HASH: 30b611734127b847bed5c68a867bcded79b2b9da0a358dbe15c4dd578f81e6c0
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2
|
||||
HASH: 986317b1d1afd4692dd533a712718196d412f46a6f3166f417ef01306ab695dd
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3
|
||||
HASH: db6329f783adf7cf5a10e47369fe03c95bcf523558f3aedf18b51a355a252517
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4
|
||||
HASH: 54bb60a43c1e045644420916bac42cc72f86649fe8efeec866cd8e8128a88def
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5
|
||||
HASH: 802875948f79eefb707094e323a0faa2d6d88949a08c044ed3757174492bd2eb
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6
|
||||
HASH: ffc9e261842e1afdaed9f364f125301f20ac8fb0eea556db975211c7db281daa
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7
|
||||
HASH: edfe0aa71067c62e894a516a72dd4bef8c3917e46eb22d39626ea826b90804e9
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8
|
||||
HASH: 98832102b93bab4f82ee872d1dc96d2651ccc9e908c3cf25a56b59cce20319df
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9
|
||||
HASH: 1248d2d1736f1c125c6928bf893f581ea25be6e6e3d3c46081c557de591d6c6c
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fa
|
||||
HASH: 7a01651d8ffa44f6695270c73066ca9d61733ae3c181e3477d11e7c9563594a3
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafb
|
||||
HASH: ced595397cfd128aadbf451002457ff5b0fc2ac3993cabd47f0fc3ddbc6d0f32
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfc
|
||||
HASH: 8797db8dd8ddd1ecbee1f1d71aed5d41adca8345277a7bc0b12df75bb4536722
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfd
|
||||
HASH: 369b09e04be27275df75c180d7283c083162f35456152f0b16ae680dda5195bc
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe
|
||||
HASH: 1d0850ee9bca0abc9601e9deabe1418fedec2fb6ac4150bd5302d2430f9be943
|
||||
|
||||
|
||||
# Longer test vectors
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe
|
||||
HASH: 450eee5f3502c7d5ac7f223d4b4f2c76a11e5bd02d253a37ca9e6e901d5fb56e
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
|
||||
HASH: 6ed9bf545705dba5971e83a1f2a46a9dd5ac2fe8a934f13cee8d353003eaf908
|
||||
|
||||
IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00
|
||||
HASH: a43b19ed8f147f18c304bffeec559e63e83877507cac11924edaf9eb6b6c1bac
|
||||
@@ -1,57 +0,0 @@
|
||||
// Copyright 2015 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
||||
int BN_parse_asn1_unsigned(CBS *cbs, BIGNUM *ret) {
|
||||
CBS child;
|
||||
int is_negative;
|
||||
if (!CBS_get_asn1(cbs, &child, CBS_ASN1_INTEGER) ||
|
||||
!CBS_is_valid_asn1_integer(&child, &is_negative)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_negative) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BN_bin2bn(CBS_data(&child), CBS_len(&child), ret) != NULL;
|
||||
}
|
||||
|
||||
int BN_marshal_asn1(CBB *cbb, const BIGNUM *bn) {
|
||||
// Negative numbers are unsupported.
|
||||
if (BN_is_negative(bn)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_INTEGER) ||
|
||||
// The number must be padded with a leading zero if the high bit would
|
||||
// otherwise be set or if |bn| is zero.
|
||||
(BN_num_bits(bn) % 8 == 0 && !CBB_add_u8(&child, 0x00)) ||
|
||||
!BN_bn2cbb_padded(&child, BN_num_bytes(bn), bn) ||
|
||||
!CBB_flush(cbb)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_ENCODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,407 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
|
||||
|
||||
int BN_bn2cbb_padded(CBB *out, size_t len, const BIGNUM *in) {
|
||||
uint8_t *ptr;
|
||||
return CBB_add_space(out, &ptr, len) && BN_bn2bin_padded(ptr, len, in);
|
||||
}
|
||||
|
||||
static const char hextable[] = "0123456789abcdef";
|
||||
|
||||
char *BN_bn2hex(const BIGNUM *bn) {
|
||||
int width = bn_minimal_width(bn);
|
||||
char *buf = reinterpret_cast<char *>(
|
||||
OPENSSL_malloc(1 /* leading '-' */ + 1 /* zero is non-empty */ +
|
||||
width * BN_BYTES * 2 + 1 /* trailing NUL */));
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *p = buf;
|
||||
if (bn->neg) {
|
||||
*(p++) = '-';
|
||||
}
|
||||
|
||||
if (BN_is_zero(bn)) {
|
||||
*(p++) = '0';
|
||||
}
|
||||
|
||||
int z = 0;
|
||||
for (int i = width - 1; i >= 0; i--) {
|
||||
for (int j = BN_BITS2 - 8; j >= 0; j -= 8) {
|
||||
// strip leading zeros
|
||||
int v = ((int)(bn->d[i] >> (long)j)) & 0xff;
|
||||
if (z || v != 0) {
|
||||
*(p++) = hextable[v >> 4];
|
||||
*(p++) = hextable[v & 0x0f];
|
||||
z = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
// decode_hex decodes |in_len| bytes of hex data from |in| and updates |bn|.
|
||||
static int decode_hex(BIGNUM *bn, const char *in, int in_len) {
|
||||
if (in_len > INT_MAX / 4) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
// |in_len| is the number of hex digits.
|
||||
if (!bn_expand(bn, in_len * 4)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (in_len > 0) {
|
||||
// Decode one |BN_ULONG| at a time.
|
||||
int todo = BN_BYTES * 2;
|
||||
if (todo > in_len) {
|
||||
todo = in_len;
|
||||
}
|
||||
|
||||
BN_ULONG word = 0;
|
||||
int j;
|
||||
for (j = todo; j > 0; j--) {
|
||||
uint8_t hex = 0;
|
||||
if (!OPENSSL_fromxdigit(&hex, in[in_len - j])) {
|
||||
// This shouldn't happen. The caller checks |OPENSSL_isxdigit|.
|
||||
assert(0);
|
||||
}
|
||||
word = (word << 4) | hex;
|
||||
}
|
||||
|
||||
bn->d[i++] = word;
|
||||
in_len -= todo;
|
||||
}
|
||||
assert(i <= bn->dmax);
|
||||
bn->width = i;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// decode_dec decodes |in_len| bytes of decimal data from |in| and updates |bn|.
|
||||
static int decode_dec(BIGNUM *bn, const char *in, int in_len) {
|
||||
int i, j;
|
||||
BN_ULONG l = 0;
|
||||
|
||||
// Decode |BN_DEC_NUM| digits at a time.
|
||||
j = BN_DEC_NUM - (in_len % BN_DEC_NUM);
|
||||
if (j == BN_DEC_NUM) {
|
||||
j = 0;
|
||||
}
|
||||
l = 0;
|
||||
for (i = 0; i < in_len; i++) {
|
||||
l *= 10;
|
||||
l += in[i] - '0';
|
||||
if (++j == BN_DEC_NUM) {
|
||||
if (!BN_mul_word(bn, BN_DEC_CONV) || !BN_add_word(bn, l)) {
|
||||
return 0;
|
||||
}
|
||||
l = 0;
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef int (*decode_func)(BIGNUM *bn, const char *in, int in_len);
|
||||
typedef int (*char_test_func)(int c);
|
||||
|
||||
static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode,
|
||||
char_test_func want_char) {
|
||||
BIGNUM *ret = NULL;
|
||||
int neg = 0, i;
|
||||
int num;
|
||||
|
||||
if (in == NULL || *in == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*in == '-') {
|
||||
neg = 1;
|
||||
in++;
|
||||
}
|
||||
|
||||
for (i = 0; want_char((unsigned char)in[i]) && i + neg < INT_MAX; i++) {
|
||||
}
|
||||
|
||||
num = i + neg;
|
||||
if (outp == NULL) {
|
||||
return num;
|
||||
}
|
||||
|
||||
// in is the start of the hex digits, and it is 'i' long
|
||||
if (*outp == NULL) {
|
||||
ret = BN_new();
|
||||
if (ret == NULL) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
ret = *outp;
|
||||
BN_zero(ret);
|
||||
}
|
||||
|
||||
if (!decode(ret, in, i)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
bn_set_minimal_width(ret);
|
||||
if (!BN_is_zero(ret)) {
|
||||
ret->neg = neg;
|
||||
}
|
||||
|
||||
*outp = ret;
|
||||
return num;
|
||||
|
||||
err:
|
||||
if (*outp == NULL) {
|
||||
BN_free(ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BN_hex2bn(BIGNUM **outp, const char *in) {
|
||||
return bn_x2bn(outp, in, decode_hex, OPENSSL_isxdigit);
|
||||
}
|
||||
|
||||
char *BN_bn2dec(const BIGNUM *a) {
|
||||
// It is easier to print strings little-endian, so we assemble it in reverse
|
||||
// and fix at the end.
|
||||
bssl::ScopedCBB cbb;
|
||||
if (!CBB_init(cbb.get(), 16) || //
|
||||
!CBB_add_u8(cbb.get(), 0 /* trailing NUL */)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (BN_is_zero(a)) {
|
||||
if (!CBB_add_u8(cbb.get(), '0')) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
bssl::UniquePtr<BIGNUM> copy(BN_dup(a));
|
||||
if (copy == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
while (!BN_is_zero(copy.get())) {
|
||||
BN_ULONG word = BN_div_word(copy.get(), BN_DEC_CONV);
|
||||
if (word == (BN_ULONG)-1) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int add_leading_zeros = !BN_is_zero(copy.get());
|
||||
for (int i = 0; i < BN_DEC_NUM && (add_leading_zeros || word != 0); i++) {
|
||||
if (!CBB_add_u8(cbb.get(), '0' + word % 10)) {
|
||||
return nullptr;
|
||||
}
|
||||
word /= 10;
|
||||
}
|
||||
assert(word == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (BN_is_negative(a) && //
|
||||
!CBB_add_u8(cbb.get(), '-')) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
if (!CBB_finish(cbb.get(), &data, &len)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::reverse(data, data + len);
|
||||
return reinterpret_cast<char *>(data);
|
||||
}
|
||||
|
||||
int BN_dec2bn(BIGNUM **outp, const char *in) {
|
||||
return bn_x2bn(outp, in, decode_dec, OPENSSL_isdigit);
|
||||
}
|
||||
|
||||
int BN_asc2bn(BIGNUM **outp, const char *in) {
|
||||
const char *const orig_in = in;
|
||||
if (*in == '-') {
|
||||
in++;
|
||||
}
|
||||
|
||||
if (in[0] == '0' && (in[1] == 'X' || in[1] == 'x')) {
|
||||
if (!BN_hex2bn(outp, in + 2)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!BN_dec2bn(outp, in)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (*orig_in == '-' && !BN_is_zero(*outp)) {
|
||||
(*outp)->neg = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_print(BIO *bp, const BIGNUM *a) {
|
||||
if (a->neg && BIO_write(bp, "-", 1) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BN_is_zero(a) && BIO_write(bp, "0", 1) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int z = 0;
|
||||
for (int i = bn_minimal_width(a) - 1; i >= 0; i--) {
|
||||
for (int j = BN_BITS2 - 4; j >= 0; j -= 4) {
|
||||
// strip leading zeros
|
||||
int v = ((int)(a->d[i] >> (long)j)) & 0x0f;
|
||||
if (z || v != 0) {
|
||||
if (BIO_write(bp, &hextable[v], 1) != 1) {
|
||||
return 0;
|
||||
}
|
||||
z = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_print_fp(FILE *fp, const BIGNUM *a) {
|
||||
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = BN_print(b, a);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
size_t BN_bn2mpi(const BIGNUM *in, uint8_t *out) {
|
||||
const size_t bits = BN_num_bits(in);
|
||||
const size_t bytes = (bits + 7) / 8;
|
||||
// If the number of bits is a multiple of 8, i.e. if the MSB is set,
|
||||
// prefix with a zero byte.
|
||||
int extend = 0;
|
||||
if (bytes != 0 && (bits & 0x07) == 0) {
|
||||
extend = 1;
|
||||
}
|
||||
|
||||
const size_t len = bytes + extend;
|
||||
if (len < bytes || 4 + len < len || (len & 0xffffffff) != len) {
|
||||
// If we cannot represent the number then we emit zero as the interface
|
||||
// doesn't allow an error to be signalled.
|
||||
if (out) {
|
||||
OPENSSL_memset(out, 0, 4);
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (out == NULL) {
|
||||
return 4 + len;
|
||||
}
|
||||
|
||||
out[0] = len >> 24;
|
||||
out[1] = len >> 16;
|
||||
out[2] = len >> 8;
|
||||
out[3] = len;
|
||||
if (extend) {
|
||||
out[4] = 0;
|
||||
}
|
||||
BN_bn2bin(in, out + 4 + extend);
|
||||
if (in->neg && len > 0) {
|
||||
out[4] |= 0x80;
|
||||
}
|
||||
return len + 4;
|
||||
}
|
||||
|
||||
BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
|
||||
if (len < 4) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
const size_t in_len = ((size_t)in[0] << 24) | //
|
||||
((size_t)in[1] << 16) | //
|
||||
((size_t)in[2] << 8) | //
|
||||
((size_t)in[3]);
|
||||
if (in_len != len - 4) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int out_is_alloced = 0;
|
||||
if (out == NULL) {
|
||||
out = BN_new();
|
||||
if (out == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
out_is_alloced = 1;
|
||||
}
|
||||
|
||||
if (in_len == 0) {
|
||||
BN_zero(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
in += 4;
|
||||
if (BN_bin2bn(in, in_len, out) == NULL) {
|
||||
if (out_is_alloced) {
|
||||
BN_free(out);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
out->neg = ((*in) & 0x80) != 0;
|
||||
if (out->neg) {
|
||||
BN_clear_bit(out, BN_num_bits(out) - 1);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
if (len < 0 || //
|
||||
!BN_bn2bin_padded(out, (size_t)len, in)) {
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int BN_bn2lebinpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
if (len < 0 || //
|
||||
!BN_bn2le_padded(out, (size_t)len, in)) {
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
int BN_mod_pow2(BIGNUM *r, const BIGNUM *a, size_t e) {
|
||||
if (e == 0 || a->width == 0) {
|
||||
BN_zero(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t num_words = 1 + ((e - 1) / BN_BITS2);
|
||||
|
||||
// If |a| definitely has less than |e| bits, just BN_copy.
|
||||
if ((size_t)a->width < num_words) {
|
||||
return BN_copy(r, a) != NULL;
|
||||
}
|
||||
|
||||
// Otherwise, first make sure we have enough space in |r|.
|
||||
// Note that this will fail if num_words > INT_MAX.
|
||||
if (!bn_wexpand(r, num_words)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Copy the content of |a| into |r|.
|
||||
OPENSSL_memcpy(r->d, a->d, num_words * sizeof(BN_ULONG));
|
||||
|
||||
// If |e| isn't word-aligned, we have to mask off some of our bits.
|
||||
size_t top_word_exponent = e % (sizeof(BN_ULONG) * 8);
|
||||
if (top_word_exponent != 0) {
|
||||
r->d[num_words - 1] &= (((BN_ULONG)1) << top_word_exponent) - 1;
|
||||
}
|
||||
|
||||
// Fill in the remaining fields of |r|.
|
||||
r->neg = a->neg;
|
||||
r->width = (int)num_words;
|
||||
bn_set_minimal_width(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_nnmod_pow2(BIGNUM *r, const BIGNUM *a, size_t e) {
|
||||
if (!BN_mod_pow2(r, a, e)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the returned value was non-negative, we're done.
|
||||
if (BN_is_zero(r) || !r->neg) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t num_words = 1 + (e - 1) / BN_BITS2;
|
||||
|
||||
// Expand |r| to the size of our modulus.
|
||||
if (!bn_wexpand(r, num_words)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Clear the upper words of |r|.
|
||||
OPENSSL_memset(&r->d[r->width], 0, (num_words - r->width) * BN_BYTES);
|
||||
|
||||
// Set parameters of |r|.
|
||||
r->neg = 0;
|
||||
r->width = (int)num_words;
|
||||
|
||||
// Now, invert every word. The idea here is that we want to compute 2^e-|x|,
|
||||
// which is actually equivalent to the twos-complement representation of |x|
|
||||
// in |e| bits, which is -x = ~x + 1.
|
||||
for (int i = 0; i < r->width; i++) {
|
||||
r->d[i] = ~r->d[i];
|
||||
}
|
||||
|
||||
// If our exponent doesn't span the top word, we have to mask the rest.
|
||||
size_t top_word_exponent = e % BN_BITS2;
|
||||
if (top_word_exponent != 0) {
|
||||
r->d[r->width - 1] &= (((BN_ULONG)1) << top_word_exponent) - 1;
|
||||
}
|
||||
|
||||
// Keep the minimal-width invariant for |BIGNUM|.
|
||||
bn_set_minimal_width(r);
|
||||
|
||||
// Finally, add one, for the reason described above.
|
||||
return BN_add(r, r, BN_value_one());
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
|
||||
|
||||
int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
bssl::BN_CTXScope scope(ctx);
|
||||
BIGNUM *rr;
|
||||
if (r == a || r == p) {
|
||||
rr = BN_CTX_get(ctx);
|
||||
} else {
|
||||
rr = r;
|
||||
}
|
||||
|
||||
BIGNUM *v = BN_CTX_get(ctx);
|
||||
if (rr == NULL || v == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BN_copy(v, a) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
int bits = BN_num_bits(p);
|
||||
|
||||
if (BN_is_odd(p)) {
|
||||
if (BN_copy(rr, a) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!BN_one(rr)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < bits; i++) {
|
||||
if (!BN_sqr(v, v, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
if (BN_is_bit_set(p, i)) {
|
||||
if (!BN_mul(rr, rr, v, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (r != rr && !BN_copy(r, rr)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mod_exp_even(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx) {
|
||||
// No cryptographic operations require modular exponentiation with an even
|
||||
// modulus. We support it for backwards compatibility with any applications
|
||||
// that may have relied on the operation, but optimize for simplicity over
|
||||
// performance with straightforward square-and-multiply routine.
|
||||
int bits = BN_num_bits(p);
|
||||
if (bits == 0) {
|
||||
return BN_one(r);
|
||||
}
|
||||
|
||||
// Make a copy of |a|, in case it aliases |r|.
|
||||
bssl::BN_CTXScope scope(ctx);
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
if (tmp == nullptr || !BN_copy(tmp, a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(BN_is_bit_set(p, bits - 1));
|
||||
if (!BN_copy(r, tmp)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = bits - 2; i >= 0; i--) {
|
||||
if (!BN_mod_sqr(r, r, m, ctx) ||
|
||||
(BN_is_bit_set(p, i) && !BN_mod_mul(r, r, tmp, m, ctx))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
|
||||
BN_CTX *ctx) {
|
||||
if (m->neg) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
if (a->neg || BN_ucmp(a, m) >= 0) {
|
||||
if (!BN_nnmod(r, a, m, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
a = r;
|
||||
}
|
||||
|
||||
if (BN_is_odd(m)) {
|
||||
return BN_mod_exp_mont(r, a, p, m, ctx, NULL);
|
||||
}
|
||||
|
||||
return mod_exp_even(r, a, p, m, ctx);
|
||||
}
|
||||
|
||||
int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
const BN_MONT_CTX *mont) {
|
||||
// BN_mod_exp_mont requires reduced inputs.
|
||||
if (bn_minimal_width(m) == 1) {
|
||||
a %= m->d[0];
|
||||
}
|
||||
|
||||
bssl::UniquePtr<BIGNUM> a_bignum(BN_new());
|
||||
if (a_bignum == nullptr || !BN_set_word(a_bignum.get(), a)) {
|
||||
OPENSSL_PUT_ERROR(BN, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BN_mod_exp_mont(rr, a_bignum.get(), p, m, ctx, mont);
|
||||
}
|
||||
|
||||
int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
|
||||
const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
|
||||
BN_CTX *ctx, const BN_MONT_CTX *mont) {
|
||||
// Allocate a montgomery context if it was not supplied by the caller.
|
||||
bssl::UniquePtr<BN_MONT_CTX> new_mont;
|
||||
if (mont == nullptr) {
|
||||
new_mont.reset(BN_MONT_CTX_new_for_modulus(m, ctx));
|
||||
if (new_mont == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
mont = new_mont.get();
|
||||
}
|
||||
|
||||
// BN_mod_mul_montgomery removes one Montgomery factor, so passing one
|
||||
// Montgomery-encoded and one non-Montgomery-encoded value gives a
|
||||
// non-Montgomery-encoded result.
|
||||
bssl::UniquePtr<BIGNUM> tmp(BN_new());
|
||||
if (tmp == nullptr || //
|
||||
!BN_mod_exp_mont(rr, a1, p1, m, ctx, mont) ||
|
||||
!BN_mod_exp_mont(tmp.get(), a2, p2, m, ctx, mont) ||
|
||||
!BN_to_montgomery(rr, rr, mont, ctx) ||
|
||||
!BN_mod_mul_montgomery(rr, rr, tmp.get(), mont, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
||||
int BN_sqrt(BIGNUM *out_sqrt, const BIGNUM *in, BN_CTX *ctx) {
|
||||
BIGNUM *estimate, *tmp, *delta, *last_delta, *tmp2;
|
||||
int ok = 0, last_delta_valid = 0;
|
||||
|
||||
if (in->neg) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
if (BN_is_zero(in)) {
|
||||
BN_zero(out_sqrt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bssl::BN_CTXScope scope(ctx);
|
||||
if (out_sqrt == in) {
|
||||
estimate = BN_CTX_get(ctx);
|
||||
} else {
|
||||
estimate = out_sqrt;
|
||||
}
|
||||
tmp = BN_CTX_get(ctx);
|
||||
last_delta = BN_CTX_get(ctx);
|
||||
delta = BN_CTX_get(ctx);
|
||||
if (estimate == NULL || tmp == NULL || last_delta == NULL || delta == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// We estimate that the square root of an n-bit number is 2^{n/2}.
|
||||
if (!BN_lshift(estimate, BN_value_one(), BN_num_bits(in)/2)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// This is Newton's method for finding a root of the equation |estimate|^2 -
|
||||
// |in| = 0.
|
||||
for (;;) {
|
||||
// |estimate| = 1/2 * (|estimate| + |in|/|estimate|)
|
||||
if (!BN_div(tmp, NULL, in, estimate, ctx) ||
|
||||
!BN_add(tmp, tmp, estimate) ||
|
||||
!BN_rshift1(estimate, tmp) ||
|
||||
// |tmp| = |estimate|^2
|
||||
!BN_sqr(tmp, estimate, ctx) ||
|
||||
// |delta| = |in| - |tmp|
|
||||
!BN_sub(delta, in, tmp)) {
|
||||
OPENSSL_PUT_ERROR(BN, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
delta->neg = 0;
|
||||
// The difference between |in| and |estimate| squared is required to always
|
||||
// decrease. This ensures that the loop always terminates, but I don't have
|
||||
// a proof that it always finds the square root for a given square.
|
||||
if (last_delta_valid && BN_cmp(delta, last_delta) >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
last_delta_valid = 1;
|
||||
|
||||
tmp2 = last_delta;
|
||||
last_delta = delta;
|
||||
delta = tmp2;
|
||||
}
|
||||
|
||||
if (BN_cmp(tmp, in) != 0) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NOT_A_SQUARE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (ok && out_sqrt == in && !BN_copy(out_sqrt, estimate)) {
|
||||
ok = 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/buf.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
BUF_MEM *BUF_MEM_new(void) {
|
||||
return reinterpret_cast<BUF_MEM *>(OPENSSL_zalloc(sizeof(BUF_MEM)));
|
||||
}
|
||||
|
||||
void BUF_MEM_free(BUF_MEM *buf) {
|
||||
if (buf == nullptr) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(buf->data);
|
||||
OPENSSL_free(buf);
|
||||
}
|
||||
|
||||
int BUF_MEM_reserve(BUF_MEM *buf, size_t cap) {
|
||||
if (buf->max >= cap) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t n = cap + 3;
|
||||
if (n < cap) {
|
||||
OPENSSL_PUT_ERROR(BUF, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
n = n / 3;
|
||||
size_t alloc_size = n * 4;
|
||||
if (alloc_size / 4 != n) {
|
||||
OPENSSL_PUT_ERROR(BUF, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *new_buf =
|
||||
reinterpret_cast<char *>(OPENSSL_realloc(buf->data, alloc_size));
|
||||
if (new_buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf->data = new_buf;
|
||||
buf->max = alloc_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t BUF_MEM_grow(BUF_MEM *buf, size_t len) {
|
||||
if (!BUF_MEM_reserve(buf, len)) {
|
||||
return 0;
|
||||
}
|
||||
if (buf->length < len) {
|
||||
OPENSSL_memset(&buf->data[buf->length], 0, len - buf->length);
|
||||
}
|
||||
buf->length = len;
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len) {
|
||||
return BUF_MEM_grow(buf, len);
|
||||
}
|
||||
|
||||
int BUF_MEM_append(BUF_MEM *buf, const void *in, size_t len) {
|
||||
// Work around a C language bug. See https://crbug.com/1019588.
|
||||
if (len == 0) {
|
||||
return 1;
|
||||
}
|
||||
size_t new_len = buf->length + len;
|
||||
if (new_len < len) {
|
||||
OPENSSL_PUT_ERROR(BUF, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
if (!BUF_MEM_reserve(buf, new_len)) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(buf->data + buf->length, in, len);
|
||||
buf->length = new_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *BUF_strdup(const char *str) { return OPENSSL_strdup(str); }
|
||||
|
||||
size_t BUF_strnlen(const char *str, size_t max_len) {
|
||||
return OPENSSL_strnlen(str, max_len);
|
||||
}
|
||||
|
||||
char *BUF_strndup(const char *str, size_t size) {
|
||||
return OPENSSL_strndup(str, size);
|
||||
}
|
||||
|
||||
size_t BUF_strlcpy(char *dst, const char *src, size_t dst_size) {
|
||||
return OPENSSL_strlcpy(dst, src, dst_size);
|
||||
}
|
||||
|
||||
size_t BUF_strlcat(char *dst, const char *src, size_t dst_size) {
|
||||
return OPENSSL_strlcat(dst, src, dst_size);
|
||||
}
|
||||
|
||||
void *BUF_memdup(const void *data, size_t size) {
|
||||
return OPENSSL_memdup(data, size);
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
// Copyright 2017 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/buf.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
TEST(BufTest, Basic) {
|
||||
bssl::UniquePtr<BUF_MEM> buf(BUF_MEM_new());
|
||||
ASSERT_TRUE(buf);
|
||||
EXPECT_EQ(0u, buf->length);
|
||||
|
||||
// Use BUF_MEM_reserve to increase buf->max.
|
||||
ASSERT_TRUE(BUF_MEM_reserve(buf.get(), 200));
|
||||
EXPECT_GE(buf->max, 200u);
|
||||
EXPECT_EQ(0u, buf->length);
|
||||
|
||||
// BUF_MEM_reserve with a smaller cap is a no-op.
|
||||
size_t old_max = buf->max;
|
||||
ASSERT_TRUE(BUF_MEM_reserve(buf.get(), 100));
|
||||
EXPECT_EQ(old_max, buf->max);
|
||||
EXPECT_EQ(0u, buf->length);
|
||||
|
||||
// BUF_MEM_grow can increase the length without reallocating.
|
||||
ASSERT_EQ(100u, BUF_MEM_grow(buf.get(), 100));
|
||||
EXPECT_EQ(100u, buf->length);
|
||||
EXPECT_EQ(old_max, buf->max);
|
||||
memset(buf->data, 'A', buf->length);
|
||||
|
||||
// If BUF_MEM_reserve reallocates, it preserves the contents.
|
||||
ASSERT_TRUE(BUF_MEM_reserve(buf.get(), old_max + 1));
|
||||
ASSERT_GE(buf->max, old_max + 1);
|
||||
EXPECT_EQ(100u, buf->length);
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
EXPECT_EQ('A', buf->data[i]);
|
||||
}
|
||||
|
||||
// BUF_MEM_grow should zero everything beyond buf->length.
|
||||
memset(buf->data, 'B', buf->max);
|
||||
ASSERT_EQ(150u, BUF_MEM_grow(buf.get(), 150));
|
||||
EXPECT_EQ(150u, buf->length);
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
EXPECT_EQ('B', buf->data[i]);
|
||||
}
|
||||
for (size_t i = 100; i < 150; i++) {
|
||||
EXPECT_EQ(0, buf->data[i]);
|
||||
}
|
||||
|
||||
// BUF_MEM_grow can rellocate if necessary.
|
||||
size_t new_len = buf->max + 1;
|
||||
ASSERT_EQ(new_len, BUF_MEM_grow(buf.get(), new_len));
|
||||
EXPECT_GE(buf->max, new_len);
|
||||
EXPECT_EQ(new_len, buf->length);
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
EXPECT_EQ('B', buf->data[i]);
|
||||
}
|
||||
for (size_t i = 100; i < new_len; i++) {
|
||||
EXPECT_EQ(0, buf->data[i]);
|
||||
}
|
||||
|
||||
// BUF_MEM_grow can shink.
|
||||
ASSERT_EQ(50u, BUF_MEM_grow(buf.get(), 50));
|
||||
EXPECT_EQ(50u, buf->length);
|
||||
for (size_t i = 0; i < 50; i++) {
|
||||
EXPECT_EQ('B', buf->data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BufTest, Append) {
|
||||
bssl::UniquePtr<BUF_MEM> buf(BUF_MEM_new());
|
||||
ASSERT_TRUE(buf);
|
||||
|
||||
ASSERT_TRUE(BUF_MEM_append(buf.get(), nullptr, 0));
|
||||
ASSERT_TRUE(BUF_MEM_append(buf.get(), "hello ", 6));
|
||||
ASSERT_TRUE(BUF_MEM_append(buf.get(), nullptr, 0));
|
||||
ASSERT_TRUE(BUF_MEM_append(buf.get(), "world", 5));
|
||||
std::string str(128, 'A');
|
||||
ASSERT_TRUE(BUF_MEM_append(buf.get(), str.data(), str.size()));
|
||||
|
||||
EXPECT_EQ("hello world" + str, std::string(buf->data, buf->length));
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright 2016 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
int CBB_finish_i2d(CBB *cbb, uint8_t **outp) {
|
||||
assert(!cbb->is_child);
|
||||
assert(cbb->u.base.can_resize);
|
||||
|
||||
uint8_t *der;
|
||||
size_t der_len;
|
||||
if (!CBB_finish(cbb, &der, &der_len)) {
|
||||
CBB_cleanup(cbb);
|
||||
return -1;
|
||||
}
|
||||
if (der_len > INT_MAX) {
|
||||
OPENSSL_free(der);
|
||||
return -1;
|
||||
}
|
||||
if (outp != NULL) {
|
||||
if (*outp == NULL) {
|
||||
*outp = der;
|
||||
der = NULL;
|
||||
} else {
|
||||
OPENSSL_memcpy(*outp, der, der_len);
|
||||
*outp += der_len;
|
||||
}
|
||||
}
|
||||
OPENSSL_free(der);
|
||||
return (int)der_len;
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// kMaxDepth limits the recursion depth to avoid overflowing the stack.
|
||||
static const uint32_t kMaxDepth = 128;
|
||||
|
||||
// is_string_type returns one if |tag| is a string type and zero otherwise. It
|
||||
// ignores the constructed bit.
|
||||
static int is_string_type(CBS_ASN1_TAG 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_OCTETSTRING:
|
||||
case CBS_ASN1_UTF8STRING:
|
||||
case CBS_ASN1_NUMERICSTRING:
|
||||
case CBS_ASN1_PRINTABLESTRING:
|
||||
case CBS_ASN1_T61STRING:
|
||||
case CBS_ASN1_VIDEOTEXSTRING:
|
||||
case CBS_ASN1_IA5STRING:
|
||||
case CBS_ASN1_GRAPHICSTRING:
|
||||
case CBS_ASN1_VISIBLESTRING:
|
||||
case CBS_ASN1_GENERALSTRING:
|
||||
case CBS_ASN1_UNIVERSALSTRING:
|
||||
case CBS_ASN1_BMPSTRING:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// cbs_find_ber walks an ASN.1 structure in |orig_in| and sets |*ber_found|
|
||||
// depending on whether an indefinite length element or constructed string was
|
||||
// found. The value of |orig_in| is not changed. It returns one on success (i.e.
|
||||
// |*ber_found| was set) and zero on error.
|
||||
static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) {
|
||||
if (depth > kMaxDepth) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS in = *orig_in;
|
||||
*ber_found = 0;
|
||||
|
||||
while (CBS_len(&in) > 0) {
|
||||
CBS contents;
|
||||
CBS_ASN1_TAG tag;
|
||||
size_t header_len;
|
||||
int indefinite;
|
||||
if (!CBS_get_any_ber_asn1_element(&in, &contents, &tag, &header_len,
|
||||
ber_found, &indefinite)) {
|
||||
return 0;
|
||||
}
|
||||
if (*ber_found) {
|
||||
return 1;
|
||||
}
|
||||
if (tag & CBS_ASN1_CONSTRUCTED) {
|
||||
if (is_string_type(tag)) {
|
||||
// Constructed strings are only legal in BER and require conversion.
|
||||
*ber_found = 1;
|
||||
return 1;
|
||||
}
|
||||
if (!CBS_skip(&contents, header_len) ||
|
||||
!cbs_find_ber(&contents, ber_found, depth + 1)) {
|
||||
return 0;
|
||||
}
|
||||
if (*ber_found) {
|
||||
// We already found BER. No need to continue parsing.
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// cbs_get_eoc returns one if |cbs| begins with an "end of contents" (EOC) value
|
||||
// and zero otherwise. If an EOC was found, it advances |cbs| past it.
|
||||
static int cbs_get_eoc(CBS *cbs) {
|
||||
if (CBS_len(cbs) >= 2 &&
|
||||
CBS_data(cbs)[0] == 0 && CBS_data(cbs)[1] == 0) {
|
||||
return CBS_skip(cbs, 2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cbs_convert_ber reads BER data from |in| and writes DER data to |out|. If
|
||||
// |string_tag| is non-zero, then all elements must match |string_tag| up to the
|
||||
// constructed bit and primitive element bodies are written to |out| without
|
||||
// element headers. This is used when concatenating the fragments of a
|
||||
// constructed string. If |looking_for_eoc| is set then any EOC elements found
|
||||
// will cause the function to return after consuming it. It returns one on
|
||||
// success and zero on error.
|
||||
static int cbs_convert_ber(CBS *in, CBB *out, CBS_ASN1_TAG string_tag,
|
||||
int looking_for_eoc, uint32_t depth) {
|
||||
assert(!(string_tag & CBS_ASN1_CONSTRUCTED));
|
||||
|
||||
if (depth > kMaxDepth) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (CBS_len(in) > 0) {
|
||||
if (looking_for_eoc && cbs_get_eoc(in)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
CBS contents;
|
||||
CBS_ASN1_TAG tag, child_string_tag = string_tag;
|
||||
size_t header_len;
|
||||
int indefinite;
|
||||
CBB *out_contents, out_contents_storage;
|
||||
if (!CBS_get_any_ber_asn1_element(in, &contents, &tag, &header_len,
|
||||
/*out_ber_found=*/NULL, &indefinite)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (string_tag != 0) {
|
||||
// This is part of a constructed string. All elements must match
|
||||
// |string_tag| up to the constructed bit and get appended to |out|
|
||||
// without a child element.
|
||||
if ((tag & ~CBS_ASN1_CONSTRUCTED) != string_tag) {
|
||||
return 0;
|
||||
}
|
||||
out_contents = out;
|
||||
} else {
|
||||
CBS_ASN1_TAG out_tag = tag;
|
||||
if ((tag & CBS_ASN1_CONSTRUCTED) && is_string_type(tag)) {
|
||||
// If a constructed string, clear the constructed bit and inform
|
||||
// children to concatenate bodies.
|
||||
out_tag &= ~CBS_ASN1_CONSTRUCTED;
|
||||
child_string_tag = out_tag;
|
||||
}
|
||||
if (!CBB_add_asn1(out, &out_contents_storage, out_tag)) {
|
||||
return 0;
|
||||
}
|
||||
out_contents = &out_contents_storage;
|
||||
}
|
||||
|
||||
if (indefinite) {
|
||||
if (!cbs_convert_ber(in, out_contents, child_string_tag,
|
||||
/*looking_for_eoc=*/1, depth + 1) ||
|
||||
!CBB_flush(out)) {
|
||||
return 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!CBS_skip(&contents, header_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tag & CBS_ASN1_CONSTRUCTED) {
|
||||
// Recurse into children.
|
||||
if (!cbs_convert_ber(&contents, out_contents, child_string_tag,
|
||||
/*looking_for_eoc=*/0, depth + 1)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
// Copy primitive contents as-is.
|
||||
if (!CBB_add_bytes(out_contents, CBS_data(&contents),
|
||||
CBS_len(&contents))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!CBB_flush(out)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return looking_for_eoc == 0;
|
||||
}
|
||||
|
||||
int CBS_asn1_ber_to_der(CBS *in, CBS *out, uint8_t **out_storage) {
|
||||
CBB cbb;
|
||||
|
||||
// First, do a quick walk to find any indefinite-length elements. Most of the
|
||||
// time we hope that there aren't any and thus we can quickly return.
|
||||
int conversion_needed;
|
||||
if (!cbs_find_ber(in, &conversion_needed, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!conversion_needed) {
|
||||
if (!CBS_get_any_asn1_element(in, out, NULL, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
*out_storage = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t len;
|
||||
if (!CBB_init(&cbb, CBS_len(in)) ||
|
||||
!cbs_convert_ber(in, &cbb, 0, 0, 0) ||
|
||||
!CBB_finish(&cbb, out_storage, &len)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS_init(out, *out_storage, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_asn1_implicit_string(CBS *in, CBS *out, uint8_t **out_storage,
|
||||
CBS_ASN1_TAG outer_tag,
|
||||
CBS_ASN1_TAG inner_tag) {
|
||||
assert(!(outer_tag & CBS_ASN1_CONSTRUCTED));
|
||||
assert(!(inner_tag & CBS_ASN1_CONSTRUCTED));
|
||||
assert(is_string_type(inner_tag));
|
||||
|
||||
if (CBS_peek_asn1_tag(in, outer_tag)) {
|
||||
// Normal implicitly-tagged string.
|
||||
*out_storage = NULL;
|
||||
return CBS_get_asn1(in, out, outer_tag);
|
||||
}
|
||||
|
||||
// Otherwise, try to parse an implicitly-tagged constructed string.
|
||||
// |CBS_asn1_ber_to_der| is assumed to have run, so only allow one level deep
|
||||
// of nesting.
|
||||
CBB result;
|
||||
CBS child;
|
||||
if (!CBB_init(&result, CBS_len(in)) ||
|
||||
!CBS_get_asn1(in, &child, outer_tag | CBS_ASN1_CONSTRUCTED)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
while (CBS_len(&child) > 0) {
|
||||
CBS chunk;
|
||||
if (!CBS_get_asn1(&child, &chunk, inner_tag) ||
|
||||
!CBB_add_bytes(&result, CBS_data(&chunk), CBS_len(&chunk))) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
if (!CBB_finish(&result, &data, &len)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CBS_init(out, data, len);
|
||||
*out_storage = data;
|
||||
return 1;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&result);
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,708 +0,0 @@
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/bytestring.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
void CBB_zero(CBB *cbb) { OPENSSL_memset(cbb, 0, sizeof(CBB)); }
|
||||
|
||||
static void cbb_init(CBB *cbb, uint8_t *buf, size_t cap, int can_resize) {
|
||||
cbb->is_child = 0;
|
||||
cbb->child = NULL;
|
||||
cbb->u.base.buf = buf;
|
||||
cbb->u.base.len = 0;
|
||||
cbb->u.base.cap = cap;
|
||||
cbb->u.base.can_resize = can_resize;
|
||||
cbb->u.base.error = 0;
|
||||
}
|
||||
|
||||
int CBB_init(CBB *cbb, size_t initial_capacity) {
|
||||
CBB_zero(cbb);
|
||||
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(initial_capacity));
|
||||
if (initial_capacity > 0 && buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cbb_init(cbb, buf, initial_capacity, /*can_resize=*/1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len) {
|
||||
CBB_zero(cbb);
|
||||
cbb_init(cbb, buf, len, /*can_resize=*/0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CBB_cleanup(CBB *cbb) {
|
||||
// Child |CBB|s are non-owning. They are implicitly discarded and should not
|
||||
// be used with |CBB_cleanup| or |ScopedCBB|.
|
||||
assert(!cbb->is_child);
|
||||
if (cbb->is_child) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cbb->u.base.can_resize) {
|
||||
OPENSSL_free(cbb->u.base.buf);
|
||||
}
|
||||
}
|
||||
|
||||
static int cbb_buffer_reserve(struct cbb_buffer_st *base, uint8_t **out,
|
||||
size_t len) {
|
||||
if (base == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t newlen = base->len + len;
|
||||
if (newlen < base->len) {
|
||||
// Overflow
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (newlen > base->cap) {
|
||||
if (!base->can_resize) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
}
|
||||
|
||||
size_t newcap = base->cap * 2;
|
||||
if (newcap < base->cap || newcap < newlen) {
|
||||
newcap = newlen;
|
||||
}
|
||||
uint8_t *newbuf =
|
||||
reinterpret_cast<uint8_t *>(OPENSSL_realloc(base->buf, newcap));
|
||||
if (newbuf == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
base->buf = newbuf;
|
||||
base->cap = newcap;
|
||||
}
|
||||
|
||||
if (out) {
|
||||
*out = base->buf + base->len;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
base->error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cbb_buffer_add(struct cbb_buffer_st *base, uint8_t **out,
|
||||
size_t len) {
|
||||
if (!cbb_buffer_reserve(base, out, len)) {
|
||||
return 0;
|
||||
}
|
||||
// This will not overflow or |cbb_buffer_reserve| would have failed.
|
||||
base->len += len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len) {
|
||||
if (cbb->is_child) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cbb->u.base.can_resize && (out_data == NULL || out_len == NULL)) {
|
||||
// |out_data| and |out_len| can only be NULL if the CBB is fixed.
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (out_data != NULL) {
|
||||
*out_data = cbb->u.base.buf;
|
||||
}
|
||||
if (out_len != NULL) {
|
||||
*out_len = cbb->u.base.len;
|
||||
}
|
||||
cbb->u.base.buf = NULL;
|
||||
CBB_cleanup(cbb);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct cbb_buffer_st *cbb_get_base(CBB *cbb) {
|
||||
if (cbb->is_child) {
|
||||
return cbb->u.child.base;
|
||||
}
|
||||
return &cbb->u.base;
|
||||
}
|
||||
|
||||
static void cbb_on_error(CBB *cbb) {
|
||||
// Due to C's lack of destructors and |CBB|'s auto-flushing API, a failing
|
||||
// |CBB|-taking function may leave a dangling pointer to a child |CBB|. As a
|
||||
// result, the convention is callers may not write to |CBB|s that have failed.
|
||||
// But, as a safety measure, we lock the |CBB| into an error state. Once the
|
||||
// error bit is set, |cbb->child| will not be read.
|
||||
//
|
||||
// TODO(davidben): This still isn't quite ideal. A |CBB| function *outside*
|
||||
// this file may originate an error while the |CBB| points to a local child.
|
||||
// In that case we don't set the error bit and are reliant on the error
|
||||
// convention. Perhaps we allow |CBB_cleanup| on child |CBB|s and make every
|
||||
// child's |CBB_cleanup| set the error bit if unflushed. That will be
|
||||
// convenient for C++ callers, but very tedious for C callers. So C callers
|
||||
// perhaps should get a |CBB_on_error| function that can be, less tediously,
|
||||
// stuck in a |goto err| block.
|
||||
cbb_get_base(cbb)->error = 1;
|
||||
|
||||
// Clearing the pointer is not strictly necessary, but GCC's dangling pointer
|
||||
// warning does not know |cbb->child| will not be read once |error| is set
|
||||
// above.
|
||||
cbb->child = NULL;
|
||||
}
|
||||
|
||||
// CBB_flush recurses and then writes out any pending length prefix. The
|
||||
// current length of the underlying base is taken to be the length of the
|
||||
// length-prefixed data.
|
||||
int CBB_flush(CBB *cbb) {
|
||||
// If |base| has hit an error, the buffer is in an undefined state, so
|
||||
// fail all following calls. In particular, |cbb->child| may point to invalid
|
||||
// memory.
|
||||
struct cbb_buffer_st *base = cbb_get_base(cbb);
|
||||
if (base == NULL || base->error) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cbb->child == NULL) {
|
||||
// Nothing to flush.
|
||||
return 1;
|
||||
}
|
||||
|
||||
assert(cbb->child->is_child);
|
||||
struct cbb_child_st *child = &cbb->child->u.child;
|
||||
assert(child->base == base);
|
||||
size_t child_start = child->offset + child->pending_len_len;
|
||||
|
||||
size_t len;
|
||||
if (!CBB_flush(cbb->child) || child_start < child->offset ||
|
||||
base->len < child_start) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
len = base->len - child_start;
|
||||
|
||||
if (child->pending_is_asn1) {
|
||||
// For ASN.1 we assume that we'll only need a single byte for the length.
|
||||
// If that turned out to be incorrect, we have to move the contents along
|
||||
// in order to make space.
|
||||
uint8_t len_len;
|
||||
uint8_t initial_length_byte;
|
||||
|
||||
assert(child->pending_len_len == 1);
|
||||
|
||||
if (len > 0xfffffffe) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
|
||||
// Too large.
|
||||
goto err;
|
||||
} else if (len > 0xffffff) {
|
||||
len_len = 5;
|
||||
initial_length_byte = 0x80 | 4;
|
||||
} else if (len > 0xffff) {
|
||||
len_len = 4;
|
||||
initial_length_byte = 0x80 | 3;
|
||||
} else if (len > 0xff) {
|
||||
len_len = 3;
|
||||
initial_length_byte = 0x80 | 2;
|
||||
} else if (len > 0x7f) {
|
||||
len_len = 2;
|
||||
initial_length_byte = 0x80 | 1;
|
||||
} else {
|
||||
len_len = 1;
|
||||
initial_length_byte = (uint8_t)len;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
if (len_len != 1) {
|
||||
// We need to move the contents along in order to make space.
|
||||
size_t extra_bytes = len_len - 1;
|
||||
if (!cbb_buffer_add(base, NULL, extra_bytes)) {
|
||||
goto err;
|
||||
}
|
||||
OPENSSL_memmove(base->buf + child_start + extra_bytes,
|
||||
base->buf + child_start, len);
|
||||
}
|
||||
base->buf[child->offset++] = initial_length_byte;
|
||||
child->pending_len_len = len_len - 1;
|
||||
}
|
||||
|
||||
for (size_t i = child->pending_len_len - 1; i < child->pending_len_len; i--) {
|
||||
base->buf[child->offset + i] = (uint8_t)len;
|
||||
len >>= 8;
|
||||
}
|
||||
if (len != 0) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
}
|
||||
|
||||
child->base = NULL;
|
||||
cbb->child = NULL;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint8_t *CBB_data(const CBB *cbb) {
|
||||
assert(cbb->child == NULL);
|
||||
if (cbb->is_child) {
|
||||
return cbb->u.child.base->buf + cbb->u.child.offset +
|
||||
cbb->u.child.pending_len_len;
|
||||
}
|
||||
return cbb->u.base.buf;
|
||||
}
|
||||
|
||||
size_t CBB_len(const CBB *cbb) {
|
||||
assert(cbb->child == NULL);
|
||||
if (cbb->is_child) {
|
||||
assert(cbb->u.child.offset + cbb->u.child.pending_len_len <=
|
||||
cbb->u.child.base->len);
|
||||
return cbb->u.child.base->len - cbb->u.child.offset -
|
||||
cbb->u.child.pending_len_len;
|
||||
}
|
||||
return cbb->u.base.len;
|
||||
}
|
||||
|
||||
static int cbb_add_child(CBB *cbb, CBB *out_child, uint8_t len_len,
|
||||
int is_asn1) {
|
||||
assert(cbb->child == NULL);
|
||||
assert(!is_asn1 || len_len == 1);
|
||||
struct cbb_buffer_st *base = cbb_get_base(cbb);
|
||||
size_t offset = base->len;
|
||||
|
||||
// Reserve space for the length prefix.
|
||||
uint8_t *prefix_bytes;
|
||||
if (!cbb_buffer_add(base, &prefix_bytes, len_len)) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memset(prefix_bytes, 0, len_len);
|
||||
|
||||
CBB_zero(out_child);
|
||||
out_child->is_child = 1;
|
||||
out_child->u.child.base = base;
|
||||
out_child->u.child.offset = offset;
|
||||
out_child->u.child.pending_len_len = len_len;
|
||||
out_child->u.child.pending_is_asn1 = is_asn1;
|
||||
cbb->child = out_child;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cbb_add_length_prefixed(CBB *cbb, CBB *out_contents,
|
||||
uint8_t len_len) {
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return cbb_add_child(cbb, out_contents, len_len, /*is_asn1=*/0);
|
||||
}
|
||||
|
||||
int CBB_add_u8_length_prefixed(CBB *cbb, CBB *out_contents) {
|
||||
return cbb_add_length_prefixed(cbb, out_contents, 1);
|
||||
}
|
||||
|
||||
int CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents) {
|
||||
return cbb_add_length_prefixed(cbb, out_contents, 2);
|
||||
}
|
||||
|
||||
int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents) {
|
||||
return cbb_add_length_prefixed(cbb, out_contents, 3);
|
||||
}
|
||||
|
||||
// add_base128_integer encodes |v| as a big-endian base-128 integer where the
|
||||
// high bit of each byte indicates where there is more data. This is the
|
||||
// encoding used in DER for both high tag number form and OID components.
|
||||
static int add_base128_integer(CBB *cbb, uint64_t v) {
|
||||
unsigned len_len = 0;
|
||||
uint64_t copy = v;
|
||||
while (copy > 0) {
|
||||
len_len++;
|
||||
copy >>= 7;
|
||||
}
|
||||
if (len_len == 0) {
|
||||
len_len = 1; // Zero is encoded with one byte.
|
||||
}
|
||||
for (unsigned i = len_len - 1; i < len_len; i--) {
|
||||
uint8_t byte = (v >> (7 * i)) & 0x7f;
|
||||
if (i != 0) {
|
||||
// The high bit denotes whether there is more data.
|
||||
byte |= 0x80;
|
||||
}
|
||||
if (!CBB_add_u8(cbb, byte)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_add_asn1(CBB *cbb, CBB *out_contents, CBS_ASN1_TAG tag) {
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Split the tag into leading bits and tag number.
|
||||
uint8_t tag_bits = (tag >> CBS_ASN1_TAG_SHIFT) & 0xe0;
|
||||
CBS_ASN1_TAG tag_number = tag & CBS_ASN1_TAG_NUMBER_MASK;
|
||||
if (tag_number >= 0x1f) {
|
||||
// Set all the bits in the tag number to signal high tag number form.
|
||||
if (!CBB_add_u8(cbb, tag_bits | 0x1f) ||
|
||||
!add_base128_integer(cbb, tag_number)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (!CBB_add_u8(cbb, tag_bits | tag_number)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Reserve one byte of length prefix. |CBB_flush| will finish it later.
|
||||
return cbb_add_child(cbb, out_contents, /*len_len=*/1, /*is_asn1=*/1);
|
||||
}
|
||||
|
||||
int CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len) {
|
||||
uint8_t *out;
|
||||
if (!CBB_add_space(cbb, &out, len)) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(out, data, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_add_zeros(CBB *cbb, size_t len) {
|
||||
uint8_t *out;
|
||||
if (!CBB_add_space(cbb, &out, len)) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memset(out, 0, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len) {
|
||||
if (!CBB_flush(cbb) || !cbb_buffer_add(cbb_get_base(cbb), out_data, len)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_reserve(CBB *cbb, uint8_t **out_data, size_t len) {
|
||||
if (!CBB_flush(cbb) ||
|
||||
!cbb_buffer_reserve(cbb_get_base(cbb), out_data, len)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_did_write(CBB *cbb, size_t len) {
|
||||
struct cbb_buffer_st *base = cbb_get_base(cbb);
|
||||
size_t newlen = base->len + len;
|
||||
if (cbb->child != NULL || newlen < base->len || newlen > base->cap) {
|
||||
return 0;
|
||||
}
|
||||
base->len = newlen;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cbb_add_u(CBB *cbb, uint64_t v, size_t len_len) {
|
||||
uint8_t *buf;
|
||||
if (!CBB_add_space(cbb, &buf, len_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t i = len_len - 1; i < len_len; i--) {
|
||||
buf[i] = v;
|
||||
v >>= 8;
|
||||
}
|
||||
|
||||
// |v| must fit in |len_len| bytes.
|
||||
if (v != 0) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_add_u8(CBB *cbb, uint8_t value) { return cbb_add_u(cbb, value, 1); }
|
||||
|
||||
int CBB_add_u16(CBB *cbb, uint16_t value) { return cbb_add_u(cbb, value, 2); }
|
||||
|
||||
int CBB_add_u16le(CBB *cbb, uint16_t value) {
|
||||
return CBB_add_u16(cbb, CRYPTO_bswap2(value));
|
||||
}
|
||||
|
||||
int CBB_add_u24(CBB *cbb, uint32_t value) { return cbb_add_u(cbb, value, 3); }
|
||||
|
||||
int CBB_add_u32(CBB *cbb, uint32_t value) { return cbb_add_u(cbb, value, 4); }
|
||||
|
||||
int CBB_add_u32le(CBB *cbb, uint32_t value) {
|
||||
return CBB_add_u32(cbb, CRYPTO_bswap4(value));
|
||||
}
|
||||
|
||||
int CBB_add_u64(CBB *cbb, uint64_t value) { return cbb_add_u(cbb, value, 8); }
|
||||
|
||||
int CBB_add_u64le(CBB *cbb, uint64_t value) {
|
||||
return CBB_add_u64(cbb, CRYPTO_bswap8(value));
|
||||
}
|
||||
|
||||
void CBB_discard_child(CBB *cbb) {
|
||||
if (cbb->child == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct cbb_buffer_st *base = cbb_get_base(cbb);
|
||||
assert(cbb->child->is_child);
|
||||
base->len = cbb->child->u.child.offset;
|
||||
|
||||
cbb->child->u.child.base = NULL;
|
||||
cbb->child = NULL;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_element(CBB *cbb, CBS_ASN1_TAG tag, const uint8_t *data,
|
||||
size_t data_len) {
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag) ||
|
||||
!CBB_add_bytes(&child, data, data_len) || //
|
||||
!CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
|
||||
return CBB_add_asn1_uint64_with_tag(cbb, value, CBS_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
|
||||
CBB child;
|
||||
int started = 0;
|
||||
if (!CBB_add_asn1(cbb, &child, tag)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
uint8_t byte = (value >> 8 * (7 - i)) & 0xff;
|
||||
if (!started) {
|
||||
if (byte == 0) {
|
||||
// Don't encode leading zeros.
|
||||
continue;
|
||||
}
|
||||
// If the high bit is set, add a padding byte to make it
|
||||
// unsigned.
|
||||
if ((byte & 0x80) && !CBB_add_u8(&child, 0)) {
|
||||
goto err;
|
||||
}
|
||||
started = 1;
|
||||
}
|
||||
if (!CBB_add_u8(&child, byte)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
// 0 is encoded as a single 0, not the empty string.
|
||||
if (!started && !CBB_add_u8(&child, 0)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return CBB_flush(cbb);
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_int64(CBB *cbb, int64_t value) {
|
||||
return CBB_add_asn1_int64_with_tag(cbb, value, CBS_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int CBB_add_asn1_int64_with_tag(CBB *cbb, int64_t value, CBS_ASN1_TAG tag) {
|
||||
if (value >= 0) {
|
||||
return CBB_add_asn1_uint64_with_tag(cbb, (uint64_t)value, tag);
|
||||
}
|
||||
|
||||
uint8_t bytes[sizeof(int64_t)];
|
||||
memcpy(bytes, &value, sizeof(value));
|
||||
int start = 7;
|
||||
// Skip leading sign-extension bytes unless they are necessary.
|
||||
while (start > 0 && (bytes[start] == 0xff && (bytes[start - 1] & 0x80))) {
|
||||
start--;
|
||||
}
|
||||
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag)) {
|
||||
goto err;
|
||||
}
|
||||
for (int i = start; i >= 0; i--) {
|
||||
if (!CBB_add_u8(&child, bytes[i])) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
return CBB_flush(cbb);
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
|
||||
return CBB_add_asn1_element(cbb, CBS_ASN1_OCTETSTRING, data, data_len);
|
||||
}
|
||||
|
||||
int CBB_add_asn1_bool(CBB *cbb, int value) {
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_BOOLEAN) ||
|
||||
!CBB_add_u8(&child, value != 0 ? 0xff : 0) || !CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// parse_dotted_decimal parses one decimal component from |cbs|, where |cbs| is
|
||||
// an OID literal, e.g., "1.2.840.113554.4.1.72585". It consumes both the
|
||||
// component and the dot, so |cbs| may be passed into the function again for the
|
||||
// next value.
|
||||
static int parse_dotted_decimal(CBS *cbs, uint64_t *out) {
|
||||
if (!CBS_get_u64_decimal(cbs, out)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The integer must have either ended at the end of the string, or a
|
||||
// non-terminal dot, which should be consumed. If the string ends with a dot,
|
||||
// this is not a valid OID string.
|
||||
uint8_t dot;
|
||||
return !CBS_get_u8(cbs, &dot) || (dot == '.' && CBS_len(cbs) > 0);
|
||||
}
|
||||
|
||||
int CBB_add_asn1_oid_from_text(CBB *cbb, const char *text, size_t len) {
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)text, len);
|
||||
|
||||
// OIDs must have at least two components.
|
||||
uint64_t a, b;
|
||||
if (!parse_dotted_decimal(&cbs, &a) || !parse_dotted_decimal(&cbs, &b)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first component is encoded as 40 * |a| + |b|. This assumes that |a| is
|
||||
// 0, 1, or 2 and that, when it is 0 or 1, |b| is at most 39.
|
||||
if (a > 2 || (a < 2 && b > 39) || b > UINT64_MAX - 80 ||
|
||||
!add_base128_integer(cbb, 40u * a + b)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The remaining components are encoded unmodified.
|
||||
while (CBS_len(&cbs) > 0) {
|
||||
if (!parse_dotted_decimal(&cbs, &a) || !add_base128_integer(cbb, a)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int compare_set_of_element(const void *a_ptr, const void *b_ptr) {
|
||||
// See X.690, section 11.6 for the ordering. They are sorted in ascending
|
||||
// order by their DER encoding.
|
||||
const CBS *a = reinterpret_cast<const CBS *>(a_ptr),
|
||||
*b = reinterpret_cast<const CBS *>(b_ptr);
|
||||
size_t a_len = CBS_len(a), b_len = CBS_len(b);
|
||||
size_t min_len = a_len < b_len ? a_len : b_len;
|
||||
int ret = OPENSSL_memcmp(CBS_data(a), CBS_data(b), min_len);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
if (a_len == b_len) {
|
||||
return 0;
|
||||
}
|
||||
// If one is a prefix of the other, the shorter one sorts first. (This is not
|
||||
// actually reachable. No DER encoding is a prefix of another DER encoding.)
|
||||
return a_len < b_len ? -1 : 1;
|
||||
}
|
||||
|
||||
int CBB_flush_asn1_set_of(CBB *cbb) {
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
size_t num_children = 0;
|
||||
CBS_init(&cbs, CBB_data(cbb), CBB_len(cbb));
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
if (!CBS_get_any_asn1_element(&cbs, NULL, NULL, NULL)) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
num_children++;
|
||||
}
|
||||
|
||||
if (num_children < 2) {
|
||||
return 1; // Nothing to do. This is the common case for X.509.
|
||||
}
|
||||
|
||||
// Parse out the children and sort. We alias them into a copy of so they
|
||||
// remain valid as we rewrite |cbb|.
|
||||
int ret = 0;
|
||||
size_t buf_len = CBB_len(cbb);
|
||||
uint8_t *buf =
|
||||
reinterpret_cast<uint8_t *>(OPENSSL_memdup(CBB_data(cbb), buf_len));
|
||||
CBS *children =
|
||||
reinterpret_cast<CBS *>(OPENSSL_calloc(num_children, sizeof(CBS)));
|
||||
uint8_t *out;
|
||||
size_t offset = 0;
|
||||
if (buf == NULL || children == NULL) {
|
||||
goto err;
|
||||
}
|
||||
CBS_init(&cbs, buf, buf_len);
|
||||
for (size_t i = 0; i < num_children; i++) {
|
||||
if (!CBS_get_any_asn1_element(&cbs, &children[i], NULL, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
qsort(children, num_children, sizeof(CBS), compare_set_of_element);
|
||||
|
||||
// Write the contents back in the new order.
|
||||
out = (uint8_t *)CBB_data(cbb);
|
||||
for (size_t i = 0; i < num_children; i++) {
|
||||
OPENSSL_memcpy(out + offset, CBS_data(&children[i]), CBS_len(&children[i]));
|
||||
offset += CBS_len(&children[i]);
|
||||
}
|
||||
assert(offset == buf_len);
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(buf);
|
||||
OPENSSL_free(children);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,912 +0,0 @@
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../asn1/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) {
|
||||
if (cbs->len < n) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*p = cbs->data;
|
||||
cbs->data += n;
|
||||
cbs->len -= n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_skip(CBS *cbs, size_t len) {
|
||||
const uint8_t *dummy;
|
||||
return cbs_get(cbs, &dummy, len);
|
||||
}
|
||||
|
||||
int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
|
||||
OPENSSL_free(*out_ptr);
|
||||
*out_ptr = NULL;
|
||||
*out_len = 0;
|
||||
|
||||
if (cbs->len == 0) {
|
||||
return 1;
|
||||
}
|
||||
*out_ptr = reinterpret_cast<uint8_t *>(OPENSSL_memdup(cbs->data, cbs->len));
|
||||
if (*out_ptr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
*out_len = cbs->len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_strdup(const CBS *cbs, char **out_ptr) {
|
||||
if (*out_ptr != NULL) {
|
||||
OPENSSL_free(*out_ptr);
|
||||
}
|
||||
*out_ptr = OPENSSL_strndup((const char *)cbs->data, cbs->len);
|
||||
return (*out_ptr != NULL);
|
||||
}
|
||||
|
||||
int CBS_contains_zero_byte(const CBS *cbs) {
|
||||
return OPENSSL_memchr(cbs->data, 0, cbs->len) != NULL;
|
||||
}
|
||||
|
||||
int CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len) {
|
||||
if (len != cbs->len) {
|
||||
return 0;
|
||||
}
|
||||
return CRYPTO_memcmp(cbs->data, data, len) == 0;
|
||||
}
|
||||
|
||||
static int cbs_get_u(CBS *cbs, uint64_t *out, size_t len) {
|
||||
uint64_t result = 0;
|
||||
const uint8_t *data;
|
||||
|
||||
if (!cbs_get(cbs, &data, len)) {
|
||||
return 0;
|
||||
}
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
result <<= 8;
|
||||
result |= data[i];
|
||||
}
|
||||
*out = result;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u8(CBS *cbs, uint8_t *out) {
|
||||
const uint8_t *v;
|
||||
if (!cbs_get(cbs, &v, 1)) {
|
||||
return 0;
|
||||
}
|
||||
*out = *v;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u16(CBS *cbs, uint16_t *out) {
|
||||
uint64_t v;
|
||||
if (!cbs_get_u(cbs, &v, 2)) {
|
||||
return 0;
|
||||
}
|
||||
*out = v;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u16le(CBS *cbs, uint16_t *out) {
|
||||
if (!CBS_get_u16(cbs, out)) {
|
||||
return 0;
|
||||
}
|
||||
*out = CRYPTO_bswap2(*out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u24(CBS *cbs, uint32_t *out) {
|
||||
uint64_t v;
|
||||
if (!cbs_get_u(cbs, &v, 3)) {
|
||||
return 0;
|
||||
}
|
||||
*out = (uint32_t)v;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u32(CBS *cbs, uint32_t *out) {
|
||||
uint64_t v;
|
||||
if (!cbs_get_u(cbs, &v, 4)) {
|
||||
return 0;
|
||||
}
|
||||
*out = (uint32_t)v;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u32le(CBS *cbs, uint32_t *out) {
|
||||
if (!CBS_get_u32(cbs, out)) {
|
||||
return 0;
|
||||
}
|
||||
*out = CRYPTO_bswap4(*out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u64(CBS *cbs, uint64_t *out) { return cbs_get_u(cbs, out, 8); }
|
||||
|
||||
int CBS_get_u64le(CBS *cbs, uint64_t *out) {
|
||||
if (!cbs_get_u(cbs, out, 8)) {
|
||||
return 0;
|
||||
}
|
||||
*out = CRYPTO_bswap8(*out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_last_u8(CBS *cbs, uint8_t *out) {
|
||||
if (cbs->len == 0) {
|
||||
return 0;
|
||||
}
|
||||
*out = cbs->data[cbs->len - 1];
|
||||
cbs->len--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) {
|
||||
const uint8_t *v;
|
||||
if (!cbs_get(cbs, &v, len)) {
|
||||
return 0;
|
||||
}
|
||||
CBS_init(out, v, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_copy_bytes(CBS *cbs, uint8_t *out, size_t len) {
|
||||
const uint8_t *v;
|
||||
if (!cbs_get(cbs, &v, len)) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(out, v, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len) {
|
||||
uint64_t len;
|
||||
if (!cbs_get_u(cbs, &len, len_len)) {
|
||||
return 0;
|
||||
}
|
||||
// If |len_len| <= 3 then we know that |len| will fit into a |size_t|, even on
|
||||
// 32-bit systems.
|
||||
assert(len_len <= 3);
|
||||
return CBS_get_bytes(cbs, out, len);
|
||||
}
|
||||
|
||||
int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out) {
|
||||
return cbs_get_length_prefixed(cbs, out, 1);
|
||||
}
|
||||
|
||||
int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out) {
|
||||
return cbs_get_length_prefixed(cbs, out, 2);
|
||||
}
|
||||
|
||||
int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) {
|
||||
return cbs_get_length_prefixed(cbs, out, 3);
|
||||
}
|
||||
|
||||
int CBS_get_until_first(CBS *cbs, CBS *out, uint8_t c) {
|
||||
const uint8_t *split = reinterpret_cast<const uint8_t *>(
|
||||
OPENSSL_memchr(CBS_data(cbs), c, CBS_len(cbs)));
|
||||
if (split == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return CBS_get_bytes(cbs, out, split - CBS_data(cbs));
|
||||
}
|
||||
|
||||
int CBS_get_u64_decimal(CBS *cbs, uint64_t *out) {
|
||||
uint64_t v = 0;
|
||||
int seen_digit = 0;
|
||||
while (CBS_len(cbs) != 0) {
|
||||
uint8_t c = CBS_data(cbs)[0];
|
||||
if (!OPENSSL_isdigit(c)) {
|
||||
break;
|
||||
}
|
||||
CBS_skip(cbs, 1);
|
||||
if (/* Forbid stray leading zeros */
|
||||
(v == 0 && seen_digit) ||
|
||||
// Check for overflow.
|
||||
v > UINT64_MAX / 10 || //
|
||||
v * 10 > UINT64_MAX - (c - '0')) {
|
||||
return 0;
|
||||
}
|
||||
v = v * 10 + (c - '0');
|
||||
seen_digit = 1;
|
||||
}
|
||||
|
||||
*out = v;
|
||||
return seen_digit;
|
||||
}
|
||||
|
||||
// parse_base128_integer reads a big-endian base-128 integer from |cbs| and sets
|
||||
// |*out| to the result. This is the encoding used in DER for both high tag
|
||||
// number form and OID components.
|
||||
static int parse_base128_integer(CBS *cbs, uint64_t *out) {
|
||||
uint64_t v = 0;
|
||||
uint8_t b;
|
||||
do {
|
||||
if (!CBS_get_u8(cbs, &b)) {
|
||||
return 0;
|
||||
}
|
||||
if ((v >> (64 - 7)) != 0) {
|
||||
// The value is too large.
|
||||
return 0;
|
||||
}
|
||||
if (v == 0 && b == 0x80) {
|
||||
// The value must be minimally encoded.
|
||||
return 0;
|
||||
}
|
||||
v = (v << 7) | (b & 0x7f);
|
||||
|
||||
// Values end at an octet with the high bit cleared.
|
||||
} while (b & 0x80);
|
||||
|
||||
*out = v;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_asn1_tag(CBS *cbs, CBS_ASN1_TAG *out) {
|
||||
uint8_t tag_byte;
|
||||
if (!CBS_get_u8(cbs, &tag_byte)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ITU-T X.690 section 8.1.2.3 specifies the format for identifiers with a tag
|
||||
// number no greater than 30.
|
||||
//
|
||||
// If the number portion is 31 (0x1f, the largest value that fits in the
|
||||
// allotted bits), then the tag is more than one byte long and the
|
||||
// continuation bytes contain the tag number.
|
||||
CBS_ASN1_TAG tag = ((CBS_ASN1_TAG)tag_byte & 0xe0) << CBS_ASN1_TAG_SHIFT;
|
||||
CBS_ASN1_TAG tag_number = tag_byte & 0x1f;
|
||||
if (tag_number == 0x1f) {
|
||||
uint64_t v;
|
||||
if (!parse_base128_integer(cbs, &v) ||
|
||||
// Check the tag number is within our supported bounds.
|
||||
v > CBS_ASN1_TAG_NUMBER_MASK ||
|
||||
// Small tag numbers should have used low tag number form, even in BER.
|
||||
v < 0x1f) {
|
||||
return 0;
|
||||
}
|
||||
tag_number = (CBS_ASN1_TAG)v;
|
||||
}
|
||||
|
||||
tag |= tag_number;
|
||||
|
||||
// Tag [UNIVERSAL 0] is reserved for use by the encoding. Reject it here to
|
||||
// avoid some ambiguity around ANY values and BER indefinite-length EOCs. See
|
||||
// https://crbug.com/boringssl/455.
|
||||
if ((tag & ~CBS_ASN1_CONSTRUCTED) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out = tag;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag,
|
||||
size_t *out_header_len, int *out_ber_found,
|
||||
int *out_indefinite, int ber_ok) {
|
||||
CBS header = *cbs;
|
||||
CBS throwaway;
|
||||
|
||||
if (out == NULL) {
|
||||
out = &throwaway;
|
||||
}
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 0;
|
||||
*out_indefinite = 0;
|
||||
} else {
|
||||
assert(out_ber_found == NULL);
|
||||
assert(out_indefinite == NULL);
|
||||
}
|
||||
|
||||
CBS_ASN1_TAG tag;
|
||||
if (!parse_asn1_tag(&header, &tag)) {
|
||||
return 0;
|
||||
}
|
||||
if (out_tag != NULL) {
|
||||
*out_tag = tag;
|
||||
}
|
||||
|
||||
uint8_t length_byte;
|
||||
if (!CBS_get_u8(&header, &length_byte)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t header_len = CBS_len(cbs) - CBS_len(&header);
|
||||
|
||||
size_t len;
|
||||
// The format for the length encoding is specified in ITU-T X.690 section
|
||||
// 8.1.3.
|
||||
if ((length_byte & 0x80) == 0) {
|
||||
// Short form length.
|
||||
len = ((size_t)length_byte) + header_len;
|
||||
if (out_header_len != NULL) {
|
||||
*out_header_len = header_len;
|
||||
}
|
||||
} else {
|
||||
// The high bit indicate that this is the long form, while the next 7 bits
|
||||
// encode the number of subsequent octets used to encode the length (ITU-T
|
||||
// X.690 clause 8.1.3.5.b).
|
||||
const size_t num_bytes = length_byte & 0x7f;
|
||||
uint64_t len64;
|
||||
|
||||
if (ber_ok && (tag & CBS_ASN1_CONSTRUCTED) != 0 && num_bytes == 0) {
|
||||
// indefinite length
|
||||
if (out_header_len != NULL) {
|
||||
*out_header_len = header_len;
|
||||
}
|
||||
*out_ber_found = 1;
|
||||
*out_indefinite = 1;
|
||||
return CBS_get_bytes(cbs, out, header_len);
|
||||
}
|
||||
|
||||
// ITU-T X.690 clause 8.1.3.5.c specifies that the value 0xff shall not be
|
||||
// used as the first byte of the length. If this parser encounters that
|
||||
// value, num_bytes will be parsed as 127, which will fail this check.
|
||||
if (num_bytes == 0 || num_bytes > 4) {
|
||||
return 0;
|
||||
}
|
||||
if (!cbs_get_u(&header, &len64, num_bytes)) {
|
||||
return 0;
|
||||
}
|
||||
// ITU-T X.690 section 10.1 (DER length forms) requires encoding the
|
||||
// length with the minimum number of octets. BER could, technically, have
|
||||
// 125 superfluous zero bytes. We do not attempt to handle that and still
|
||||
// require that the length fit in a |uint32_t| for BER.
|
||||
if (len64 < 128) {
|
||||
// Length should have used short-form encoding.
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((len64 >> ((num_bytes - 1) * 8)) == 0) {
|
||||
// Length should have been at least one byte shorter.
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
len = len64;
|
||||
if (len + header_len + num_bytes < len) {
|
||||
// Overflow.
|
||||
return 0;
|
||||
}
|
||||
len += header_len + num_bytes;
|
||||
if (out_header_len != NULL) {
|
||||
*out_header_len = header_len + num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
return CBS_get_bytes(cbs, out, len);
|
||||
}
|
||||
|
||||
int CBS_get_any_asn1(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag) {
|
||||
size_t header_len;
|
||||
if (!CBS_get_any_asn1_element(cbs, out, out_tag, &header_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (out && !CBS_skip(out, header_len)) {
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_any_asn1_element(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag,
|
||||
size_t *out_header_len) {
|
||||
return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, NULL, NULL,
|
||||
/*ber_ok=*/0);
|
||||
}
|
||||
|
||||
int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag,
|
||||
size_t *out_header_len, int *out_ber_found,
|
||||
int *out_indefinite) {
|
||||
int ber_found_temp;
|
||||
return cbs_get_any_asn1_element(
|
||||
cbs, out, out_tag, out_header_len,
|
||||
out_ber_found ? out_ber_found : &ber_found_temp, out_indefinite,
|
||||
/*ber_ok=*/1);
|
||||
}
|
||||
|
||||
static int cbs_get_asn1(CBS *cbs, CBS *out, CBS_ASN1_TAG tag_value,
|
||||
int skip_header) {
|
||||
size_t header_len;
|
||||
CBS_ASN1_TAG tag;
|
||||
CBS throwaway;
|
||||
|
||||
if (out == NULL) {
|
||||
out = &throwaway;
|
||||
}
|
||||
|
||||
if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) ||
|
||||
tag != tag_value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (skip_header && !CBS_skip(out, header_len)) {
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_asn1(CBS *cbs, CBS *out, CBS_ASN1_TAG tag_value) {
|
||||
return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */);
|
||||
}
|
||||
|
||||
int CBS_get_asn1_element(CBS *cbs, CBS *out, CBS_ASN1_TAG tag_value) {
|
||||
return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */);
|
||||
}
|
||||
|
||||
int CBS_peek_asn1_tag(const CBS *cbs, CBS_ASN1_TAG tag_value) {
|
||||
CBS copy = *cbs;
|
||||
CBS_ASN1_TAG actual_tag;
|
||||
return parse_asn1_tag(©, &actual_tag) && tag_value == actual_tag;
|
||||
}
|
||||
|
||||
int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
|
||||
return CBS_get_asn1_uint64_with_tag(cbs, out, CBS_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int CBS_get_asn1_uint64_with_tag(CBS *cbs, uint64_t *out, CBS_ASN1_TAG tag) {
|
||||
CBS bytes;
|
||||
if (!CBS_get_asn1(cbs, &bytes, tag) ||
|
||||
!CBS_is_unsigned_asn1_integer(&bytes)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out = 0;
|
||||
const uint8_t *data = CBS_data(&bytes);
|
||||
size_t len = CBS_len(&bytes);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if ((*out >> 56) != 0) {
|
||||
// Too large to represent as a uint64_t.
|
||||
return 0;
|
||||
}
|
||||
*out <<= 8;
|
||||
*out |= data[i];
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_asn1_int64(CBS *cbs, int64_t *out) {
|
||||
return CBS_get_asn1_int64_with_tag(cbs, out, CBS_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int CBS_get_asn1_int64_with_tag(CBS *cbs, int64_t *out, CBS_ASN1_TAG tag) {
|
||||
int is_negative;
|
||||
CBS bytes;
|
||||
if (!CBS_get_asn1(cbs, &bytes, tag) ||
|
||||
!CBS_is_valid_asn1_integer(&bytes, &is_negative)) {
|
||||
return 0;
|
||||
}
|
||||
const uint8_t *data = CBS_data(&bytes);
|
||||
const size_t len = CBS_len(&bytes);
|
||||
if (len > sizeof(int64_t)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t sign_extend[sizeof(int64_t)];
|
||||
OPENSSL_memset(sign_extend, is_negative ? 0xff : 0, sizeof(sign_extend));
|
||||
OPENSSL_memcpy(sign_extend + sizeof(int64_t) - len, data, len);
|
||||
*out = CRYPTO_load_u64_be(sign_extend);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_asn1_bool(CBS *cbs, int *out) {
|
||||
CBS bytes;
|
||||
if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_BOOLEAN) || CBS_len(&bytes) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint8_t value = *CBS_data(&bytes);
|
||||
if (value != 0 && value != 0xff) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out = !!value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present,
|
||||
CBS_ASN1_TAG tag) {
|
||||
int present = 0;
|
||||
|
||||
if (CBS_peek_asn1_tag(cbs, tag)) {
|
||||
if (!CBS_get_asn1(cbs, out, tag)) {
|
||||
return 0;
|
||||
}
|
||||
present = 1;
|
||||
}
|
||||
|
||||
if (out_present != NULL) {
|
||||
*out_present = present;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,
|
||||
CBS_ASN1_TAG tag) {
|
||||
CBS child;
|
||||
int present;
|
||||
if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
|
||||
return 0;
|
||||
}
|
||||
if (present) {
|
||||
assert(out);
|
||||
if (!CBS_get_asn1(&child, out, CBS_ASN1_OCTETSTRING) ||
|
||||
CBS_len(&child) != 0) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
CBS_init(out, NULL, 0);
|
||||
}
|
||||
if (out_present) {
|
||||
*out_present = present;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, CBS_ASN1_TAG tag,
|
||||
uint64_t default_value) {
|
||||
CBS child;
|
||||
int present;
|
||||
if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
|
||||
return 0;
|
||||
}
|
||||
if (present) {
|
||||
if (!CBS_get_asn1_uint64(&child, out) || CBS_len(&child) != 0) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
*out = default_value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_optional_asn1_bool(CBS *cbs, int *out, CBS_ASN1_TAG tag,
|
||||
int default_value) {
|
||||
CBS child, child2;
|
||||
int present;
|
||||
if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
|
||||
return 0;
|
||||
}
|
||||
if (present) {
|
||||
uint8_t boolean;
|
||||
|
||||
if (!CBS_get_asn1(&child, &child2, CBS_ASN1_BOOLEAN) ||
|
||||
CBS_len(&child2) != 1 || CBS_len(&child) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
boolean = CBS_data(&child2)[0];
|
||||
if (boolean == 0) {
|
||||
*out = 0;
|
||||
} else if (boolean == 0xff) {
|
||||
*out = 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
*out = default_value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_is_valid_asn1_bitstring(const CBS *cbs) {
|
||||
CBS in = *cbs;
|
||||
uint8_t num_unused_bits;
|
||||
if (!CBS_get_u8(&in, &num_unused_bits) || num_unused_bits > 7) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (num_unused_bits == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// All num_unused_bits bits must exist and be zeros.
|
||||
uint8_t last;
|
||||
if (!CBS_get_last_u8(&in, &last) ||
|
||||
(last & ((1 << num_unused_bits) - 1)) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_asn1_bitstring_has_bit(const CBS *cbs, unsigned bit) {
|
||||
if (!CBS_is_valid_asn1_bitstring(cbs)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const unsigned byte_num = (bit >> 3) + 1;
|
||||
const unsigned bit_num = 7 - (bit & 7);
|
||||
|
||||
// Unused bits are zero, and this function does not distinguish between
|
||||
// missing and unset bits. Thus it is sufficient to do a byte-level length
|
||||
// check.
|
||||
return byte_num < CBS_len(cbs) &&
|
||||
(CBS_data(cbs)[byte_num] & (1 << bit_num)) != 0;
|
||||
}
|
||||
|
||||
int CBS_is_valid_asn1_integer(const CBS *cbs, int *out_is_negative) {
|
||||
CBS copy = *cbs;
|
||||
uint8_t first_byte, second_byte;
|
||||
if (!CBS_get_u8(©, &first_byte)) {
|
||||
return 0; // INTEGERs may not be empty.
|
||||
}
|
||||
if (out_is_negative != NULL) {
|
||||
*out_is_negative = (first_byte & 0x80) != 0;
|
||||
}
|
||||
if (!CBS_get_u8(©, &second_byte)) {
|
||||
return 1; // One byte INTEGERs are always minimal.
|
||||
}
|
||||
if ((first_byte == 0x00 && (second_byte & 0x80) == 0) ||
|
||||
(first_byte == 0xff && (second_byte & 0x80) != 0)) {
|
||||
return 0; // The value is minimal iff the first 9 bits are not all equal.
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_is_unsigned_asn1_integer(const CBS *cbs) {
|
||||
int is_negative;
|
||||
return CBS_is_valid_asn1_integer(cbs, &is_negative) && !is_negative;
|
||||
}
|
||||
|
||||
static int add_decimal(CBB *out, uint64_t v) {
|
||||
char buf[DECIMAL_SIZE(uint64_t) + 1];
|
||||
snprintf(buf, sizeof(buf), "%" PRIu64, v);
|
||||
return CBB_add_bytes(out, (const uint8_t *)buf, strlen(buf));
|
||||
}
|
||||
|
||||
int CBS_is_valid_asn1_oid(const CBS *cbs) {
|
||||
if (CBS_len(cbs) == 0) {
|
||||
return 0; // OID encodings cannot be empty.
|
||||
}
|
||||
|
||||
CBS copy = *cbs;
|
||||
uint8_t v, prev = 0;
|
||||
while (CBS_get_u8(©, &v)) {
|
||||
// OID encodings are a sequence of minimally-encoded base-128 integers (see
|
||||
// |parse_base128_integer|). If |prev|'s MSB was clear, it was the last byte
|
||||
// of an integer (or |v| is the first byte). |v| is then the first byte of
|
||||
// the next integer. If first byte of an integer is 0x80, it is not
|
||||
// minimally-encoded.
|
||||
if ((prev & 0x80) == 0 && v == 0x80) {
|
||||
return 0;
|
||||
}
|
||||
prev = v;
|
||||
}
|
||||
|
||||
// The last byte should must end an integer encoding.
|
||||
return (prev & 0x80) == 0;
|
||||
}
|
||||
|
||||
char *CBS_asn1_oid_to_text(const CBS *cbs) {
|
||||
CBS copy = *cbs;
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, 32)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// The first component is 40 * value1 + value2, where value1 is 0, 1, or 2.
|
||||
uint64_t v;
|
||||
if (!parse_base128_integer(©, &v)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (v >= 80) {
|
||||
if (!CBB_add_bytes(&cbb, (const uint8_t *)"2.", 2) ||
|
||||
!add_decimal(&cbb, v - 80)) {
|
||||
goto err;
|
||||
}
|
||||
} else if (!add_decimal(&cbb, v / 40) || !CBB_add_u8(&cbb, '.') ||
|
||||
!add_decimal(&cbb, v % 40)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
while (CBS_len(©) != 0) {
|
||||
if (!parse_base128_integer(©, &v) || !CBB_add_u8(&cbb, '.') ||
|
||||
!add_decimal(&cbb, v)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *txt;
|
||||
size_t txt_len;
|
||||
if (!CBB_add_u8(&cbb, '\0') || !CBB_finish(&cbb, &txt, &txt_len)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return (char *)txt;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&cbb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int cbs_get_two_digits(CBS *cbs, int *out) {
|
||||
uint8_t first_digit, second_digit;
|
||||
if (!CBS_get_u8(cbs, &first_digit)) {
|
||||
return 0;
|
||||
}
|
||||
if (!OPENSSL_isdigit(first_digit)) {
|
||||
return 0;
|
||||
}
|
||||
if (!CBS_get_u8(cbs, &second_digit)) {
|
||||
return 0;
|
||||
}
|
||||
if (!OPENSSL_isdigit(second_digit)) {
|
||||
return 0;
|
||||
}
|
||||
*out = (first_digit - '0') * 10 + (second_digit - '0');
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int is_valid_day(int year, int month, int day) {
|
||||
if (day < 1) {
|
||||
return 0;
|
||||
}
|
||||
switch (month) {
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
return day <= 31;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
return day <= 30;
|
||||
case 2:
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
|
||||
return day <= 29;
|
||||
} else {
|
||||
return day <= 28;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int CBS_parse_rfc5280_time_internal(const CBS *cbs, int is_gentime,
|
||||
int allow_timezone_offset,
|
||||
struct tm *out_tm) {
|
||||
int year, month, day, hour, min, sec, tmp;
|
||||
CBS copy = *cbs;
|
||||
uint8_t tz;
|
||||
|
||||
if (is_gentime) {
|
||||
if (!cbs_get_two_digits(©, &tmp)) {
|
||||
return 0;
|
||||
}
|
||||
year = tmp * 100;
|
||||
if (!cbs_get_two_digits(©, &tmp)) {
|
||||
return 0;
|
||||
}
|
||||
year += tmp;
|
||||
} else {
|
||||
year = 1900;
|
||||
if (!cbs_get_two_digits(©, &tmp)) {
|
||||
return 0;
|
||||
}
|
||||
year += tmp;
|
||||
if (year < 1950) {
|
||||
year += 100;
|
||||
}
|
||||
if (year >= 2050) {
|
||||
return 0; // A Generalized time must be used.
|
||||
}
|
||||
}
|
||||
if (!cbs_get_two_digits(©, &month) || month < 1 ||
|
||||
month > 12 || // Reject invalid months.
|
||||
!cbs_get_two_digits(©, &day) ||
|
||||
!is_valid_day(year, month, day) || // Reject invalid days.
|
||||
!cbs_get_two_digits(©, &hour) ||
|
||||
hour > 23 || // Reject invalid hours.
|
||||
!cbs_get_two_digits(©, &min) ||
|
||||
min > 59 || // Reject invalid minutes.
|
||||
!cbs_get_two_digits(©, &sec) || sec > 59 || !CBS_get_u8(©, &tz)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int offset_sign = 0;
|
||||
switch (tz) {
|
||||
case 'Z':
|
||||
break; // We correctly have 'Z' on the end as per spec.
|
||||
case '+':
|
||||
offset_sign = 1;
|
||||
break; // Should not be allowed per RFC 5280.
|
||||
case '-':
|
||||
offset_sign = -1;
|
||||
break; // Should not be allowed per RFC 5280.
|
||||
default:
|
||||
return 0; // Reject anything else after the time.
|
||||
}
|
||||
|
||||
// If allow_timezone_offset is non-zero, allow for a four digit timezone
|
||||
// offset to be specified even though this is not allowed by RFC 5280. We are
|
||||
// permissive of this for UTCTimes due to the unfortunate existence of
|
||||
// artisinally rolled long lived certificates that were baked into places that
|
||||
// are now difficult to change. These certificates were generated with the
|
||||
// 'openssl' command that permissively allowed the creation of certificates
|
||||
// with notBefore and notAfter times specified as strings for direct
|
||||
// certificate inclusion on the command line. For context see cl/237068815.
|
||||
//
|
||||
// TODO(bbe): This has been expunged from public web-pki as the ecosystem has
|
||||
// managed to encourage CA compliance with standards. We should find a way to
|
||||
// get rid of this or make it off by default.
|
||||
int offset_seconds = 0;
|
||||
if (offset_sign != 0) {
|
||||
if (!allow_timezone_offset) {
|
||||
return 0;
|
||||
}
|
||||
int offset_hours, offset_minutes;
|
||||
if (!cbs_get_two_digits(©, &offset_hours) ||
|
||||
offset_hours > 23 || // Reject invalid hours.
|
||||
!cbs_get_two_digits(©, &offset_minutes) ||
|
||||
offset_minutes > 59) { // Reject invalid minutes.
|
||||
return 0;
|
||||
}
|
||||
offset_seconds = offset_sign * (offset_hours * 3600 + offset_minutes * 60);
|
||||
}
|
||||
|
||||
if (CBS_len(©) != 0) {
|
||||
return 0; // Reject invalid lengths.
|
||||
}
|
||||
|
||||
if (out_tm != NULL) {
|
||||
// Fill in the tm fields corresponding to what we validated.
|
||||
out_tm->tm_year = year - 1900;
|
||||
out_tm->tm_mon = month - 1;
|
||||
out_tm->tm_mday = day;
|
||||
out_tm->tm_hour = hour;
|
||||
out_tm->tm_min = min;
|
||||
out_tm->tm_sec = sec;
|
||||
if (offset_seconds && !OPENSSL_gmtime_adj(out_tm, 0, offset_seconds)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_parse_generalized_time(const CBS *cbs, struct tm *out_tm,
|
||||
int allow_timezone_offset) {
|
||||
return CBS_parse_rfc5280_time_internal(cbs, 1, allow_timezone_offset, out_tm);
|
||||
}
|
||||
|
||||
int CBS_parse_utc_time(const CBS *cbs, struct tm *out_tm,
|
||||
int allow_timezone_offset) {
|
||||
return CBS_parse_rfc5280_time_internal(cbs, 0, allow_timezone_offset, out_tm);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user