2017-07-01 22:39:26 +00:00
|
|
|
/*
|
2023-11-30 01:43:03 +00:00
|
|
|
* Copyright (c) 2017,2023 Stephen Heumann
|
2017-07-01 22:39:26 +00:00
|
|
|
*
|
2024-06-27 02:46:58 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2017-07-01 22:39:26 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2017-06-29 21:54:49 +00:00
|
|
|
struct sha1_context {
|
2017-07-01 03:53:59 +00:00
|
|
|
unsigned long length;
|
|
|
|
unsigned long length2;
|
|
|
|
unsigned short extra;
|
|
|
|
unsigned char reserved1[30];
|
|
|
|
unsigned char hash[20];
|
2017-07-01 22:39:26 +00:00
|
|
|
unsigned char block[64];
|
2017-07-01 03:53:59 +00:00
|
|
|
unsigned char reserved2[16];
|
2017-06-29 21:54:49 +00:00
|
|
|
};
|
|
|
|
|
2023-11-30 01:43:03 +00:00
|
|
|
struct hmac_sha1_context {
|
|
|
|
union {
|
|
|
|
struct sha1_context ctx;
|
|
|
|
unsigned char k[64];
|
|
|
|
} u[3];
|
|
|
|
unsigned char inner_hash[20];
|
|
|
|
};
|
|
|
|
|
2017-07-01 22:39:26 +00:00
|
|
|
/*
|
|
|
|
* The context structure must be in bank 0, preferably page-aligned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a SHA-1 context.
|
|
|
|
* This must be called before any of the other SHA-1 functions.
|
|
|
|
*/
|
2017-07-01 03:53:59 +00:00
|
|
|
void sha1_init(struct sha1_context *context);
|
|
|
|
|
2017-07-01 22:39:26 +00:00
|
|
|
/*
|
|
|
|
* Update a SHA-1 context based on the specified data.
|
|
|
|
*/
|
2017-07-01 03:53:59 +00:00
|
|
|
void sha1_update(struct sha1_context *context, const unsigned char *data, unsigned long length);
|
|
|
|
|
2017-07-01 22:39:26 +00:00
|
|
|
/*
|
|
|
|
* Finish SHA-1 processing and generate the final hash code.
|
|
|
|
*/
|
2017-07-01 03:53:59 +00:00
|
|
|
void sha1_finalize(struct sha1_context *context);
|
2017-07-01 22:39:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process one 64-byte block through the SHA-1 hashing function.
|
|
|
|
* This is a low-level function; users should normally not call this directly.
|
|
|
|
*/
|
|
|
|
void sha1_processblock(struct sha1_context *context);
|
2023-11-30 01:43:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a context for HMAC-SHA1 computation with a specified key.
|
2024-04-15 23:29:01 +00:00
|
|
|
* This must be called before any other HMAC calls. After initialization,
|
|
|
|
* the context can be used with either hmac_sha1_update/hmac_sha1_finalize
|
|
|
|
* or hmac_sha1_compute, but they should not be mixed.
|
2023-11-30 01:43:03 +00:00
|
|
|
*/
|
|
|
|
void hmac_sha1_init(struct hmac_sha1_context *context,
|
|
|
|
const unsigned char *key,
|
|
|
|
unsigned long key_length);
|
|
|
|
|
|
|
|
/*
|
2024-04-15 23:29:01 +00:00
|
|
|
* Update an HMAC-SHA1 context based on the specified data.
|
|
|
|
*/
|
|
|
|
void hmac_sha1_update(struct hmac_sha1_context *context,
|
|
|
|
const unsigned char *message_part,
|
|
|
|
unsigned long part_length);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish HMAC-SHA1 processing and generate the final HMAC.
|
|
|
|
*/
|
|
|
|
void hmac_sha1_finalize(struct hmac_sha1_context *context);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the HMAC-SHA1 of a message as a single operation.
|
|
|
|
* The context can be reused for multiple hmac_sha1_compute operations.
|
2023-11-30 01:43:03 +00:00
|
|
|
*/
|
|
|
|
void hmac_sha1_compute(struct hmac_sha1_context *context,
|
|
|
|
const unsigned char *message,
|
|
|
|
unsigned long message_length);
|
2024-04-15 23:39:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the result of an HMAC-SHA1 computation following hmac_sha1_finalize
|
|
|
|
* or hmac_sha1_compute.
|
|
|
|
*/
|
|
|
|
#define hmac_sha1_result(context) ((context)->u[0].ctx.hash)
|