goboringcrypto.h raw

   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_128_gcm_tls13(void);
 129  const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls12(void);
 130  const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls13(void);
 131  enum go_evp_aead_direction_t {
 132  	go_evp_aead_open = 0,
 133  	go_evp_aead_seal = 1
 134  };
 135  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);
 136  
 137  // #include <openssl/bn.h>
 138  /*unchecked (opaque)*/ typedef struct GO_BN_CTX { char data[1]; } GO_BN_CTX;
 139  typedef struct GO_BIGNUM { char data[24]; } GO_BIGNUM;
 140  GO_BIGNUM* _goboringcrypto_BN_new(void);
 141  void _goboringcrypto_BN_free(GO_BIGNUM*);
 142  unsigned _goboringcrypto_BN_num_bits(const GO_BIGNUM*);
 143  unsigned _goboringcrypto_BN_num_bytes(const GO_BIGNUM*);
 144  int _goboringcrypto_BN_is_negative(const GO_BIGNUM*);
 145  GO_BIGNUM* _goboringcrypto_BN_bin2bn(const uint8_t*, size_t, GO_BIGNUM*);
 146  GO_BIGNUM* _goboringcrypto_BN_le2bn(const uint8_t*, size_t, GO_BIGNUM*);
 147  size_t _goboringcrypto_BN_bn2bin(const GO_BIGNUM*, uint8_t*);
 148  int _goboringcrypto_BN_bn2le_padded(uint8_t*, size_t, const GO_BIGNUM*);
 149  int _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;
 153  GO_EC_GROUP* _goboringcrypto_EC_GROUP_new_by_curve_name(int);
 154  void _goboringcrypto_EC_GROUP_free(GO_EC_GROUP*);
 155  
 156  /*unchecked (opaque)*/ typedef struct GO_EC_POINT { char data[1]; } GO_EC_POINT;
 157  GO_EC_POINT* _goboringcrypto_EC_POINT_new(const GO_EC_GROUP*);
 158  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*);
 159  void _goboringcrypto_EC_POINT_free(GO_EC_POINT*);
 160  int _goboringcrypto_EC_POINT_get_affine_coordinates_GFp(const GO_EC_GROUP*, const GO_EC_POINT*, GO_BIGNUM*, GO_BIGNUM*, GO_BN_CTX*);
 161  int _goboringcrypto_EC_POINT_set_affine_coordinates_GFp(const GO_EC_GROUP*, GO_EC_POINT*, const GO_BIGNUM*, const GO_BIGNUM*, GO_BN_CTX*);
 162  int _goboringcrypto_EC_POINT_oct2point(const GO_EC_GROUP*, GO_EC_POINT*, const uint8_t*, size_t, GO_BN_CTX*);
 163  GO_EC_POINT* _goboringcrypto_EC_POINT_dup(const GO_EC_POINT*, const GO_EC_GROUP*);
 164  int _goboringcrypto_EC_POINT_is_on_curve(const GO_EC_GROUP*, const GO_EC_POINT*, GO_BN_CTX*);
 165  #ifndef OPENSSL_HEADER_EC_H
 166  typedef 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
 172  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*);
 173  
 174  // #include <openssl/ec_key.h>
 175  /*unchecked (opaque)*/ typedef struct GO_EC_KEY { char data[1]; } GO_EC_KEY;
 176  GO_EC_KEY* _goboringcrypto_EC_KEY_new(void);
 177  GO_EC_KEY* _goboringcrypto_EC_KEY_new_by_curve_name(int);
 178  void _goboringcrypto_EC_KEY_free(GO_EC_KEY*);
 179  const GO_EC_GROUP* _goboringcrypto_EC_KEY_get0_group(const GO_EC_KEY*);
 180  int _goboringcrypto_EC_KEY_generate_key_fips(GO_EC_KEY*);
 181  int _goboringcrypto_EC_KEY_set_private_key(GO_EC_KEY*, const GO_BIGNUM*);
 182  int _goboringcrypto_EC_KEY_set_public_key(GO_EC_KEY*, const GO_EC_POINT*);
 183  int _goboringcrypto_EC_KEY_is_opaque(const GO_EC_KEY*);
 184  const GO_BIGNUM* _goboringcrypto_EC_KEY_get0_private_key(const GO_EC_KEY*);
 185  const 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>
 189  int _goboringcrypto_ECDH_compute_key_fips(uint8_t*, size_t, const GO_EC_POINT*, const GO_EC_KEY*);
 190  
 191  // #include <openssl/ecdsa.h>
 192  typedef struct GO_ECDSA_SIG { char data[16]; } GO_ECDSA_SIG;
 193  GO_ECDSA_SIG* _goboringcrypto_ECDSA_SIG_new(void);
 194  void _goboringcrypto_ECDSA_SIG_free(GO_ECDSA_SIG*);
 195  GO_ECDSA_SIG* _goboringcrypto_ECDSA_do_sign(const uint8_t*, size_t, const GO_EC_KEY*);
 196  int _goboringcrypto_ECDSA_do_verify(const uint8_t*, size_t, const GO_ECDSA_SIG*, const GO_EC_KEY*);
 197  int _goboringcrypto_ECDSA_sign(int, const uint8_t*, size_t, uint8_t*, unsigned int*, const GO_EC_KEY*);
 198  size_t _goboringcrypto_ECDSA_size(const GO_EC_KEY*);
 199  int _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.
 204  typedef 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;
 206  GO_RSA* _goboringcrypto_RSA_new(void);
 207  void _goboringcrypto_RSA_free(GO_RSA*);
 208  void _goboringcrypto_RSA_get0_key(const GO_RSA*, const GO_BIGNUM **n, const GO_BIGNUM **e, const GO_BIGNUM **d);
 209  void _goboringcrypto_RSA_get0_factors(const GO_RSA*, const GO_BIGNUM **p, const GO_BIGNUM **q);
 210  void _goboringcrypto_RSA_get0_crt_params(const GO_RSA*, const GO_BIGNUM **dmp1, const GO_BIGNUM **dmp2, const GO_BIGNUM **iqmp);
 211  int _goboringcrypto_RSA_generate_key_ex(GO_RSA*, int, const GO_BIGNUM*, GO_BN_GENCB*);
 212  int _goboringcrypto_RSA_generate_key_fips(GO_RSA*, int, GO_BN_GENCB*);
 213  enum {
 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  };
 219  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);
 220  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);
 221  int _goboringcrypto_RSA_sign(int hash_nid, const uint8_t* in, unsigned int in_len, uint8_t *out, unsigned int *out_len, GO_RSA*);
 222  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);
 223  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);
 224  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*);
 225  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);
 226  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);
 227  unsigned _goboringcrypto_RSA_size(const GO_RSA*);
 228  int _goboringcrypto_RSA_is_opaque(const GO_RSA*);
 229  int _goboringcrypto_RSA_check_key(const GO_RSA*);
 230  int _goboringcrypto_RSA_check_fips(GO_RSA*);
 231  GO_RSA* _goboringcrypto_RSA_public_key_from_bytes(const uint8_t*, size_t);
 232  GO_RSA* _goboringcrypto_RSA_private_key_from_bytes(const uint8_t*, size_t);
 233  int _goboringcrypto_RSA_public_key_to_bytes(uint8_t**, size_t*, const GO_RSA*);
 234  int _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;
 238  GO_EVP_PKEY* _goboringcrypto_EVP_PKEY_new(void);
 239  void _goboringcrypto_EVP_PKEY_free(GO_EVP_PKEY*);
 240  int _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  
 244  GO_EVP_PKEY_CTX* _goboringcrypto_EVP_PKEY_CTX_new(GO_EVP_PKEY*, GO_ENGINE*);
 245  void _goboringcrypto_EVP_PKEY_CTX_free(GO_EVP_PKEY_CTX*);
 246  int _goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(GO_EVP_PKEY_CTX*, uint8_t*, size_t);
 247  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_oaep_md(GO_EVP_PKEY_CTX*, const GO_EVP_MD*);
 248  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(GO_EVP_PKEY_CTX*, int padding);
 249  int _goboringcrypto_EVP_PKEY_decrypt(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
 250  int _goboringcrypto_EVP_PKEY_encrypt(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
 251  int _goboringcrypto_EVP_PKEY_decrypt_init(GO_EVP_PKEY_CTX*);
 252  int _goboringcrypto_EVP_PKEY_encrypt_init(GO_EVP_PKEY_CTX*);
 253  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(GO_EVP_PKEY_CTX*, const GO_EVP_MD*);
 254  int _goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(GO_EVP_PKEY_CTX*, int);
 255  int _goboringcrypto_EVP_PKEY_sign_init(GO_EVP_PKEY_CTX*);
 256  int _goboringcrypto_EVP_PKEY_verify_init(GO_EVP_PKEY_CTX*);
 257  int _goboringcrypto_EVP_PKEY_sign(GO_EVP_PKEY_CTX*, uint8_t*, size_t*, const uint8_t*, size_t);
 258