File indexing completed on 2025-01-18 10:02:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef NETTLE_BASE64_H_INCLUDED
0035 #define NETTLE_BASE64_H_INCLUDED
0036
0037 #include "nettle-types.h"
0038
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042
0043
0044 #define base64_encode_init nettle_base64_encode_init
0045 #define base64url_encode_init nettle_base64url_encode_init
0046 #define base64_encode_single nettle_base64_encode_single
0047 #define base64_encode_update nettle_base64_encode_update
0048 #define base64_encode_final nettle_base64_encode_final
0049 #define base64_encode_raw nettle_base64_encode_raw
0050 #define base64_encode_group nettle_base64_encode_group
0051 #define base64_decode_init nettle_base64_decode_init
0052 #define base64url_decode_init nettle_base64url_decode_init
0053 #define base64_decode_single nettle_base64_decode_single
0054 #define base64_decode_update nettle_base64_decode_update
0055 #define base64_decode_final nettle_base64_decode_final
0056
0057 #define BASE64_BINARY_BLOCK_SIZE 3
0058 #define BASE64_TEXT_BLOCK_SIZE 4
0059
0060
0061
0062
0063
0064
0065 #define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
0066
0067
0068 #define BASE64_ENCODE_FINAL_LENGTH 3
0069
0070
0071
0072 #define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
0073
0074 struct base64_encode_ctx
0075 {
0076 const char *alphabet;
0077 unsigned short word;
0078 unsigned char bits;
0079 };
0080
0081
0082 void
0083 base64_encode_init(struct base64_encode_ctx *ctx);
0084
0085
0086 void
0087 base64url_encode_init(struct base64_encode_ctx *ctx);
0088
0089
0090 size_t
0091 base64_encode_single(struct base64_encode_ctx *ctx,
0092 char *dst,
0093 uint8_t src);
0094
0095
0096
0097 size_t
0098 base64_encode_update(struct base64_encode_ctx *ctx,
0099 char *dst,
0100 size_t length,
0101 const uint8_t *src);
0102
0103
0104
0105 size_t
0106 base64_encode_final(struct base64_encode_ctx *ctx,
0107 char *dst);
0108
0109
0110
0111
0112
0113
0114
0115
0116 void
0117 base64_encode_raw(char *dst, size_t length, const uint8_t *src);
0118
0119 void
0120 base64_encode_group(char *dst, uint32_t group);
0121
0122
0123
0124
0125
0126
0127 #define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
0128
0129 struct base64_decode_ctx
0130 {
0131 const signed char *table;
0132 unsigned short word;
0133 unsigned char bits;
0134
0135
0136 unsigned char padding;
0137 };
0138
0139
0140 void
0141 base64_decode_init(struct base64_decode_ctx *ctx);
0142
0143
0144 void
0145 base64url_decode_init(struct base64_decode_ctx *ctx);
0146
0147
0148
0149 int
0150 base64_decode_single(struct base64_decode_ctx *ctx,
0151 uint8_t *dst,
0152 char src);
0153
0154
0155
0156
0157 int
0158 base64_decode_update(struct base64_decode_ctx *ctx,
0159 size_t *dst_length,
0160 uint8_t *dst,
0161 size_t src_length,
0162 const char *src);
0163
0164
0165 int
0166 base64_decode_final(struct base64_decode_ctx *ctx);
0167
0168 #ifdef __cplusplus
0169 }
0170 #endif
0171
0172 #endif