Go to the documentation of this file.
65 #include "../internal.h"
102 "data length must be a multiple of base64 chunk size");
111 if (((
len << 2) >> 2) !=
len) {
151 assert(
ctx->data_used <
sizeof(
ctx->data));
153 if (
sizeof(
ctx->data) -
ctx->data_used > in_len) {
155 ctx->data_used += (unsigned)in_len;
159 if (
ctx->data_used != 0) {
160 const size_t todo =
sizeof(
ctx->data) -
ctx->data_used;
175 while (in_len >=
sizeof(
ctx->data)) {
177 in +=
sizeof(
ctx->data);
178 in_len -=
sizeof(
ctx->data);
189 total += encoded + 1;
196 ctx->data_used = (unsigned)in_len;
198 if (
total > INT_MAX) {
207 if (
ctx->data_used == 0) {
213 out[encoded++] =
'\n';
219 assert(encoded <= INT_MAX);
220 *out_len = (
int)encoded;
225 size_t remaining = src_len,
ret = 0;
228 if (remaining >= 3) {
237 if (remaining == 2) {
263 *out_len = (
len / 4) * 3;
282 ret |= is_upper & (
a -
'A');
283 ret |= is_lower & (
a -
'a' + 26);
284 ret |= is_digit & (
a -
'0' + 52);
286 ret |= is_slash & 63;
290 is_upper | is_lower | is_digit | is_plus | is_slash | is_equals;
305 if (
a == 0xff ||
b == 0xff ||
c == 0xff ||
d == 0xff) {
312 const unsigned padding_pattern = (
in[0] ==
'=') << 3 |
313 (
in[1] ==
'=') << 2 |
314 (
in[2] ==
'=') << 1 |
317 switch (padding_pattern) {
348 if (
ctx->error_encountered) {
352 size_t bytes_out = 0,
i;
353 for (
i = 0;
i < in_len;
i++) {
354 const char c =
in[
i];
364 ctx->error_encountered = 1;
368 ctx->data[
ctx->data_used++] =
c;
369 if (
ctx->data_used == 4) {
370 size_t num_bytes_resulting;
372 ctx->error_encountered = 1;
377 bytes_out += num_bytes_resulting;
378 out += num_bytes_resulting;
380 if (num_bytes_resulting < 3) {
386 if (bytes_out > INT_MAX) {
387 ctx->error_encountered = 1;
391 *out_len = (
int)bytes_out;
402 if (
ctx->error_encountered ||
ctx->data_used != 0) {
413 if (in_len % 4 != 0) {
423 size_t i, bytes_out = 0;
424 for (
i = 0;
i < in_len;
i += 4) {
425 size_t num_bytes_resulting;
431 bytes_out += num_bytes_resulting;
432 out += num_bytes_resulting;
433 if (num_bytes_resulting != 3 &&
i != in_len - 4) {
438 *out_len = bytes_out;
444 while (src_len > 0) {
445 if (src[0] !=
' ' && src[0] !=
'\t') {
454 while (src_len > 0) {
455 switch (src[src_len-1]) {
476 while (dst_len % 3 != 0) {
477 dst[dst_len++] =
'\0';
479 assert(dst_len <= INT_MAX);
static int base64_decode_quad(uint8_t *out, size_t *out_num_bytes, const uint8_t *in)
int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len)
void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len)
static uint8_t constant_time_lt_args_8(uint8_t a, uint8_t b)
void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
static uint8_t base64_ascii_to_bin(uint8_t a)
int EVP_DecodedLength(size_t *out_len, size_t len)
static void * OPENSSL_memset(void *dst, int c, size_t n)
int EVP_DecodeBase64(uint8_t *out, size_t *out_len, size_t max_out, const uint8_t *in, size_t in_len)
size_t EVP_EncodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len)
static crypto_word_t constant_time_msb_w(crypto_word_t a)
int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len, const uint8_t *in, size_t in_len)
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len, const uint8_t *in, size_t in_len)
static uint8_t constant_time_eq_8(crypto_word_t a, crypto_word_t b)
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx)
int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len)
UniquePtr< SSL_SESSION > ret
void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
static uint8_t constant_time_in_range_8(uint8_t a, uint8_t min, uint8_t max)
EVP_ENCODE_CTX * EVP_ENCODE_CTX_new(void)
int EVP_EncodedLength(size_t *out_len, size_t len)
static uint8_t constant_time_select_8(uint8_t mask, uint8_t a, uint8_t b)
static uint8_t conv_bin2ascii(uint8_t a)
OPENSSL_STATIC_ASSERT(sizeof(((EVP_ENCODE_CTX *)(NULL)) ->data) % 3==0, "data length must be a multiple of base64 chunk size")
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:45