Commit ab9552e1 authored by Geoff Simmons's avatar Geoff Simmons

Move code around in anticipation of adding the encryption VFP.

parent e834e299
......@@ -95,6 +95,41 @@ suck_bytes(struct vfp_ctx *ctx, void *ptr, size_t *lenp)
return (vp);
}
static inline void
seq_inc(struct ece *ece)
{
CHECK_OBJ_NOTNULL(ece, ECE_MAGIC);
if (ece->seq_lo < UINT64_MAX)
ece->seq_lo++;
else {
assert(ece->seq_hi != UINT32_MAX);
ece->seq_hi++;
ece->seq_lo = 0;
}
}
static inline void
nonce_xor_seq(struct ece *ece, uint8_t *nonce)
{
uint32_t nonce_hi;
uint64_t nonce_lo;
CHECK_OBJ_NOTNULL(ece, ECE_MAGIC);
CHECK_OBJ_NOTNULL(ece->crypto, ECE_CRYPTO_MAGIC);
AN(nonce);
nonce_hi = ece->crypto->prenonce_hi ^ ece->seq_hi;
nonce_lo = ece->crypto->prenonce_lo ^ ece->seq_lo;
vbe32enc(nonce, nonce_hi);
vbe64enc(nonce + 4, nonce_lo);
}
/**
** VFP decrypt
**/
/*
* RFC8188 ch 2: "The final encoding consists of a header ... and zero or
* more fixed-size encrypted records ..."
......@@ -175,37 +210,6 @@ decrypt_init(struct ece *ece, struct vfp_ctx *ctx)
return (VFP_OK);
}
static inline void
seq_inc(struct ece *ece)
{
CHECK_OBJ_NOTNULL(ece, ECE_MAGIC);
if (ece->seq_lo < UINT64_MAX)
ece->seq_lo++;
else {
assert(ece->seq_hi != UINT32_MAX);
ece->seq_hi++;
ece->seq_lo = 0;
}
}
static inline void
nonce_xor_seq(struct ece *ece, uint8_t *nonce)
{
uint32_t nonce_hi;
uint64_t nonce_lo;
CHECK_OBJ_NOTNULL(ece, ECE_MAGIC);
CHECK_OBJ_NOTNULL(ece->crypto, ECE_CRYPTO_MAGIC);
AN(nonce);
nonce_hi = ece->crypto->prenonce_hi ^ ece->seq_hi;
nonce_lo = ece->crypto->prenonce_lo ^ ece->seq_lo;
vbe32enc(nonce, nonce_hi);
vbe64enc(nonce + 4, nonce_lo);
}
static enum vfp_status
decrypt(struct ece *ece, struct vfp_ctx *ctx, unsigned char *plaintext,
size_t *lenp, enum vfp_status vp)
......@@ -242,8 +246,6 @@ decrypt(struct ece *ece, struct vfp_ctx *ctx, unsigned char *plaintext,
return (vp);
}
/* VFP interface */
static enum vfp_status v_matchproto_(vfp_init_f)
vfp_decrypt_init(struct vfp_ctx *ctx, struct vfp_entry *ent)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment