/*
- * Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
#include <string.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
-#include "modes_lcl.h"
+#include "crypto/modes.h"
#ifndef OPENSSL_NO_OCB
static void ocb_block_lshift(const unsigned char *in, size_t shift,
unsigned char *out)
{
- unsigned char shift_mask;
int i;
- unsigned char mask[15];
+ unsigned char carry = 0, carry_next;
- shift_mask = 0xff;
- shift_mask <<= (8 - shift);
for (i = 15; i >= 0; i--) {
- if (i > 0) {
- mask[i - 1] = in[i] & shift_mask;
- mask[i - 1] >>= 8 - shift;
- }
- out[i] = in[i] << shift;
-
- if (i != 15) {
- out[i] ^= mask[i];
- }
+ carry_next = in[i] >> (8 - shift);
+ out[i] = (in[i] << shift) | carry;
+ carry = carry_next;
}
}
* the index.
*/
ctx->max_l_index += (idx - ctx->max_l_index + 4) & ~3;
- tmp_ptr =
- OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK));
+ tmp_ptr = OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK));
if (tmp_ptr == NULL) /* prevent ctx->l from being clobbered */
return NULL;
ctx->l = tmp_ptr;
memset(ctx, 0, sizeof(*ctx));
ctx->l_index = 0;
ctx->max_l_index = 5;
- if ((ctx->l = OPENSSL_malloc(ctx->max_l_index * 16)) == NULL) {
- CRYPTOerr(CRYPTO_F_CRYPTO_OCB128_INIT, ERR_R_MALLOC_FAILURE);
+ if ((ctx->l = OPENSSL_malloc(ctx->max_l_index * 16)) == NULL)
return 0;
- }
/*
* We set both the encryption and decryption key schedules - decryption
if (keydec)
dest->keydec = keydec;
if (src->l) {
- if ((dest->l = OPENSSL_malloc(src->max_l_index * 16)) == NULL) {
- CRYPTOerr(CRYPTO_F_CRYPTO_OCB128_COPY_CTX, ERR_R_MALLOC_FAILURE);
+ if ((dest->l = OPENSSL_malloc(src->max_l_index * 16)) == NULL)
return 0;
- }
memcpy(dest->l, src->l, (src->l_index + 1) * 16);
}
return 1;