xref: /freebsd/contrib/libfido2/fuzz/wrap.c (revision 2ccfa855)
10afa8e06SEd Maste /*
2*2ccfa855SEd Maste  * Copyright (c) 2019-2022 Yubico AB. All rights reserved.
30afa8e06SEd Maste  * Use of this source code is governed by a BSD-style
40afa8e06SEd Maste  * license that can be found in the LICENSE file.
5*2ccfa855SEd Maste  * SPDX-License-Identifier: BSD-2-Clause
60afa8e06SEd Maste  */
70afa8e06SEd Maste 
8f540a430SEd Maste #include <sys/types.h>
9*2ccfa855SEd Maste #include <sys/random.h>
10f540a430SEd Maste #include <sys/socket.h>
11f540a430SEd Maste 
120afa8e06SEd Maste #include <openssl/bn.h>
130afa8e06SEd Maste #include <openssl/evp.h>
140afa8e06SEd Maste #include <openssl/sha.h>
150afa8e06SEd Maste 
160afa8e06SEd Maste #include <cbor.h>
170afa8e06SEd Maste #include <stdbool.h>
180afa8e06SEd Maste #include <stdint.h>
190afa8e06SEd Maste #include <stdio.h>
200afa8e06SEd Maste #include <stdlib.h>
21*2ccfa855SEd Maste #include <zlib.h>
220afa8e06SEd Maste 
230afa8e06SEd Maste #include "mutator_aux.h"
240afa8e06SEd Maste 
250afa8e06SEd Maste extern int prng_up;
260afa8e06SEd Maste 
27*2ccfa855SEd Maste int fuzz_save_corpus;
28*2ccfa855SEd Maste 
290afa8e06SEd Maste /*
300afa8e06SEd Maste  * Build wrappers around functions of interest, and have them fail
31*2ccfa855SEd Maste  * in a pseudo-random manner. A uniform probability of 0.25% (1/400)
32*2ccfa855SEd Maste  * allows for a depth of log(0.5)/log(399/400) > 276 operations
33*2ccfa855SEd Maste  * before simulated errors become statistically more likely.
340afa8e06SEd Maste  */
350afa8e06SEd Maste 
360afa8e06SEd Maste #define WRAP(type, name, args, retval, param, prob)	\
370afa8e06SEd Maste extern type __wrap_##name args;				\
380afa8e06SEd Maste extern type __real_##name args;				\
390afa8e06SEd Maste type __wrap_##name args {				\
400afa8e06SEd Maste 	if (prng_up && uniform_random(400) < (prob)) {	\
410afa8e06SEd Maste 		return (retval);			\
420afa8e06SEd Maste 	}						\
430afa8e06SEd Maste 							\
440afa8e06SEd Maste 	return (__real_##name param);			\
450afa8e06SEd Maste }
460afa8e06SEd Maste 
470afa8e06SEd Maste WRAP(void *,
480afa8e06SEd Maste 	malloc,
490afa8e06SEd Maste 	(size_t size),
500afa8e06SEd Maste 	NULL,
510afa8e06SEd Maste 	(size),
520afa8e06SEd Maste 	1
530afa8e06SEd Maste )
540afa8e06SEd Maste 
550afa8e06SEd Maste WRAP(void *,
560afa8e06SEd Maste 	calloc,
570afa8e06SEd Maste 	(size_t nmemb, size_t size),
580afa8e06SEd Maste 	NULL,
590afa8e06SEd Maste 	(nmemb, size),
600afa8e06SEd Maste 	1
610afa8e06SEd Maste )
620afa8e06SEd Maste 
63f540a430SEd Maste WRAP(void *,
64f540a430SEd Maste 	realloc,
65f540a430SEd Maste 	(void *ptr, size_t size),
66f540a430SEd Maste 	NULL,
67f540a430SEd Maste 	(ptr, size),
68f540a430SEd Maste 	1
69f540a430SEd Maste )
70f540a430SEd Maste 
710afa8e06SEd Maste WRAP(char *,
720afa8e06SEd Maste 	strdup,
730afa8e06SEd Maste 	(const char *s),
740afa8e06SEd Maste 	NULL,
750afa8e06SEd Maste 	(s),
760afa8e06SEd Maste 	1
770afa8e06SEd Maste )
780afa8e06SEd Maste 
79*2ccfa855SEd Maste WRAP(ssize_t,
80*2ccfa855SEd Maste 	getrandom,
81*2ccfa855SEd Maste 	(void *buf, size_t buflen, unsigned int flags),
82*2ccfa855SEd Maste 	-1,
83*2ccfa855SEd Maste 	(buf, buflen, flags),
84*2ccfa855SEd Maste 	1
85*2ccfa855SEd Maste )
86*2ccfa855SEd Maste 
870afa8e06SEd Maste WRAP(int,
880afa8e06SEd Maste 	EVP_Cipher,
890afa8e06SEd Maste 	(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in,
900afa8e06SEd Maste 	    unsigned int inl),
910afa8e06SEd Maste 	-1,
920afa8e06SEd Maste 	(ctx, out, in, inl),
930afa8e06SEd Maste 	1
940afa8e06SEd Maste )
950afa8e06SEd Maste 
960afa8e06SEd Maste WRAP(int,
970afa8e06SEd Maste 	EVP_CIPHER_CTX_ctrl,
980afa8e06SEd Maste 	(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr),
990afa8e06SEd Maste 	0,
1000afa8e06SEd Maste 	(ctx, type, arg, ptr),
1010afa8e06SEd Maste 	1
1020afa8e06SEd Maste )
1030afa8e06SEd Maste 
1040afa8e06SEd Maste WRAP(EVP_CIPHER_CTX *,
1050afa8e06SEd Maste 	EVP_CIPHER_CTX_new,
1060afa8e06SEd Maste 	(void),
1070afa8e06SEd Maste 	NULL,
1080afa8e06SEd Maste 	(),
1090afa8e06SEd Maste 	1
1100afa8e06SEd Maste )
1110afa8e06SEd Maste 
1120afa8e06SEd Maste WRAP(int,
1130afa8e06SEd Maste 	EVP_CipherInit,
1140afa8e06SEd Maste 	(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
1150afa8e06SEd Maste 	    const unsigned char *key, const unsigned char *iv, int enc),
1160afa8e06SEd Maste 	0,
1170afa8e06SEd Maste 	(ctx, cipher, key, iv, enc),
1180afa8e06SEd Maste 	1
1190afa8e06SEd Maste )
1200afa8e06SEd Maste 
1210afa8e06SEd Maste WRAP(RSA *,
1220afa8e06SEd Maste 	EVP_PKEY_get0_RSA,
1230afa8e06SEd Maste 	(EVP_PKEY *pkey),
1240afa8e06SEd Maste 	NULL,
1250afa8e06SEd Maste 	(pkey),
1260afa8e06SEd Maste 	1
1270afa8e06SEd Maste )
1280afa8e06SEd Maste 
1290afa8e06SEd Maste WRAP(EC_KEY *,
1300afa8e06SEd Maste 	EVP_PKEY_get0_EC_KEY,
1310afa8e06SEd Maste 	(EVP_PKEY *pkey),
1320afa8e06SEd Maste 	NULL,
1330afa8e06SEd Maste 	(pkey),
1340afa8e06SEd Maste 	1
1350afa8e06SEd Maste )
1360afa8e06SEd Maste 
1370afa8e06SEd Maste WRAP(int,
1380afa8e06SEd Maste 	EVP_PKEY_get_raw_public_key,
1390afa8e06SEd Maste 	(const EVP_PKEY *pkey, unsigned char *pub, size_t *len),
1400afa8e06SEd Maste 	0,
1410afa8e06SEd Maste 	(pkey, pub, len),
1420afa8e06SEd Maste 	1
1430afa8e06SEd Maste )
1440afa8e06SEd Maste 
1450afa8e06SEd Maste WRAP(EVP_MD_CTX *,
1460afa8e06SEd Maste 	EVP_MD_CTX_new,
1470afa8e06SEd Maste 	(void),
1480afa8e06SEd Maste 	NULL,
1490afa8e06SEd Maste 	(),
1500afa8e06SEd Maste 	1
1510afa8e06SEd Maste )
1520afa8e06SEd Maste 
1530afa8e06SEd Maste WRAP(int,
1540afa8e06SEd Maste 	EVP_DigestVerifyInit,
1550afa8e06SEd Maste 	(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e,
1560afa8e06SEd Maste 	    EVP_PKEY *pkey),
1570afa8e06SEd Maste 	0,
1580afa8e06SEd Maste 	(ctx, pctx, type, e, pkey),
1590afa8e06SEd Maste 	1
1600afa8e06SEd Maste )
1610afa8e06SEd Maste 
162f540a430SEd Maste WRAP(int,
163f540a430SEd Maste 	EVP_DigestInit_ex,
164f540a430SEd Maste 	(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl),
165f540a430SEd Maste 	0,
166f540a430SEd Maste 	(ctx, type, impl),
167f540a430SEd Maste 	1
168f540a430SEd Maste )
169f540a430SEd Maste 
170f540a430SEd Maste WRAP(int,
171f540a430SEd Maste 	EVP_DigestUpdate,
172f540a430SEd Maste 	(EVP_MD_CTX *ctx, const void *data, size_t count),
173f540a430SEd Maste 	0,
174f540a430SEd Maste 	(ctx, data, count),
175f540a430SEd Maste 	1
176f540a430SEd Maste )
177f540a430SEd Maste 
178f540a430SEd Maste WRAP(int,
179f540a430SEd Maste 	EVP_DigestFinal_ex,
180f540a430SEd Maste 	(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize),
181f540a430SEd Maste 	0,
182f540a430SEd Maste 	(ctx, md, isize),
183f540a430SEd Maste 	1
184f540a430SEd Maste )
185f540a430SEd Maste 
1860afa8e06SEd Maste WRAP(BIGNUM *,
1870afa8e06SEd Maste 	BN_bin2bn,
1880afa8e06SEd Maste 	(const unsigned char *s, int len, BIGNUM *ret),
1890afa8e06SEd Maste 	NULL,
1900afa8e06SEd Maste 	(s, len, ret),
1910afa8e06SEd Maste 	1
1920afa8e06SEd Maste )
1930afa8e06SEd Maste 
1940afa8e06SEd Maste WRAP(int,
1950afa8e06SEd Maste 	BN_bn2bin,
1960afa8e06SEd Maste 	(const BIGNUM *a, unsigned char *to),
1970afa8e06SEd Maste 	-1,
1980afa8e06SEd Maste 	(a, to),
1990afa8e06SEd Maste 	1
2000afa8e06SEd Maste )
2010afa8e06SEd Maste 
2020afa8e06SEd Maste WRAP(BIGNUM *,
2030afa8e06SEd Maste 	BN_CTX_get,
2040afa8e06SEd Maste 	(BN_CTX *ctx),
2050afa8e06SEd Maste 	NULL,
2060afa8e06SEd Maste 	(ctx),
2070afa8e06SEd Maste 	1
2080afa8e06SEd Maste )
2090afa8e06SEd Maste 
2100afa8e06SEd Maste WRAP(BN_CTX *,
2110afa8e06SEd Maste 	BN_CTX_new,
2120afa8e06SEd Maste 	(void),
2130afa8e06SEd Maste 	NULL,
2140afa8e06SEd Maste 	(),
2150afa8e06SEd Maste 	1
2160afa8e06SEd Maste )
2170afa8e06SEd Maste 
2180afa8e06SEd Maste WRAP(BIGNUM *,
2190afa8e06SEd Maste 	BN_new,
2200afa8e06SEd Maste 	(void),
2210afa8e06SEd Maste 	NULL,
2220afa8e06SEd Maste 	(),
2230afa8e06SEd Maste 	1
2240afa8e06SEd Maste )
2250afa8e06SEd Maste 
226f540a430SEd Maste WRAP(RSA *,
227f540a430SEd Maste 	RSA_new,
228f540a430SEd Maste 	(void),
229f540a430SEd Maste 	NULL,
230f540a430SEd Maste 	(),
231f540a430SEd Maste 	1
232f540a430SEd Maste )
233f540a430SEd Maste 
2340afa8e06SEd Maste WRAP(int,
2350afa8e06SEd Maste 	RSA_set0_key,
2360afa8e06SEd Maste 	(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d),
2370afa8e06SEd Maste 	0,
2380afa8e06SEd Maste 	(r, n, e, d),
2390afa8e06SEd Maste 	1
2400afa8e06SEd Maste )
2410afa8e06SEd Maste 
242f540a430SEd Maste WRAP(int,
243f540a430SEd Maste 	RSA_pkey_ctx_ctrl,
244f540a430SEd Maste 	(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2),
245f540a430SEd Maste 	-1,
246f540a430SEd Maste 	(ctx, optype, cmd, p1, p2),
247f540a430SEd Maste 	1
248f540a430SEd Maste )
249f540a430SEd Maste 
2500afa8e06SEd Maste WRAP(EC_KEY *,
2510afa8e06SEd Maste 	EC_KEY_new_by_curve_name,
2520afa8e06SEd Maste 	(int nid),
2530afa8e06SEd Maste 	NULL,
2540afa8e06SEd Maste 	(nid),
2550afa8e06SEd Maste 	1
2560afa8e06SEd Maste )
2570afa8e06SEd Maste 
2580afa8e06SEd Maste WRAP(const EC_GROUP *,
2590afa8e06SEd Maste 	EC_KEY_get0_group,
2600afa8e06SEd Maste 	(const EC_KEY *key),
2610afa8e06SEd Maste 	NULL,
2620afa8e06SEd Maste 	(key),
2630afa8e06SEd Maste 	1
2640afa8e06SEd Maste )
2650afa8e06SEd Maste 
2660afa8e06SEd Maste WRAP(const BIGNUM *,
2670afa8e06SEd Maste 	EC_KEY_get0_private_key,
2680afa8e06SEd Maste 	(const EC_KEY *key),
2690afa8e06SEd Maste 	NULL,
2700afa8e06SEd Maste 	(key),
2710afa8e06SEd Maste 	1
2720afa8e06SEd Maste )
2730afa8e06SEd Maste 
2740afa8e06SEd Maste WRAP(EC_POINT *,
2750afa8e06SEd Maste 	EC_POINT_new,
2760afa8e06SEd Maste 	(const EC_GROUP *group),
2770afa8e06SEd Maste 	NULL,
2780afa8e06SEd Maste 	(group),
2790afa8e06SEd Maste 	1
2800afa8e06SEd Maste )
2810afa8e06SEd Maste 
2820afa8e06SEd Maste WRAP(int,
2830afa8e06SEd Maste 	EC_POINT_get_affine_coordinates_GFp,
2840afa8e06SEd Maste 	(const EC_GROUP *group, const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx),
2850afa8e06SEd Maste 	0,
2860afa8e06SEd Maste 	(group, p, x, y, ctx),
2870afa8e06SEd Maste 	1
2880afa8e06SEd Maste )
2890afa8e06SEd Maste 
2900afa8e06SEd Maste WRAP(EVP_PKEY *,
2910afa8e06SEd Maste 	EVP_PKEY_new,
2920afa8e06SEd Maste 	(void),
2930afa8e06SEd Maste 	NULL,
2940afa8e06SEd Maste 	(),
2950afa8e06SEd Maste 	1
2960afa8e06SEd Maste )
2970afa8e06SEd Maste 
2980afa8e06SEd Maste WRAP(int,
2990afa8e06SEd Maste 	EVP_PKEY_assign,
3000afa8e06SEd Maste 	(EVP_PKEY *pkey, int type, void *key),
3010afa8e06SEd Maste 	0,
3020afa8e06SEd Maste 	(pkey, type, key),
3030afa8e06SEd Maste 	1
3040afa8e06SEd Maste )
3050afa8e06SEd Maste 
3060afa8e06SEd Maste WRAP(int,
3070afa8e06SEd Maste 	EVP_PKEY_keygen_init,
3080afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx),
3090afa8e06SEd Maste 	0,
3100afa8e06SEd Maste 	(ctx),
3110afa8e06SEd Maste 	1
3120afa8e06SEd Maste )
3130afa8e06SEd Maste 
3140afa8e06SEd Maste WRAP(int,
3150afa8e06SEd Maste 	EVP_PKEY_keygen,
3160afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey),
3170afa8e06SEd Maste 	0,
3180afa8e06SEd Maste 	(ctx, ppkey),
3190afa8e06SEd Maste 	1
3200afa8e06SEd Maste )
3210afa8e06SEd Maste 
3220afa8e06SEd Maste WRAP(int,
3230afa8e06SEd Maste 	EVP_PKEY_paramgen_init,
3240afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx),
3250afa8e06SEd Maste 	0,
3260afa8e06SEd Maste 	(ctx),
3270afa8e06SEd Maste 	1
3280afa8e06SEd Maste )
3290afa8e06SEd Maste 
3300afa8e06SEd Maste WRAP(int,
3310afa8e06SEd Maste 	EVP_PKEY_paramgen,
3320afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey),
3330afa8e06SEd Maste 	0,
3340afa8e06SEd Maste 	(ctx, ppkey),
3350afa8e06SEd Maste 	1
3360afa8e06SEd Maste )
3370afa8e06SEd Maste 
3380afa8e06SEd Maste WRAP(EVP_PKEY *,
3390afa8e06SEd Maste 	EVP_PKEY_new_raw_public_key,
3400afa8e06SEd Maste 	(int type, ENGINE *e, const unsigned char *key, size_t keylen),
3410afa8e06SEd Maste 	NULL,
3420afa8e06SEd Maste 	(type, e, key, keylen),
3430afa8e06SEd Maste 	1
3440afa8e06SEd Maste )
3450afa8e06SEd Maste 
3460afa8e06SEd Maste WRAP(EVP_PKEY_CTX *,
3470afa8e06SEd Maste 	EVP_PKEY_CTX_new,
3480afa8e06SEd Maste 	(EVP_PKEY *pkey, ENGINE *e),
3490afa8e06SEd Maste 	NULL,
3500afa8e06SEd Maste 	(pkey, e),
3510afa8e06SEd Maste 	1
3520afa8e06SEd Maste )
3530afa8e06SEd Maste 
3540afa8e06SEd Maste WRAP(EVP_PKEY_CTX *,
3550afa8e06SEd Maste 	EVP_PKEY_CTX_new_id,
3560afa8e06SEd Maste 	(int id, ENGINE *e),
3570afa8e06SEd Maste 	NULL,
3580afa8e06SEd Maste 	(id, e),
3590afa8e06SEd Maste 	1
3600afa8e06SEd Maste )
3610afa8e06SEd Maste 
3620afa8e06SEd Maste WRAP(int,
3630afa8e06SEd Maste 	EVP_PKEY_derive,
3640afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen),
3650afa8e06SEd Maste 	0,
3660afa8e06SEd Maste 	(ctx, key, pkeylen),
3670afa8e06SEd Maste 	1
3680afa8e06SEd Maste )
3690afa8e06SEd Maste 
3700afa8e06SEd Maste WRAP(int,
3710afa8e06SEd Maste 	EVP_PKEY_derive_init,
3720afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx),
3730afa8e06SEd Maste 	0,
3740afa8e06SEd Maste 	(ctx),
3750afa8e06SEd Maste 	1
3760afa8e06SEd Maste )
3770afa8e06SEd Maste 
3780afa8e06SEd Maste WRAP(int,
3790afa8e06SEd Maste 	EVP_PKEY_derive_set_peer,
3800afa8e06SEd Maste 	(EVP_PKEY_CTX *ctx, EVP_PKEY *peer),
3810afa8e06SEd Maste 	0,
3820afa8e06SEd Maste 	(ctx, peer),
3830afa8e06SEd Maste 	1
3840afa8e06SEd Maste )
3850afa8e06SEd Maste 
386f540a430SEd Maste WRAP(int,
387f540a430SEd Maste 	EVP_PKEY_verify_init,
388f540a430SEd Maste 	(EVP_PKEY_CTX *ctx),
389f540a430SEd Maste 	0,
390f540a430SEd Maste 	(ctx),
391f540a430SEd Maste 	1
392f540a430SEd Maste )
393f540a430SEd Maste 
394f540a430SEd Maste WRAP(int,
395f540a430SEd Maste 	EVP_PKEY_CTX_ctrl,
396f540a430SEd Maste 	(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2),
397f540a430SEd Maste 	-1,
398f540a430SEd Maste 	(ctx, keytype, optype, cmd, p1, p2),
399f540a430SEd Maste 	1
400f540a430SEd Maste )
401f540a430SEd Maste 
402f540a430SEd Maste WRAP(const EVP_MD *,
403f540a430SEd Maste 	EVP_sha1,
404f540a430SEd Maste 	(void),
405f540a430SEd Maste 	NULL,
406f540a430SEd Maste 	(),
407f540a430SEd Maste 	1
408f540a430SEd Maste )
409f540a430SEd Maste 
4100afa8e06SEd Maste WRAP(const EVP_MD *,
4110afa8e06SEd Maste 	EVP_sha256,
4120afa8e06SEd Maste 	(void),
4130afa8e06SEd Maste 	NULL,
4140afa8e06SEd Maste 	(),
4150afa8e06SEd Maste 	1
4160afa8e06SEd Maste )
4170afa8e06SEd Maste 
418f540a430SEd Maste WRAP(const EVP_CIPHER *,
419f540a430SEd Maste 	EVP_aes_256_cbc,
420f540a430SEd Maste 	(void),
421f540a430SEd Maste 	NULL,
422f540a430SEd Maste 	(),
423f540a430SEd Maste 	1
424f540a430SEd Maste )
425f540a430SEd Maste 
426f540a430SEd Maste WRAP(const EVP_CIPHER *,
427f540a430SEd Maste 	EVP_aes_256_gcm,
428f540a430SEd Maste 	(void),
429f540a430SEd Maste 	NULL,
430f540a430SEd Maste 	(),
431f540a430SEd Maste 	1
432f540a430SEd Maste )
433f540a430SEd Maste 
4340afa8e06SEd Maste WRAP(unsigned char *,
4350afa8e06SEd Maste 	HMAC,
4360afa8e06SEd Maste 	(const EVP_MD *evp_md, const void *key, int key_len,
4370afa8e06SEd Maste 	    const unsigned char *d, int n, unsigned char *md,
4380afa8e06SEd Maste 	    unsigned int *md_len),
4390afa8e06SEd Maste 	NULL,
4400afa8e06SEd Maste 	(evp_md, key, key_len, d, n, md, md_len),
4410afa8e06SEd Maste 	1
4420afa8e06SEd Maste )
4430afa8e06SEd Maste 
4440afa8e06SEd Maste WRAP(HMAC_CTX *,
4450afa8e06SEd Maste 	HMAC_CTX_new,
4460afa8e06SEd Maste 	(void),
4470afa8e06SEd Maste 	NULL,
4480afa8e06SEd Maste 	(),
4490afa8e06SEd Maste 	1
4500afa8e06SEd Maste )
4510afa8e06SEd Maste 
4520afa8e06SEd Maste WRAP(int,
4530afa8e06SEd Maste 	HMAC_Init_ex,
4540afa8e06SEd Maste 	(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md,
4550afa8e06SEd Maste 	    ENGINE *impl),
4560afa8e06SEd Maste 	0,
4570afa8e06SEd Maste 	(ctx, key, key_len, md, impl),
4580afa8e06SEd Maste 	1
4590afa8e06SEd Maste )
4600afa8e06SEd Maste 
4610afa8e06SEd Maste WRAP(int,
4620afa8e06SEd Maste 	HMAC_Update,
4630afa8e06SEd Maste 	(HMAC_CTX *ctx, const unsigned char *data, int len),
4640afa8e06SEd Maste 	0,
4650afa8e06SEd Maste 	(ctx, data, len),
4660afa8e06SEd Maste 	1
4670afa8e06SEd Maste )
4680afa8e06SEd Maste 
4690afa8e06SEd Maste WRAP(int,
4700afa8e06SEd Maste 	HMAC_Final,
4710afa8e06SEd Maste 	(HMAC_CTX *ctx, unsigned char *md, unsigned int *len),
4720afa8e06SEd Maste 	0,
4730afa8e06SEd Maste 	(ctx, md, len),
4740afa8e06SEd Maste 	1
4750afa8e06SEd Maste )
4760afa8e06SEd Maste 
4770afa8e06SEd Maste WRAP(unsigned char *,
478f540a430SEd Maste 	SHA1,
479f540a430SEd Maste 	(const unsigned char *d, size_t n, unsigned char *md),
480f540a430SEd Maste 	NULL,
481f540a430SEd Maste 	(d, n, md),
482f540a430SEd Maste 	1
483f540a430SEd Maste )
484f540a430SEd Maste 
485f540a430SEd Maste WRAP(unsigned char *,
4860afa8e06SEd Maste 	SHA256,
4870afa8e06SEd Maste 	(const unsigned char *d, size_t n, unsigned char *md),
4880afa8e06SEd Maste 	NULL,
4890afa8e06SEd Maste 	(d, n, md),
4900afa8e06SEd Maste 	1
4910afa8e06SEd Maste )
4920afa8e06SEd Maste 
4930afa8e06SEd Maste WRAP(cbor_item_t *,
4940afa8e06SEd Maste 	cbor_build_string,
4950afa8e06SEd Maste 	(const char *val),
4960afa8e06SEd Maste 	NULL,
4970afa8e06SEd Maste 	(val),
4980afa8e06SEd Maste 	1
4990afa8e06SEd Maste )
5000afa8e06SEd Maste 
5010afa8e06SEd Maste WRAP(cbor_item_t *,
5020afa8e06SEd Maste 	cbor_build_bytestring,
5030afa8e06SEd Maste 	(cbor_data handle, size_t length),
5040afa8e06SEd Maste 	NULL,
5050afa8e06SEd Maste 	(handle, length),
5060afa8e06SEd Maste 	1
5070afa8e06SEd Maste )
5080afa8e06SEd Maste 
5090afa8e06SEd Maste WRAP(cbor_item_t *,
5100afa8e06SEd Maste 	cbor_build_bool,
5110afa8e06SEd Maste 	(bool value),
5120afa8e06SEd Maste 	NULL,
5130afa8e06SEd Maste 	(value),
5140afa8e06SEd Maste 	1
5150afa8e06SEd Maste )
5160afa8e06SEd Maste 
5170afa8e06SEd Maste WRAP(cbor_item_t *,
5180afa8e06SEd Maste 	cbor_build_negint8,
5190afa8e06SEd Maste 	(uint8_t value),
5200afa8e06SEd Maste 	NULL,
5210afa8e06SEd Maste 	(value),
5220afa8e06SEd Maste 	1
5230afa8e06SEd Maste )
5240afa8e06SEd Maste 
5250afa8e06SEd Maste WRAP(cbor_item_t *,
5260afa8e06SEd Maste 	cbor_build_negint16,
5270afa8e06SEd Maste 	(uint16_t value),
5280afa8e06SEd Maste 	NULL,
5290afa8e06SEd Maste 	(value),
5300afa8e06SEd Maste 	1
5310afa8e06SEd Maste )
5320afa8e06SEd Maste 
5330afa8e06SEd Maste WRAP(cbor_item_t *,
5340afa8e06SEd Maste 	cbor_load,
5350afa8e06SEd Maste 	(cbor_data source, size_t source_size, struct cbor_load_result *result),
5360afa8e06SEd Maste 	NULL,
5370afa8e06SEd Maste 	(source, source_size, result),
5380afa8e06SEd Maste 	1
5390afa8e06SEd Maste )
5400afa8e06SEd Maste 
5410afa8e06SEd Maste WRAP(cbor_item_t *,
5420afa8e06SEd Maste 	cbor_build_uint8,
5430afa8e06SEd Maste 	(uint8_t value),
5440afa8e06SEd Maste 	NULL,
5450afa8e06SEd Maste 	(value),
5460afa8e06SEd Maste 	1
5470afa8e06SEd Maste )
5480afa8e06SEd Maste 
5490afa8e06SEd Maste WRAP(cbor_item_t *,
550f540a430SEd Maste 	cbor_build_uint16,
551f540a430SEd Maste 	(uint16_t value),
552f540a430SEd Maste 	NULL,
553f540a430SEd Maste 	(value),
554f540a430SEd Maste 	1
555f540a430SEd Maste )
556f540a430SEd Maste 
557f540a430SEd Maste WRAP(cbor_item_t *,
5580afa8e06SEd Maste 	cbor_build_uint32,
5590afa8e06SEd Maste 	(uint32_t value),
5600afa8e06SEd Maste 	NULL,
5610afa8e06SEd Maste 	(value),
5620afa8e06SEd Maste 	1
5630afa8e06SEd Maste )
5640afa8e06SEd Maste 
565f540a430SEd Maste WRAP(cbor_item_t *,
566f540a430SEd Maste 	cbor_build_uint64,
567f540a430SEd Maste 	(uint64_t value),
568f540a430SEd Maste 	NULL,
569f540a430SEd Maste 	(value),
570f540a430SEd Maste 	1
571f540a430SEd Maste )
572f540a430SEd Maste 
5730afa8e06SEd Maste WRAP(struct cbor_pair *,
5740afa8e06SEd Maste 	cbor_map_handle,
5750afa8e06SEd Maste 	(const cbor_item_t *item),
5760afa8e06SEd Maste 	NULL,
5770afa8e06SEd Maste 	(item),
5780afa8e06SEd Maste 	1
5790afa8e06SEd Maste )
5800afa8e06SEd Maste 
5810afa8e06SEd Maste WRAP(cbor_item_t **,
5820afa8e06SEd Maste 	cbor_array_handle,
5830afa8e06SEd Maste 	(const cbor_item_t *item),
5840afa8e06SEd Maste 	NULL,
5850afa8e06SEd Maste 	(item),
5860afa8e06SEd Maste 	1
5870afa8e06SEd Maste )
5880afa8e06SEd Maste 
5890afa8e06SEd Maste WRAP(bool,
5900afa8e06SEd Maste 	cbor_array_push,
5910afa8e06SEd Maste 	(cbor_item_t *array, cbor_item_t *pushee),
5920afa8e06SEd Maste 	false,
5930afa8e06SEd Maste 	(array, pushee),
5940afa8e06SEd Maste 	1
5950afa8e06SEd Maste )
5960afa8e06SEd Maste 
5970afa8e06SEd Maste WRAP(bool,
5980afa8e06SEd Maste 	cbor_map_add,
5990afa8e06SEd Maste 	(cbor_item_t *item, struct cbor_pair pair),
6000afa8e06SEd Maste 	false,
6010afa8e06SEd Maste 	(item, pair),
6020afa8e06SEd Maste 	1
6030afa8e06SEd Maste )
6040afa8e06SEd Maste 
6050afa8e06SEd Maste WRAP(cbor_item_t *,
6060afa8e06SEd Maste 	cbor_new_definite_map,
6070afa8e06SEd Maste 	(size_t size),
6080afa8e06SEd Maste 	NULL,
6090afa8e06SEd Maste 	(size),
6100afa8e06SEd Maste 	1
6110afa8e06SEd Maste )
6120afa8e06SEd Maste 
6130afa8e06SEd Maste WRAP(cbor_item_t *,
6140afa8e06SEd Maste 	cbor_new_definite_array,
6150afa8e06SEd Maste 	(size_t size),
6160afa8e06SEd Maste 	NULL,
6170afa8e06SEd Maste 	(size),
6180afa8e06SEd Maste 	1
6190afa8e06SEd Maste )
6200afa8e06SEd Maste 
621f540a430SEd Maste WRAP(cbor_item_t *,
622f540a430SEd Maste 	cbor_new_definite_bytestring,
623f540a430SEd Maste 	(void),
624f540a430SEd Maste 	NULL,
625f540a430SEd Maste 	(),
626f540a430SEd Maste 	1
627f540a430SEd Maste )
628f540a430SEd Maste 
6290afa8e06SEd Maste WRAP(size_t,
6300afa8e06SEd Maste 	cbor_serialize_alloc,
6310afa8e06SEd Maste 	(const cbor_item_t *item, cbor_mutable_data *buffer,
6320afa8e06SEd Maste 	    size_t *buffer_size),
6330afa8e06SEd Maste 	0,
6340afa8e06SEd Maste 	(item, buffer, buffer_size),
6350afa8e06SEd Maste 	1
6360afa8e06SEd Maste )
6370afa8e06SEd Maste 
6380afa8e06SEd Maste WRAP(int,
6390afa8e06SEd Maste 	fido_tx,
640f540a430SEd Maste 	(fido_dev_t *d, uint8_t cmd, const void *buf, size_t count, int *ms),
6410afa8e06SEd Maste 	-1,
642f540a430SEd Maste 	(d, cmd, buf, count, ms),
6430afa8e06SEd Maste 	1
6440afa8e06SEd Maste )
6450afa8e06SEd Maste 
6460afa8e06SEd Maste WRAP(int,
647f540a430SEd Maste 	bind,
648f540a430SEd Maste 	(int sockfd, const struct sockaddr *addr, socklen_t addrlen),
6490afa8e06SEd Maste 	-1,
650f540a430SEd Maste 	(sockfd, addr, addrlen),
6510afa8e06SEd Maste 	1
6520afa8e06SEd Maste )
653*2ccfa855SEd Maste 
654*2ccfa855SEd Maste WRAP(int,
655*2ccfa855SEd Maste 	deflateInit2_,
656*2ccfa855SEd Maste 	(z_streamp strm, int level, int method, int windowBits, int memLevel,
657*2ccfa855SEd Maste 	    int strategy, const char *version, int stream_size),
658*2ccfa855SEd Maste 	Z_STREAM_ERROR,
659*2ccfa855SEd Maste 	(strm, level, method, windowBits, memLevel, strategy, version,
660*2ccfa855SEd Maste 	    stream_size),
661*2ccfa855SEd Maste 	1
662*2ccfa855SEd Maste )
663*2ccfa855SEd Maste 
664*2ccfa855SEd Maste int __wrap_deflate(z_streamp, int);
665*2ccfa855SEd Maste int __real_deflate(z_streamp, int);
666*2ccfa855SEd Maste 
667*2ccfa855SEd Maste int
__wrap_deflate(z_streamp strm,int flush)668*2ccfa855SEd Maste __wrap_deflate(z_streamp strm, int flush)
669*2ccfa855SEd Maste {
670*2ccfa855SEd Maste 	if (prng_up && uniform_random(400) < 1) {
671*2ccfa855SEd Maste 		return Z_BUF_ERROR;
672*2ccfa855SEd Maste 	}
673*2ccfa855SEd Maste 	/* should never happen, but we check for it */
674*2ccfa855SEd Maste 	if (prng_up && uniform_random(400) < 1) {
675*2ccfa855SEd Maste 		strm->avail_out = UINT_MAX;
676*2ccfa855SEd Maste 		return Z_STREAM_END;
677*2ccfa855SEd Maste 	}
678*2ccfa855SEd Maste 
679*2ccfa855SEd Maste 	return __real_deflate(strm, flush);
680*2ccfa855SEd Maste }
681*2ccfa855SEd Maste 
682*2ccfa855SEd Maste int __wrap_asprintf(char **, const char *, ...);
683*2ccfa855SEd Maste 
684*2ccfa855SEd Maste int
__wrap_asprintf(char ** strp,const char * fmt,...)685*2ccfa855SEd Maste __wrap_asprintf(char **strp, const char *fmt, ...)
686*2ccfa855SEd Maste {
687*2ccfa855SEd Maste 	va_list ap;
688*2ccfa855SEd Maste 	int r;
689*2ccfa855SEd Maste 
690*2ccfa855SEd Maste 	if (prng_up && uniform_random(400) < 1) {
691*2ccfa855SEd Maste 		*strp = (void *)0xdeadbeef;
692*2ccfa855SEd Maste 		return -1;
693*2ccfa855SEd Maste 	}
694*2ccfa855SEd Maste 
695*2ccfa855SEd Maste 	va_start(ap, fmt);
696*2ccfa855SEd Maste 	r = vasprintf(strp, fmt, ap);
697*2ccfa855SEd Maste 	va_end(ap);
698*2ccfa855SEd Maste 
699*2ccfa855SEd Maste 	return r;
700*2ccfa855SEd Maste }
701