mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
xen/sha2: Export additional sha256 functions
In future, some code needs to generate a digest over several separate buffers so export the necessary functions to do so. Adjust sha2_256_final() to have a proper digest parameter. Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
e0d0af238d
commit
aea52ce607
2 files changed
+15
-11
No files matched your search
@@ -12,4 +12,15 @@
|
||||
void sha2_256_digest(uint8_t digest[SHA2_256_DIGEST_SIZE],
|
||||
const void *msg, size_t len);
|
||||
|
||||
struct sha2_256_state {
|
||||
uint32_t state[SHA2_256_DIGEST_SIZE / sizeof(uint32_t)];
|
||||
uint8_t buf[64];
|
||||
size_t count; /* Byte count. */
|
||||
};
|
||||
|
||||
void sha2_256_init(struct sha2_256_state *s);
|
||||
void sha2_256_update(struct sha2_256_state *s, const void *msg, size_t len);
|
||||
void sha2_256_final(struct sha2_256_state *s,
|
||||
uint8_t digest[SHA2_256_DIGEST_SIZE]);
|
||||
|
||||
#endif /* XEN_SHA2_H */
|
||||
+4
-11
@@ -10,12 +10,6 @@
|
||||
#include <xen/string.h>
|
||||
#include <xen/unaligned.h>
|
||||
|
||||
struct sha2_256_state {
|
||||
uint32_t state[SHA2_256_DIGEST_SIZE / sizeof(uint32_t)];
|
||||
uint8_t buf[64];
|
||||
size_t count; /* Byte count. */
|
||||
};
|
||||
|
||||
static uint32_t choose(uint32_t x, uint32_t y, uint32_t z)
|
||||
{
|
||||
return z ^ (x & (y ^ z));
|
||||
@@ -131,7 +125,7 @@ static void sha2_256_transform(uint32_t *state, const void *_input)
|
||||
state[4] += e; state[5] += f; state[6] += g; state[7] += h;
|
||||
}
|
||||
|
||||
static void sha2_256_init(struct sha2_256_state *s)
|
||||
void sha2_256_init(struct sha2_256_state *s)
|
||||
{
|
||||
*s = (struct sha2_256_state){
|
||||
.state = {
|
||||
@@ -147,8 +141,7 @@ static void sha2_256_init(struct sha2_256_state *s)
|
||||
};
|
||||
}
|
||||
|
||||
static void sha2_256_update(struct sha2_256_state *s, const void *msg,
|
||||
size_t len)
|
||||
void sha2_256_update(struct sha2_256_state *s, const void *msg, size_t len)
|
||||
{
|
||||
unsigned int partial = s->count & 63;
|
||||
|
||||
@@ -177,9 +170,9 @@ static void sha2_256_update(struct sha2_256_state *s, const void *msg,
|
||||
memcpy(s->buf + partial, msg, len);
|
||||
}
|
||||
|
||||
static void sha2_256_final(struct sha2_256_state *s, void *_dst)
|
||||
void sha2_256_final(struct sha2_256_state *s, uint8_t digest[SHA2_256_DIGEST_SIZE])
|
||||
{
|
||||
uint32_t *dst = _dst;
|
||||
uint32_t *dst = (uint32_t *)digest;
|
||||
unsigned int i, partial = s->count & 63;
|
||||
|
||||
/* Start padding */
|
||||
|
||||