Skip to content

Commit

Permalink
crypto_aesctr: move pblk into struct crypto_aesctr
Browse files Browse the repository at this point in the history
This moves the counter block (aka pblk) into the structure; minimizing
the next commit.
  • Loading branch information
gperciva committed Dec 16, 2020
1 parent 2b5a2bc commit 9ff90c2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crypto/crypto_aesctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct crypto_aesctr {
uint64_t nonce;
uint64_t bytectr;
uint8_t buf[16];
uint8_t pblk[16];
};

/**
Expand Down Expand Up @@ -93,17 +94,16 @@ crypto_aesctr_init(const struct crypto_aes_key * key, uint64_t nonce)
static inline void
crypto_aesctr_stream_cipherblock_generate(struct crypto_aesctr * stream)
{
uint8_t pblk[16];

/* Sanity check. */
assert(stream->bytectr % 16 == 0);

/* Prepare nonce and counter. */
be64enc(pblk, stream->nonce);
be64enc(pblk + 8, stream->bytectr / 16);
be64enc(stream->pblk, stream->nonce);
be64enc(stream->pblk + 8, stream->bytectr / 16);

/* Encrypt the cipherblock. */
crypto_aes_encrypt_block(pblk, stream->buf, stream->key);
crypto_aes_encrypt_block(stream->pblk, stream->buf, stream->key);
}

/* Encrypt ${nbytes} bytes, then update ${inbuf}, ${outbuf}, and ${buflen}. */
Expand Down

0 comments on commit 9ff90c2

Please sign in to comment.