...

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

View as plain text