Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gcm #1908

Closed
wants to merge 12 commits into from
50 changes: 50 additions & 0 deletions core/lib/libtomcrypt/src/encauth/gcm/gcm_mult_h_arm_ce.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2017, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <crypto/ghash-ce-core.h>
#include <io.h>
#include <tomcrypt_arm_neon.h>
#include <tomcrypt.h>
#include <utee_defines.h>

/**
GCM multiply by H
@param gcm The GCM state which holds the H value
@param I The value to multiply H by
*/
void gcm_mult_h(gcm_state *gcm, unsigned char *I)
{
struct tomcrypt_arm_neon_state state;
const uint8_t zeroes[TEE_AES_BLOCK_SIZE] = { 0 };
uint64_t k[2];
uint64_t a;
uint64_t b;
uint64_t dg[2];

b = get_be64(gcm->H);
a = get_be64(gcm->H + 8);

k[0] = (a << 1) | (b >> 63);
k[1] = (b << 1) | (a >> 63);
if (b >> 63)
k[1] ^= 0xc200000000000000UL;

dg[1] = get_be64(I);
dg[0] = get_be64(I + 8);

tomcrypt_arm_neon_enable(&state);
#ifdef CFG_HWSUPP_PMULL
pmull_ghash_update_p64(1, dg, zeroes, k, NULL);
#else
pmull_ghash_update_p8(1, dg, zeroes, k, NULL);
#endif
tomcrypt_arm_neon_disable(&state);

put_be64(I, dg[1]);
put_be64(I + 8, dg[0]);
}

4 changes: 4 additions & 0 deletions core/lib/libtomcrypt/src/encauth/gcm/sub.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
srcs-y += gcm_add_aad.c
srcs-y += gcm_add_iv.c
srcs-y += gcm_done.c
ifeq ($(CFG_CRYPTO_WITH_CE),y)
srcs-y += gcm_mult_h_arm_ce.c
else
srcs-y += gcm_gf_mult.c
endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong place? (should be #else gcm_mult_h.c, not gcm_gf_mult.c)

srcs-y += gcm_init.c
srcs-y += gcm_memory.c
srcs-y += gcm_mult_h.c
Expand Down