| OLD | NEW |
| 1 /* | 1 /* |
| 2 * sha1.h | 2 * sha1.h |
| 3 * | 3 * |
| 4 * interface to the Secure Hash Algorithm v.1 (SHA-1), specified in | 4 * interface to the Secure Hash Algorithm v.1 (SHA-1), specified in |
| 5 * FIPS 180-1 | 5 * FIPS 180-1 |
| 6 * | 6 * |
| 7 * David A. McGrew | 7 * David A. McGrew |
| 8 * Cisco Systems, Inc. | 8 * Cisco Systems, Inc. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 43 * OF THE POSSIBILITY OF SUCH DAMAGE. | 43 * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 44 * | 44 * |
| 45 */ | 45 */ |
| 46 | 46 |
| 47 #ifndef SHA1_H | 47 #ifndef SHA1_H |
| 48 #define SHA1_H | 48 #define SHA1_H |
| 49 | 49 |
| 50 #include "err.h" | 50 #include "err.h" |
| 51 #ifdef OPENSSL |
| 52 #include <openssl/evp.h> |
| 53 #include <stdint.h> |
| 54 |
| 55 typedef EVP_MD_CTX sha1_ctx_t; |
| 56 |
| 57 /* |
| 58 * sha1_init(&ctx) initializes the SHA1 context ctx |
| 59 * |
| 60 * sha1_update(&ctx, msg, len) hashes the len octets starting at msg |
| 61 * into the SHA1 context |
| 62 * |
| 63 * sha1_final(&ctx, output) performs the final processing of the SHA1 |
| 64 * context and writes the result to the 20 octets at output |
| 65 * |
| 66 * Return values are ignored on the EVP functions since all three |
| 67 * of these functions return void. |
| 68 * |
| 69 */ |
| 70 |
| 71 static inline void sha1_init (sha1_ctx_t *ctx) |
| 72 { |
| 73 EVP_MD_CTX_init(ctx); |
| 74 EVP_DigestInit(ctx, EVP_sha1()); |
| 75 } |
| 76 |
| 77 static inline void sha1_update (sha1_ctx_t *ctx, const uint8_t *M, int octets_in
_msg) |
| 78 { |
| 79 EVP_DigestUpdate(ctx, M, octets_in_msg); |
| 80 } |
| 81 |
| 82 static inline void sha1_final (sha1_ctx_t *ctx, uint32_t *output) |
| 83 { |
| 84 unsigned int len = 0; |
| 85 |
| 86 EVP_DigestFinal(ctx, (unsigned char*)output, &len); |
| 87 } |
| 88 #else |
| 51 #include "datatypes.h" | 89 #include "datatypes.h" |
| 52 | 90 |
| 53 typedef struct { | 91 typedef struct { |
| 54 uint32_t H[5]; /* state vector */ | 92 uint32_t H[5]; /* state vector */ |
| 55 uint32_t M[16]; /* message buffer */ | 93 uint32_t M[16]; /* message buffer */ |
| 56 int octets_in_buffer; /* octets of message in buffer */ | 94 int octets_in_buffer; /* octets of message in buffer */ |
| 57 uint32_t num_bits_in_msg; /* total number of bits in message */ | 95 uint32_t num_bits_in_msg; /* total number of bits in message */ |
| 58 } sha1_ctx_t; | 96 } sha1_ctx_t; |
| 59 | 97 |
| 60 /* | 98 /* |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 * sha1_core(M, H) computes the core sha1 compression function, where M is | 135 * sha1_core(M, H) computes the core sha1 compression function, where M is |
| 98 * the next part of the message and H is the intermediate state {H0, | 136 * the next part of the message and H is the intermediate state {H0, |
| 99 * H1, ...} | 137 * H1, ...} |
| 100 * | 138 * |
| 101 * this function does not do any of the padding required in the | 139 * this function does not do any of the padding required in the |
| 102 * complete sha1 function | 140 * complete sha1 function |
| 103 */ | 141 */ |
| 104 | 142 |
| 105 void | 143 void |
| 106 sha1_core(const uint32_t M[16], uint32_t hash_value[5]); | 144 sha1_core(const uint32_t M[16], uint32_t hash_value[5]); |
| 145 |
| 146 #endif /* else OPENSSL */ |
| 107 | 147 |
| 108 #endif /* SHA1_H */ | 148 #endif /* SHA1_H */ |
| OLD | NEW |