File indexing completed on 2025-01-18 10:12:40
0001
0002 #ifndef sodium_utils_H
0003 #define sodium_utils_H
0004
0005 #include <stddef.h>
0006
0007 #include "export.h"
0008
0009 #ifdef __cplusplus
0010 extern "C" {
0011 #endif
0012
0013 #ifndef SODIUM_C99
0014 # if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
0015 # define SODIUM_C99(X)
0016 # else
0017 # define SODIUM_C99(X) X
0018 # endif
0019 #endif
0020
0021 SODIUM_EXPORT
0022 void sodium_memzero(void * const pnt, const size_t len);
0023
0024 SODIUM_EXPORT
0025 void sodium_stackzero(const size_t len);
0026
0027
0028
0029
0030
0031
0032
0033 SODIUM_EXPORT
0034 int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
0035 __attribute__ ((warn_unused_result));
0036
0037
0038
0039
0040
0041
0042
0043 SODIUM_EXPORT
0044 int sodium_compare(const unsigned char *b1_, const unsigned char *b2_,
0045 size_t len) __attribute__ ((warn_unused_result));
0046
0047 SODIUM_EXPORT
0048 int sodium_is_zero(const unsigned char *n, const size_t nlen);
0049
0050 SODIUM_EXPORT
0051 void sodium_increment(unsigned char *n, const size_t nlen);
0052
0053 SODIUM_EXPORT
0054 void sodium_add(unsigned char *a, const unsigned char *b, const size_t len);
0055
0056 SODIUM_EXPORT
0057 void sodium_sub(unsigned char *a, const unsigned char *b, const size_t len);
0058
0059 SODIUM_EXPORT
0060 char *sodium_bin2hex(char * const hex, const size_t hex_maxlen,
0061 const unsigned char * const bin, const size_t bin_len)
0062 __attribute__ ((nonnull(1)));
0063
0064 SODIUM_EXPORT
0065 int sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen,
0066 const char * const hex, const size_t hex_len,
0067 const char * const ignore, size_t * const bin_len,
0068 const char ** const hex_end)
0069 __attribute__ ((nonnull(1)));
0070
0071 #define sodium_base64_VARIANT_ORIGINAL 1
0072 #define sodium_base64_VARIANT_ORIGINAL_NO_PADDING 3
0073 #define sodium_base64_VARIANT_URLSAFE 5
0074 #define sodium_base64_VARIANT_URLSAFE_NO_PADDING 7
0075
0076
0077
0078
0079
0080 #define sodium_base64_ENCODED_LEN(BIN_LEN, VARIANT) \
0081 (((BIN_LEN) / 3U) * 4U + \
0082 ((((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) | (((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) >> 1)) & 1U) * \
0083 (4U - (~((((VARIANT) & 2U) >> 1) - 1U) & (3U - ((BIN_LEN) - ((BIN_LEN) / 3U) * 3U)))) + 1U)
0084
0085 SODIUM_EXPORT
0086 size_t sodium_base64_encoded_len(const size_t bin_len, const int variant);
0087
0088 SODIUM_EXPORT
0089 char *sodium_bin2base64(char * const b64, const size_t b64_maxlen,
0090 const unsigned char * const bin, const size_t bin_len,
0091 const int variant) __attribute__ ((nonnull(1)));
0092
0093 SODIUM_EXPORT
0094 int sodium_base642bin(unsigned char * const bin, const size_t bin_maxlen,
0095 const char * const b64, const size_t b64_len,
0096 const char * const ignore, size_t * const bin_len,
0097 const char ** const b64_end, const int variant)
0098 __attribute__ ((nonnull(1)));
0099
0100 SODIUM_EXPORT
0101 int sodium_mlock(void * const addr, const size_t len)
0102 __attribute__ ((nonnull));
0103
0104 SODIUM_EXPORT
0105 int sodium_munlock(void * const addr, const size_t len)
0106 __attribute__ ((nonnull));
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 SODIUM_EXPORT
0142 void *sodium_malloc(const size_t size)
0143 __attribute__ ((malloc));
0144
0145 SODIUM_EXPORT
0146 void *sodium_allocarray(size_t count, size_t size)
0147 __attribute__ ((malloc));
0148
0149 SODIUM_EXPORT
0150 void sodium_free(void *ptr);
0151
0152 SODIUM_EXPORT
0153 int sodium_mprotect_noaccess(void *ptr) __attribute__ ((nonnull));
0154
0155 SODIUM_EXPORT
0156 int sodium_mprotect_readonly(void *ptr) __attribute__ ((nonnull));
0157
0158 SODIUM_EXPORT
0159 int sodium_mprotect_readwrite(void *ptr) __attribute__ ((nonnull));
0160
0161 SODIUM_EXPORT
0162 int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
0163 size_t unpadded_buflen, size_t blocksize, size_t max_buflen)
0164 __attribute__ ((nonnull(2)));
0165
0166 SODIUM_EXPORT
0167 int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
0168 size_t padded_buflen, size_t blocksize)
0169 __attribute__ ((nonnull(2)));
0170
0171
0172
0173 int _sodium_alloc_init(void);
0174
0175 #ifdef __cplusplus
0176 }
0177 #endif
0178
0179 #endif