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

     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>
    30  int _goboringcrypto_FIPS_mode(void);
    31  void* _goboringcrypto_OPENSSL_malloc(size_t);
    32  
    33  // #include <openssl/rand.h>
    34  int _goboringcrypto_RAND_bytes(uint8_t*, size_t);
    35  
    36  // #include <openssl/nid.h>
    37  enum {
    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>
    52  typedef struct GO_SHA_CTX { char data[96]; } GO_SHA_CTX;
    53  int _goboringcrypto_SHA1_Init(GO_SHA_CTX*);
    54  int _goboringcrypto_SHA1_Update(GO_SHA_CTX*, const void*, size_t);
    55  int _goboringcrypto_SHA1_Final(uint8_t*, GO_SHA_CTX*);
    56  
    57  typedef struct GO_SHA256_CTX { char data[48+64]; } GO_SHA256_CTX;
    58  int _goboringcrypto_SHA224_Init(GO_SHA256_CTX*);
    59  int _goboringcrypto_SHA224_Update(GO_SHA256_CTX*, const void*, size_t);
    60  int _goboringcrypto_SHA224_Final(uint8_t*, GO_SHA256_CTX*);
    61  int _goboringcrypto_SHA256_Init(GO_SHA256_CTX*);
    62  int _goboringcrypto_SHA256_Update(GO_SHA256_CTX*, const void*, size_t);
    63  int _goboringcrypto_SHA256_Final(uint8_t*, GO_SHA256_CTX*);
    64  
    65  typedef struct GO_SHA512_CTX { char data[88+128]; } GO_SHA512_CTX;
    66  int _goboringcrypto_SHA384_Init(GO_SHA512_CTX*);
    67  int _goboringcrypto_SHA384_Update(GO_SHA512_CTX*, const void*, size_t);
    68  int _goboringcrypto_SHA384_Final(uint8_t*, GO_SHA512_CTX*);
    69  int _goboringcrypto_SHA512_Init(GO_SHA512_CTX*);
    70  int _goboringcrypto_SHA512_Update(GO_SHA512_CTX*, const void*, size_t);
    71  int _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;
    75  const GO_EVP_MD* _goboringcrypto_EVP_md4(void);
    76  const GO_EVP_MD* _goboringcrypto_EVP_md5(void);
    77  const GO_EVP_MD* _goboringcrypto_EVP_md5_sha1(void);
    78  const GO_EVP_MD* _goboringcrypto_EVP_sha1(void);
    79  const GO_EVP_MD* _goboringcrypto_EVP_sha224(void);
    80  const GO_EVP_MD* _goboringcrypto_EVP_sha256(void);
    81  const GO_EVP_MD* _goboringcrypto_EVP_sha384(void);
    82  const GO_EVP_MD* _goboringcrypto_EVP_sha512(void);
    83  int _goboringcrypto_EVP_MD_type(const GO_EVP_MD*);
    84  size_t _goboringcrypto_EVP_MD_size(const GO_EVP_MD*);
    85  
    86  // #include <openssl/hmac.h>
    87  typedef struct GO_HMAC_CTX { char data[104]; } GO_HMAC_CTX;
    88  void _goboringcrypto_HMAC_CTX_init(GO_HMAC_CTX*);
    89  void _goboringcrypto_HMAC_CTX_cleanup(GO_HMAC_CTX*);
    90  int _goboringcrypto_HMAC_Init(GO_HMAC_CTX*, const void*, int, const GO_EVP_MD*);
    91  int _goboringcrypto_HMAC_Update(GO_HMAC_CTX*, const uint8_t*, size_t);
    92  int _goboringcrypto_HMAC_Final(GO_HMAC_CTX*, uint8_t*, unsigned int*);
    93  size_t _goboringcrypto_HMAC_size(const GO_HMAC_CTX*);
    94  int _goboringcrypto_HMAC_CTX_copy_ex(GO_HMAC_CTX *dest, const GO_HMAC_CTX *src);
    95  
    96  // #include <openssl/aes.h>
    97  typedef struct GO_AES_KEY { char data[244]; } GO_AES_KEY;
    98  int _goboringcrypto_AES_set_encrypt_key(const uint8_t*, unsigned int, GO_AES_KEY*);
    99  int _goboringcrypto_AES_set_decrypt_key(const uint8_t*, unsigned int, GO_AES_KEY*);
   100  void _goboringcrypto_AES_encrypt(const uint8_t*, uint8_t*, const GO_AES_KEY*);
   101  void _goboringcrypto_AES_decrypt(const uint8_t*, uint8_t*, const GO_AES_KEY*);
   102  void _goboringcrypto_AES_ctr128_encrypt(const uint8_t*, uint8_t*, size_t, const GO_AES_KEY*, uint8_t*, uint8_t*, unsigned int*);
   103  enum {
   104  	GO_AES_ENCRYPT = 1,
   105  	GO_AES_DECRYPT = 0
   106  };
   107  void _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;
   112  const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm(void);
   113  const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm(void);
   114  enum {
   115  	GO_EVP_AEAD_DEFAULT_TAG_LENGTH = 0
   116  };
   117  size_t _goboringcrypto_EVP_AEAD_key_length(const GO_EVP_AEAD*);
   118  size_t _goboringcrypto_EVP_AEAD_nonce_length(const GO_EVP_AEAD*);
   119  size_t _goboringcrypto_EVP_AEAD_max_overhead(const GO_EVP_AEAD*);
   120  size_t _goboringcrypto_EVP_AEAD_max_tag_len(const GO_EVP_AEAD*);
   121  typedef struct GO_EVP_AEAD_CTX { char data[600]; } GO_EVP_AEAD_CTX;
   122  void _goboringcrypto_EVP_AEAD_CTX_zero(GO_EVP_AEAD_CTX*);
   123  int _goboringcrypto_EVP_AEAD_CTX_init(GO_EVP_AEAD_CTX*, const GO_EVP_AEAD*, const uint8_t*, size_t, size_t, GO_ENGINE*);
   124  void _goboringcrypto_EVP_AEAD_CTX_cleanup(GO_EVP_AEAD_CTX*);
   125  int _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);
   126  int _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);
   127  const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm_tls12(void);
   128  const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls12(void);
   129  enum go_evp_aead_direction_t {
   130  	go_evp_aead_open = 0,
   131  	go_evp_aead_seal = 1
   132  };
   133  int _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);
   134  
   135  // #include <openssl/bn.h>
   136  /*unchecked (opaque)*/ typedef struct GO_BN_CTX { char data[1]; } GO_BN_CTX;
   137  typedef struct GO_BIGNUM { char data[24]; } GO_BIGNUM;
   138  GO_BIGNUM* _goboringcrypto_BN_new(void);
   139  void _goboringcrypto_BN_free(GO_BIGNUM*);
   140  unsigned _goboringcrypto_BN_num_bits(const GO_BIGNUM*);
   141  unsigned _goboringcrypto_BN_num_bytes(const GO_BIGNUM*);
   142  int _goboringcrypto_BN_is_negative(const GO_BIGNUM*);
   143  GO_BIGNUM* _goboringcrypto_BN_bin2bn(const uint8_t*, size_t, GO_BIGNUM*);
   144  GO_BIGNUM* _goboringcrypto_BN_le2bn(const uint8_t*, size_t, GO_BIGNUM*);
   145  size_t _goboringcrypto_BN_bn2bin(const GO_BIGNUM*, uint8_t*);
   146  int _goboringcrypto_BN_bn2le_padded(uint8_t*, size_t, const GO_BIGNUM*);
   147  int _goboringcrypto_BN_bn2bin_padded(uint8_t*, size_t, const GO_BIGNUM*);
   148  
   149  // #include <openssl/ec.h>
   150  /*unchecked (opaque)*/ typedef struct GO_EC_GROUP { char data[1]; } GO_EC_GROUP;
   151  GO_EC_GROUP* _goboringcrypto_EC_GROUP_new_by_curve_name(int);
   152  void _goboringcrypto_EC_GROUP_free(GO_EC_GROUP*);
   153  
   154  /*unchecked (opaque)*/ typedef struct GO_EC_POINT { char data[1]; } GO_EC_POINT;
   155  GO_EC_POINT* _goboringcrypto_EC_POINT_new(const GO_EC_GROUP*);
   156  int _goboringcrypto_EC_POINT_mul(const GO_EC_GROUP*, GO_EC_POINT*, const GO_BIGNUM*, const GO_EC_POINT*, const GO_BIGNUM*, GO_BN_CTX*);
   157  void _goboringcrypto_EC_POINT_free(GO_EC_POINT*);
   158  int _goboringcrypto_EC_POINT_get_affine_coordinates_GFp(const GO_EC_GROUP*, const GO_EC_POINT*, GO_BIGNUM*, GO_BIGNUM*, GO_BN_CTX*);
   159  int _goboringcrypto_EC_POINT_set_affine_coordinates_GFp(const GO_EC_GROUP*, GO_EC_POINT*, const GO_BIGNUM*, const GO_BIGNUM*, GO_BN_CTX*);
   160  int _goboringcrypto_EC_POINT_oct2point(const GO_EC_GROUP*, GO_EC_POINT*, const uint8_t*, size_t, GO_BN_CTX*);
   161  GO_EC_POINT* _goboringcrypto_EC_POINT_dup(const GO_EC_POINT*, const GO_EC_GROUP*);
   162  int _goboringcrypto_EC_POINT_is_on_curve(const GO_EC_GROUP*, const GO_EC_POINT*, GO_BN_CTX*);
   163  #ifndef OPENSSL_HEADER_EC_H
   164  typedef enum {
   165  	GO_POINT_CONVERSION_COMPRESSED = 2,
   166  	GO_POINT_CONVERSION_UNCOMPRESSED = 4,
   167  	GO_POINT_CONVERSION_HYBRID = 6,
   168  } go_point_conversion_form_t;
   169  #endif
   170  size_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*);
   171  
   172  // #include <openssl/ec_key.h>
   173  /*unchecked (opaque)*/ typedef struct GO_EC_KEY { char data[1]; } GO_EC_KEY;
   174  GO_EC_KEY* _goboringcrypto_EC_KEY_new(void);
   175  GO_EC_KEY* _goboringcrypto_EC_KEY_new_by_curve_name(int);
   176  void _goboringcrypto_EC_KEY_free(GO_EC_KEY*);
   177  const GO_EC_GROUP* _goboringcrypto_EC_KEY_get0_group(const GO_EC_KEY*);
   178  int _goboringcrypto_EC_KEY_generate_key_fips(GO_EC_KEY*);
   179  int _goboringcrypto_EC_KEY_set_private_key(GO_EC_KEY*, const GO_BIGNUM*);
   180  int _goboringcrypto_EC_KEY_set_public_key(GO_EC_KEY*, const GO_EC_POINT*);
   181  int _goboringcrypto_EC_KEY_is_opaque(const GO_EC_KEY*);
   182  const GO_BIGNUM* _goboringcrypto_EC_KEY_get0_private_key(const GO_EC_KEY*);
   183  const GO_EC_POINT* _goboringcrypto_EC_KEY_get0_public_key(const GO_EC_KEY*);
   184  // TODO: EC_KEY_check_fips?
   185  
   186  // #include <openssl/ecdh.h>
   187  int _goboringcrypto_ECDH_compute_key_fips(uint8_t*, size_t, const GO_EC_POINT*, const GO_EC_KEY*);
   188  
   189  // #include <openssl/ecdsa.h>
   190  typedef struct GO_ECDSA_SIG { char data[16]; } GO_ECDSA_SIG;
   191  GO_ECDSA_SIG* _goboringcrypto_ECDSA_SIG_new(void);
   192  void _goboringcrypto_ECDSA_SIG_free(GO_ECDSA_SIG*);
   193  GO_ECDSA_SIG* _goboringcrypto_ECDSA_do_sign(const uint8_t*, size_t, const GO_EC_KEY*);
   194  int _goboringcrypto_ECDSA_do_verify(const uint8_t*, size_t, const GO_ECDSA_SIG*, const GO_EC_KEY*);
   195  int _goboringcrypto_ECDSA_sign(int, const uint8_t*, size_t, uint8_t*, unsigned int*, const GO_EC_KEY*);
   196  size_t _goboringcrypto_ECDSA_size(const GO_EC_KEY*);
   197  int _goboringcrypto_ECDSA_verify(int, const uint8_t*, size_t, const uint8_t*, size_t, const GO_EC_KEY*);
   198  
   199  // #include <openssl/rsa.h>
   200  
   201  // Note: order of struct fields here is unchecked.
   202  typedef struct GO_RSA { void *meth; GO_BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; char data[168]; } GO_RSA;
   203  /*unchecked (opaque)*/ typedef struct GO_BN_GENCB { char data[1]; } GO_BN_GENCB;
   204  GO_RSA* _goboringcrypto_RSA_new(void);
   205  void _goboringcrypto_RSA_free(GO_RSA*);
   206  void _goboringcrypto_RSA_get0_key(const GO_RSA*, const GO_BIGNUM **n, const GO_BIGNUM **e, const GO_BIGNUM **d);
   207  void _goboringcrypto_RSA_get0_factors(const GO_RSA*, const GO_BIGNUM **p, const GO_BIGNUM **q);
   208  void _goboringcrypto_RSA_get0_crt_params(const GO_RSA*, const GO_BIGNUM **dmp1, const GO_BIGNUM **dmp2, const GO_BIGNUM **iqmp);
   209  int _goboringcrypto_RSA_generate_key_ex(GO_RSA*, int, const GO_BIGNUM*, GO_BN_GENCB*);
   210  int _goboringcrypto_RSA_generate_key_fips(GO_RSA*, int, GO_BN_GENCB*);
   211  enum {
   212  	GO_RSA_PKCS1_PADDING = 1,
   213  	GO_RSA_NO_PADDING = 3,
   214  	GO_RSA_PKCS1_OAEP_PADDING = 4,
   215  	GO_RSA_PKCS1_PSS_PADDING = 6,
   216  };
   217  int _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);
   218  int _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);
   219  int _goboringcrypto_RSA_sign(int hash_nid, const uint8_t* in, unsigned int in_len, uint8_t *out, unsigned int *out_len, GO_RSA*);
   220  int _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);
   221  int _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);
   222  int _goboringcrypto_RSA_verify(int hash_nid, const uint8_t *msg, size_t msg_len, const uint8_t *sig, size_t sig_len, GO_RSA*);
   223  int _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);
   224  int _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);
   225  unsigned _goboringcrypto_RSA_size(const GO_RSA*);
   226  int _goboringcrypto_RSA_is_opaque(const GO_RSA*);
   227  int _goboringcrypto_RSA_check_key(const GO_RSA*);
   228  int _goboringcrypto_RSA_check_fips(GO_RSA*);
   229  GO_RSA* _goboringcrypto_RSA_public_key_from_bytes(const uint8_t*, size_t);
   230  GO_RSA* _goboringcrypto_RSA_private_key_from_bytes(const uint8_t*, size_t);
   231  int _goboringcrypto_RSA_public_key_to_bytes(uint8_t**, size_t*, const GO_RSA*);
   232  int _goboringcrypto_RSA_private_key_to_bytes(uint8_t**, size_t*, const GO_RSA*);
   233  
   234  // #include <openssl/evp.h>
   235  /*unchecked (opaque)*/ typedef struct GO_EVP_PKEY { char data[1]; } GO_EVP_PKEY;
   236  GO_EVP_PKEY* _goboringcrypto_EVP_PKEY_new(void);
   237  void _goboringcrypto_EVP_PKEY_free(GO_EVP_PKEY*);
   238  int _goboringcrypto_EVP_PKEY_set1_RSA(GO_EVP_PKEY*, GO_RSA*);
   239  
   240  /*unchecked (opaque)*/ typedef struct GO_EVP_PKEY_CTX { char data[1]; } GO_EVP_PKEY_CTX;
   241  
   242  GO_EVP_PKEY_CTX* _goboringcrypto_EVP_PKEY_CTX_new(GO_EVP_PKEY*, GO_ENGINE*);
   243  void _goboringcrypto_EVP_PKEY_CTX_free(GO_EVP_PKEY_CTX*);
   244  int _goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(GO_EVP_PKEY_CTX*, uint8_t*, size_t);
   245  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_oaep_md(GO_EVP_PKEY_CTX*, const GO_EVP_MD*);
   246  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(GO_EVP_PKEY_CTX*, int padding);
   247  int _goboringcrypto_EVP_PKEY_decrypt(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
   248  int _goboringcrypto_EVP_PKEY_encrypt(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
   249  int _goboringcrypto_EVP_PKEY_decrypt_init(GO_EVP_PKEY_CTX*);
   250  int _goboringcrypto_EVP_PKEY_encrypt_init(GO_EVP_PKEY_CTX*);
   251  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(GO_EVP_PKEY_CTX*, const GO_EVP_MD*);
   252  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(GO_EVP_PKEY_CTX*, int);
   253  int _goboringcrypto_EVP_PKEY_sign_init(GO_EVP_PKEY_CTX*);
   254  int _goboringcrypto_EVP_PKEY_verify_init(GO_EVP_PKEY_CTX*);
   255  int _goboringcrypto_EVP_PKEY_sign(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
   256  

View as plain text