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

Libcperciva import #306

Merged
merged 3 commits into from
Feb 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
crypto_aesctr_aesni.c: add shim for _mm_loadu_si64()
Abstracting this function will be useful in the following commit.
  • Loading branch information
gperciva committed Feb 23, 2021
commit fbbdf3cbd99774986db5c59236ea233a2e2b2530
16 changes: 14 additions & 2 deletions libcperciva/crypto/crypto_aesctr_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
*/
#include "crypto_aesctr_shared.c"

/**
* load_si64(mem):
* Load an unaligned 64-bit integer from memory into the lowest 64 bits of the
* returned value. The contents of the upper 64 bits is not defined.
*/
static inline __m128i
load_si64(const void * mem)
{

return (_mm_loadu_si64(mem));
}

/* Process multiple whole blocks by generating & using a cipherblock. */
static void
crypto_aesctr_aesni_stream_wholeblocks(struct crypto_aesctr * stream,
Expand All @@ -44,7 +56,7 @@ crypto_aesctr_aesni_stream_wholeblocks(struct crypto_aesctr * stream,
size_t i;

/* Load local variables from stream. */
nonce_be = _mm_loadu_si64(stream->pblk);
nonce_be = load_si64(stream->pblk);
block_counter = stream->bytectr / 16;

/* How many blocks should we process? */
Expand All @@ -60,7 +72,7 @@ crypto_aesctr_aesni_stream_wholeblocks(struct crypto_aesctr * stream,
be64enc(block_counter_be_arr, block_counter);

/* Encrypt the cipherblock. */
bufsse = _mm_loadu_si64(block_counter_be_arr);
bufsse = load_si64(block_counter_be_arr);
bufsse = _mm_unpacklo_epi64(nonce_be, bufsse);
bufsse = crypto_aes_encrypt_block_aesni_m128i(bufsse,
stream->key);
Expand Down