xref: /lighttpd1.4/src/ck.h (revision 62ccda85)
1 /*
2  * ck - C11 Annex K wrappers  (selected functions; not complete)
3  *
4  * ck is also an abbreviation for "check".
5  * These are validating, checking functions.
6  *
7  * Copyright(c) 2016 Glenn Strauss gstrauss()gluelogic.com  All rights reserved
8  * License: BSD 3-clause (same as lighttpd)
9  */
10 #ifndef INCLUDED_CK_H
11 #define INCLUDED_CK_H
12 #ifndef __STDC_WANT_LIB_EXT1__ /*(enable C11 Annex K ext1 *_s functions)*/
13 #define __STDC_WANT_LIB_EXT1__ 1
14 #endif
15 #include "first.h"
16 #ifdef __FreeBSD__
17 #include <errno.h>
18 #endif
19 
20 __BEGIN_DECLS
21 
22 
23 #ifndef RSIZE_MAX
24 #define RSIZE_MAX (SIZE_MAX >> 1)
25 typedef size_t rsize_t;
26 typedef int errno_t;
27 #endif
28 
29 
30 errno_t ck_getenv_s (size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name);
31 
32 /*(ck_memclear_s() is not from C11 Annex K
33  * ck_memclear_s() is similar to memset_s() using constant byte 0 for fill)*/
34 errno_t ck_memclear_s (void *s, rsize_t smax, rsize_t n);
35 
36 /*(ck_memzero() is not from C11 Annex K
37  * ck_memzero() is a convenience wrapper around ck_memclear_s())*/
38 static inline errno_t ck_memzero(void *s, rsize_t n);
39 static inline errno_t ck_memzero(void *s, rsize_t n) {
40     return ck_memclear_s(s, n, n);
41 }
42 
43 errno_t ck_strerror_s (char *s, rsize_t maxsize, errno_t errnum);
44 
45 /*(ck_memeq_const_time() is not from C11 Annex K)
46  * constant time memory compare for equality
47  * rounds to next multiple of 64 to avoid potentially leaking exact
48  * string lengths when subject to high precision timing attacks */
49 int ck_memeq_const_time (const void *a, size_t alen, const void *b, size_t blen);
50 
51 /*(ck_memeq_const_time_fixed_len() is not from C11 Annex K)
52  * constant time memory compare for equality for fixed len (e.g. digests)
53  * (padding not necessary for digests, which have fixed, defined lengths) */
54 int ck_memeq_const_time_fixed_len (const void *a, const void *b, size_t len);
55 
56 __END_DECLS
57 
58 
59 #endif
60