Commit f3617f9d authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Add smp_copy_signspace() and smp_trunc_signspace() utility functions

smp_copy_signspace() will copy the sign data of one space onto another.

smp_trunc_signspace() will truncate the signed space to len bytes and
resign the space.
parent a0c9a8e9
......@@ -207,6 +207,9 @@ void smp_def_signspace(const struct smp_sc *sc, struct smp_signspace *spc,
int smp_chk_signspace(struct smp_signspace *spc);
void smp_append_signspace(struct smp_signspace *spc, uint32_t len);
void smp_reset_signspace(struct smp_signspace *spc);
void smp_copy_signspace(struct smp_signspace *dst,
const struct smp_signspace *src);
void smp_trunc_signspace(struct smp_signspace *spc, uint32_t len);
void smp_newsilo(struct smp_sc *sc);
int smp_valid_silo(struct smp_sc *sc);
......
......@@ -223,6 +223,37 @@ smp_reset_signspace(struct smp_signspace *spc)
smp_reset_sign(&spc->ctx);
}
/*--------------------------------------------------------------------
* Copy the contents of one signspace to another. Prepare for
* appending.
*/
void
smp_copy_signspace(struct smp_signspace *dst, const struct smp_signspace *src)
{
assert(SIGNSPACE_LEN(src) <= dst->size);
smp_reset_signspace(dst);
memcpy(SIGNSPACE_DATA(dst), SIGNSPACE_DATA(src), SIGNSPACE_LEN(src));
smp_append_signspace(dst, SIGNSPACE_LEN(src));
assert(SIGNSPACE_LEN(src) == SIGNSPACE_LEN(dst));
}
/*--------------------------------------------------------------------
* Reapplies the sign over the len first bytes of the
* signspace. Prepares for appending.
*/
void
smp_trunc_signspace(struct smp_signspace *spc, uint32_t len)
{
assert(len <= SIGNSPACE_LEN(spc));
spc->ctx.ss->length = 0;
SHA256_Init(&spc->ctx.ctx);
SHA256_Update(&spc->ctx.ctx, spc->ctx.ss,
offsetof(struct smp_sign, length));
smp_append_signspace(spc, len);
}
/*--------------------------------------------------------------------
* Create a new signature space and force the signature to backing store.
*/
......
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