...

Text file src/crypto/internal/boring/goboringcrypto.h

Documentation: crypto/internal/boring

     1// Copyright 2017 The Go Authors. All rights reserved.
     2// Use of this source code is governed by a BSD-style
     3// license that can be found in the LICENSE file.
     4
     5// This header file describes the BoringCrypto ABI as built for use in Go.
     6// The BoringCrypto build for Go (which generates goboringcrypto_*.syso)
     7// takes the standard libcrypto.a from BoringCrypto and adds the prefix
     8// _goboringcrypto_ to every symbol, to avoid possible conflicts with
     9// code wrapping a different BoringCrypto or OpenSSL.
    10//
    11// To make this header standalone (so that building Go does not require
    12// having a full set of BoringCrypto headers), the struct details are not here.
    13// Instead, while building the syso, we compile and run a C++ program
    14// that checks that the sizes match. The program also checks (during compilation)
    15// that all the function prototypes match the BoringCrypto equivalents.
    16// The generation of the checking program depends on the declaration
    17// forms used below (one line for most, multiline for enums).
    18
    19#include <stdlib.h> // size_t
    20#include <stdint.h> // uint8_t
    21
    22// This symbol is hidden in BoringCrypto and marked as a constructor,
    23// but cmd/link's internal linking mode doesn't handle constructors.
    24// Until it does, we've exported the symbol and can call it explicitly.
    25// (If using external linking mode, it will therefore be called twice,
    26// once explicitly and once as a constructor, but that's OK.)
    27/*unchecked*/ void _goboringcrypto_BORINGSSL_bcm_power_on_self_test(void);
    28
    29// #include <openssl/crypto.h>
    30int _goboringcrypto_FIPS_mode(void);
    31void* _goboringcrypto_OPENSSL_malloc(size_t);
    32
    33// #include <openssl/rand.h>
    34int _goboringcrypto_RAND_bytes(uint8_t*, size_t);
    35
    36// #include <openssl/nid.h>
    37enum {
    38	GO_NID_md5_sha1 = 114,
    39
    40	GO_NID_secp224r1 = 713,
    41	GO_NID_X9_62_prime256v1 = 415,
    42	GO_NID_secp384r1 = 715,
    43	GO_NID_secp521r1 = 716,
    44
    45	GO_NID_sha224 = 675,
    46	GO_NID_sha256 = 672,
    47	GO_NID_sha384 = 673,
    48	GO_NID_sha512 = 674,
    49};
    50
    51// #include <openssl/sha.h>
    52typedef struct GO_SHA_CTX { char data[96]; } GO_SHA_CTX;
    53int _goboringcrypto_SHA1_Init(GO_SHA_CTX*);
    54int _goboringcrypto_SHA1_Update(GO_SHA_CTX*, const void*, size_t);
    55int _goboringcrypto_SHA1_Final(uint8_t*, GO_SHA_CTX*);
    56
    57typedef struct GO_SHA256_CTX { char data[48+64]; } GO_SHA256_CTX;
    58int _goboringcrypto_SHA224_Init(GO_SHA256_CTX*);
    59int _goboringcrypto_SHA224_Update(GO_SHA256_CTX*, const void*, size_t);
    60int _goboringcrypto_SHA224_Final(uint8_t*, GO_SHA256_CTX*);
    61int _goboringcrypto_SHA256_Init(GO_SHA256_CTX*);
    62int _goboringcrypto_SHA256_Update(GO_SHA256_CTX*, const void*, size_t);
    63int _goboringcrypto_SHA256_Final(uint8_t*, GO_SHA256_CTX*);
    64
    65typedef struct GO_SHA512_CTX { char data[88+128]; } GO_SHA512_CTX;
    66int _goboringcrypto_SHA384_Init(GO_SHA512_CTX*);
    67int _goboringcrypto_SHA384_Update(GO_SHA512_CTX*, const void*, size_t);
    68int _goboringcrypto_SHA384_Final(uint8_t*, GO_SHA512_CTX*);
    69int _goboringcrypto_SHA512_Init(GO_SHA512_CTX*);
    70int _goboringcrypto_SHA512_Update(GO_SHA512_CTX*, const void*, size_t);
    71int _goboringcrypto_SHA512_Final(uint8_t*, GO_SHA512_CTX*);
    72
    73// #include <openssl/digest.h>
    74/*unchecked (opaque)*/ typedef struct GO_EVP_MD { char data[1]; } GO_EVP_MD;
    75const GO_EVP_MD* _goboringcrypto_EVP_md4(void);
    76const GO_EVP_MD* _goboringcrypto_EVP_md5(void);
    77const GO_EVP_MD* _goboringcrypto_EVP_md5_sha1(void);
    78const GO_EVP_MD* _goboringcrypto_EVP_sha1(void);
    79const GO_EVP_MD* _goboringcrypto_EVP_sha224(void);
    80const GO_EVP_MD* _goboringcrypto_EVP_sha256(void);
    81const GO_EVP_MD* _goboringcrypto_EVP_sha384(void);
    82const GO_EVP_MD* _goboringcrypto_EVP_sha512(void);
    83int _goboringcrypto_EVP_MD_type(const GO_EVP_MD*);
    84size_t _goboringcrypto_EVP_MD_size(const GO_EVP_MD*);
    85
    86// #include <openssl/hmac.h>
    87typedef struct GO_HMAC_CTX { char data[104]; } GO_HMAC_CTX;
    88void _goboringcrypto_HMAC_CTX_init(GO_HMAC_CTX*);
    89void _goboringcrypto_HMAC_CTX_cleanup(GO_HMAC_CTX*);
    90int _goboringcrypto_HMAC_Init(GO_HMAC_CTX*, const void*, int, const GO_EVP_MD*);
    91int _goboringcrypto_HMAC_Update(GO_HMAC_CTX*, const uint8_t*, size_t);
    92int _goboringcrypto_HMAC_Final(GO_HMAC_CTX*, uint8_t*, unsigned int*);
    93size_t _goboringcrypto_HMAC_size(const GO_HMAC_CTX*);
    94int _goboringcrypto_HMAC_CTX_copy_ex(GO_HMAC_CTX *dest, const GO_HMAC_CTX *src);
    95
    96// #include <openssl/aes.h>
    97typedef struct GO_AES_KEY { char data[244]; } GO_AES_KEY;
    98int _goboringcrypto_AES_set_encrypt_key(const uint8_t*, unsigned int, GO_AES_KEY*);
    99int _goboringcrypto_AES_set_decrypt_key(const uint8_t*, unsigned int, GO_AES_KEY*);
   100void _goboringcrypto_AES_encrypt(const uint8_t*, uint8_t*, const GO_AES_KEY*);
   101void _goboringcrypto_AES_decrypt(const uint8_t*, uint8_t*, const GO_AES_KEY*);
   102void _goboringcrypto_AES_ctr128_encrypt(const uint8_t*, uint8_t*, size_t, const GO_AES_KEY*, uint8_t*, uint8_t*, unsigned int*);
   103enum {
   104	GO_AES_ENCRYPT = 1,
   105	GO_AES_DECRYPT = 0
   106};
   107void _goboringcrypto_AES_cbc_encrypt(const uint8_t*, uint8_t*, size_t, const GO_AES_KEY*, uint8_t*, const int);
   108
   109// #include <openssl/aead.h>
   110/*unchecked (opaque)*/ typedef struct GO_EVP_AEAD { char data[1]; } GO_EVP_AEAD;
   111/*unchecked (opaque)*/ typedef struct GO_ENGINE { char data[1]; } GO_ENGINE;
   112const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm(void);
   113const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm(void);
   114enum {
   115	GO_EVP_AEAD_DEFAULT_TAG_LENGTH = 0
   116};
   117size_t _goboringcrypto_EVP_AEAD_key_length(const GO_EVP_AEAD*);
   118size_t _goboringcrypto_EVP_AEAD_nonce_length(const GO_EVP_AEAD*);
   119size_t _goboringcrypto_EVP_AEAD_max_overhead(const GO_EVP_AEAD*);
   120size_t _goboringcrypto_EVP_AEAD_max_tag_len(const GO_EVP_AEAD*);
   121typedef struct GO_EVP_AEAD_CTX { char data[600]; } GO_EVP_AEAD_CTX;
   122void _goboringcrypto_EVP_AEAD_CTX_zero(GO_EVP_AEAD_CTX*);
   123int _goboringcrypto_EVP_AEAD_CTX_init(GO_EVP_AEAD_CTX*, const GO_EVP_AEAD*, const uint8_t*, size_t, size_t, GO_ENGINE*);
   124void _goboringcrypto_EVP_AEAD_CTX_cleanup(GO_EVP_AEAD_CTX*);
   125int _goboringcrypto_EVP_AEAD_CTX_seal(const GO_EVP_AEAD_CTX*, uint8_t*, size_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t);
   126int _goboringcrypto_EVP_AEAD_CTX_open(const GO_EVP_AEAD_CTX*, uint8_t*, size_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t);
   127const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm_tls12(void);
   128const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm_tls13(void);
   129const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls12(void);
   130const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls13(void);
   131enum go_evp_aead_direction_t {
   132	go_evp_aead_open = 0,
   133	go_evp_aead_seal = 1
   134};
   135int _goboringcrypto_EVP_AEAD_CTX_init_with_direction(GO_EVP_AEAD_CTX*, const GO_EVP_AEAD*, const uint8_t*, size_t, size_t, enum go_evp_aead_direction_t);
   136
   137// #include <openssl/bn.h>
   138/*unchecked (opaque)*/ typedef struct GO_BN_CTX { char data[1]; } GO_BN_CTX;
   139typedef struct GO_BIGNUM { char data[24]; } GO_BIGNUM;
   140GO_BIGNUM* _goboringcrypto_BN_new(void);
   141void _goboringcrypto_BN_free(GO_BIGNUM*);
   142unsigned _goboringcrypto_BN_num_bits(const GO_BIGNUM*);
   143unsigned _goboringcrypto_BN_num_bytes(const GO_BIGNUM*);
   144int _goboringcrypto_BN_is_negative(const GO_BIGNUM*);
   145GO_BIGNUM* _goboringcrypto_BN_bin2bn(const uint8_t*, size_t, GO_BIGNUM*);
   146GO_BIGNUM* _goboringcrypto_BN_le2bn(const uint8_t*, size_t, GO_BIGNUM*);
   147size_t _goboringcrypto_BN_bn2bin(const GO_BIGNUM*, uint8_t*);
   148int _goboringcrypto_BN_bn2le_padded(uint8_t*, size_t, const GO_BIGNUM*);
   149int _goboringcrypto_BN_bn2bin_padded(uint8_t*, size_t, const GO_BIGNUM*);
   150
   151// #include <openssl/ec.h>
   152/*unchecked (opaque)*/ typedef struct GO_EC_GROUP { char data[1]; } GO_EC_GROUP;
   153GO_EC_GROUP* _goboringcrypto_EC_GROUP_new_by_curve_name(int);
   154void _goboringcrypto_EC_GROUP_free(GO_EC_GROUP*);
   155
   156/*unchecked (opaque)*/ typedef struct GO_EC_POINT { char data[1]; } GO_EC_POINT;
   157GO_EC_POINT* _goboringcrypto_EC_POINT_new(const GO_EC_GROUP*);
   158int _goboringcrypto_EC_POINT_mul(const GO_EC_GROUP*, GO_EC_POINT*, const GO_BIGNUM*, const GO_EC_POINT*, const GO_BIGNUM*, GO_BN_CTX*);
   159void _goboringcrypto_EC_POINT_free(GO_EC_POINT*);
   160int _goboringcrypto_EC_POINT_get_affine_coordinates_GFp(const GO_EC_GROUP*, const GO_EC_POINT*, GO_BIGNUM*, GO_BIGNUM*, GO_BN_CTX*);
   161int _goboringcrypto_EC_POINT_set_affine_coordinates_GFp(const GO_EC_GROUP*, GO_EC_POINT*, const GO_BIGNUM*, const GO_BIGNUM*, GO_BN_CTX*);
   162int _goboringcrypto_EC_POINT_oct2point(const GO_EC_GROUP*, GO_EC_POINT*, const uint8_t*, size_t, GO_BN_CTX*);
   163GO_EC_POINT* _goboringcrypto_EC_POINT_dup(const GO_EC_POINT*, const GO_EC_GROUP*);
   164int _goboringcrypto_EC_POINT_is_on_curve(const GO_EC_GROUP*, const GO_EC_POINT*, GO_BN_CTX*);
   165#ifndef OPENSSL_HEADER_EC_H
   166typedef enum {
   167	GO_POINT_CONVERSION_COMPRESSED = 2,
   168	GO_POINT_CONVERSION_UNCOMPRESSED = 4,
   169	GO_POINT_CONVERSION_HYBRID = 6,
   170} go_point_conversion_form_t;
   171#endif
   172size_t _goboringcrypto_EC_POINT_point2oct(const GO_EC_GROUP*, const GO_EC_POINT*, go_point_conversion_form_t, uint8_t*, size_t, GO_BN_CTX*);
   173
   174// #include <openssl/ec_key.h>
   175/*unchecked (opaque)*/ typedef struct GO_EC_KEY { char data[1]; } GO_EC_KEY;
   176GO_EC_KEY* _goboringcrypto_EC_KEY_new(void);
   177GO_EC_KEY* _goboringcrypto_EC_KEY_new_by_curve_name(int);
   178void _goboringcrypto_EC_KEY_free(GO_EC_KEY*);
   179const GO_EC_GROUP* _goboringcrypto_EC_KEY_get0_group(const GO_EC_KEY*);
   180int _goboringcrypto_EC_KEY_generate_key_fips(GO_EC_KEY*);
   181int _goboringcrypto_EC_KEY_set_private_key(GO_EC_KEY*, const GO_BIGNUM*);
   182int _goboringcrypto_EC_KEY_set_public_key(GO_EC_KEY*, const GO_EC_POINT*);
   183int _goboringcrypto_EC_KEY_is_opaque(const GO_EC_KEY*);
   184const GO_BIGNUM* _goboringcrypto_EC_KEY_get0_private_key(const GO_EC_KEY*);
   185const GO_EC_POINT* _goboringcrypto_EC_KEY_get0_public_key(const GO_EC_KEY*);
   186// TODO: EC_KEY_check_fips?
   187
   188// #include <openssl/ecdh.h>
   189int _goboringcrypto_ECDH_compute_key_fips(uint8_t*, size_t, const GO_EC_POINT*, const GO_EC_KEY*);
   190
   191// #include <openssl/ecdsa.h>
   192typedef struct GO_ECDSA_SIG { char data[16]; } GO_ECDSA_SIG;
   193GO_ECDSA_SIG* _goboringcrypto_ECDSA_SIG_new(void);
   194void _goboringcrypto_ECDSA_SIG_free(GO_ECDSA_SIG*);
   195GO_ECDSA_SIG* _goboringcrypto_ECDSA_do_sign(const uint8_t*, size_t, const GO_EC_KEY*);
   196int _goboringcrypto_ECDSA_do_verify(const uint8_t*, size_t, const GO_ECDSA_SIG*, const GO_EC_KEY*);
   197int _goboringcrypto_ECDSA_sign(int, const uint8_t*, size_t, uint8_t*, unsigned int*, const GO_EC_KEY*);
   198size_t _goboringcrypto_ECDSA_size(const GO_EC_KEY*);
   199int _goboringcrypto_ECDSA_verify(int, const uint8_t*, size_t, const uint8_t*, size_t, const GO_EC_KEY*);
   200
   201// #include <openssl/rsa.h>
   202
   203// Note: order of struct fields here is unchecked.
   204typedef struct GO_RSA { void *meth; GO_BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; char data[168]; } GO_RSA;
   205/*unchecked (opaque)*/ typedef struct GO_BN_GENCB { char data[1]; } GO_BN_GENCB;
   206GO_RSA* _goboringcrypto_RSA_new(void);
   207void _goboringcrypto_RSA_free(GO_RSA*);
   208void _goboringcrypto_RSA_get0_key(const GO_RSA*, const GO_BIGNUM **n, const GO_BIGNUM **e, const GO_BIGNUM **d);
   209void _goboringcrypto_RSA_get0_factors(const GO_RSA*, const GO_BIGNUM **p, const GO_BIGNUM **q);
   210void _goboringcrypto_RSA_get0_crt_params(const GO_RSA*, const GO_BIGNUM **dmp1, const GO_BIGNUM **dmp2, const GO_BIGNUM **iqmp);
   211int _goboringcrypto_RSA_generate_key_ex(GO_RSA*, int, const GO_BIGNUM*, GO_BN_GENCB*);
   212int _goboringcrypto_RSA_generate_key_fips(GO_RSA*, int, GO_BN_GENCB*);
   213enum {
   214	GO_RSA_PKCS1_PADDING = 1,
   215	GO_RSA_NO_PADDING = 3,
   216	GO_RSA_PKCS1_OAEP_PADDING = 4,
   217	GO_RSA_PKCS1_PSS_PADDING = 6,
   218};
   219int _goboringcrypto_RSA_encrypt(GO_RSA*, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding);
   220int _goboringcrypto_RSA_decrypt(GO_RSA*, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding);
   221int _goboringcrypto_RSA_sign(int hash_nid, const uint8_t* in, unsigned int in_len, uint8_t *out, unsigned int *out_len, GO_RSA*);
   222int _goboringcrypto_RSA_sign_pss_mgf1(GO_RSA*, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, const GO_EVP_MD *md, const GO_EVP_MD *mgf1_md, int salt_len);
   223int _goboringcrypto_RSA_sign_raw(GO_RSA*, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding);
   224int _goboringcrypto_RSA_verify(int hash_nid, const uint8_t *msg, size_t msg_len, const uint8_t *sig, size_t sig_len, GO_RSA*);
   225int _goboringcrypto_RSA_verify_pss_mgf1(GO_RSA*, const uint8_t *msg, size_t msg_len, const GO_EVP_MD *md, const GO_EVP_MD *mgf1_md, int salt_len, const uint8_t *sig, size_t sig_len);
   226int _goboringcrypto_RSA_verify_raw(GO_RSA*, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding);
   227unsigned _goboringcrypto_RSA_size(const GO_RSA*);
   228int _goboringcrypto_RSA_is_opaque(const GO_RSA*);
   229int _goboringcrypto_RSA_check_key(const GO_RSA*);
   230int _goboringcrypto_RSA_check_fips(GO_RSA*);
   231GO_RSA* _goboringcrypto_RSA_public_key_from_bytes(const uint8_t*, size_t);
   232GO_RSA* _goboringcrypto_RSA_private_key_from_bytes(const uint8_t*, size_t);
   233int _goboringcrypto_RSA_public_key_to_bytes(uint8_t**, size_t*, const GO_RSA*);
   234int _goboringcrypto_RSA_private_key_to_bytes(uint8_t**, size_t*, const GO_RSA*);
   235
   236// #include <openssl/evp.h>
   237/*unchecked (opaque)*/ typedef struct GO_EVP_PKEY { char data[1]; } GO_EVP_PKEY;
   238GO_EVP_PKEY* _goboringcrypto_EVP_PKEY_new(void);
   239void _goboringcrypto_EVP_PKEY_free(GO_EVP_PKEY*);
   240int _goboringcrypto_EVP_PKEY_set1_RSA(GO_EVP_PKEY*, GO_RSA*);
   241
   242/*unchecked (opaque)*/ typedef struct GO_EVP_PKEY_CTX { char data[1]; } GO_EVP_PKEY_CTX;
   243
   244GO_EVP_PKEY_CTX* _goboringcrypto_EVP_PKEY_CTX_new(GO_EVP_PKEY*, GO_ENGINE*);
   245void _goboringcrypto_EVP_PKEY_CTX_free(GO_EVP_PKEY_CTX*);
   246int _goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(GO_EVP_PKEY_CTX*, uint8_t*, size_t);
   247int _goboringcrypto_EVP_PKEY_CTX_set_rsa_oaep_md(GO_EVP_PKEY_CTX*, const GO_EVP_MD*);
   248int _goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(GO_EVP_PKEY_CTX*, int padding);
   249int _goboringcrypto_EVP_PKEY_decrypt(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
   250int _goboringcrypto_EVP_PKEY_encrypt(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
   251int _goboringcrypto_EVP_PKEY_decrypt_init(GO_EVP_PKEY_CTX*);
   252int _goboringcrypto_EVP_PKEY_encrypt_init(GO_EVP_PKEY_CTX*);
   253int _goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(GO_EVP_PKEY_CTX*, const GO_EVP_MD*);
   254int _goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(GO_EVP_PKEY_CTX*, int);
   255int _goboringcrypto_EVP_PKEY_sign_init(GO_EVP_PKEY_CTX*);
   256int _goboringcrypto_EVP_PKEY_verify_init(GO_EVP_PKEY_CTX*);
   257int _goboringcrypto_EVP_PKEY_sign(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);

View as plain text