1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/include/sha1.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* 1.5 + * sha1.h 1.6 + * 1.7 + * interface to the Secure Hash Algorithm v.1 (SHA-1), specified in 1.8 + * FIPS 180-1 1.9 + * 1.10 + * David A. McGrew 1.11 + * Cisco Systems, Inc. 1.12 + */ 1.13 + 1.14 +/* 1.15 + * 1.16 + * Copyright (c) 2001-2006, Cisco Systems, Inc. 1.17 + * All rights reserved. 1.18 + * 1.19 + * Redistribution and use in source and binary forms, with or without 1.20 + * modification, are permitted provided that the following conditions 1.21 + * are met: 1.22 + * 1.23 + * Redistributions of source code must retain the above copyright 1.24 + * notice, this list of conditions and the following disclaimer. 1.25 + * 1.26 + * Redistributions in binary form must reproduce the above 1.27 + * copyright notice, this list of conditions and the following 1.28 + * disclaimer in the documentation and/or other materials provided 1.29 + * with the distribution. 1.30 + * 1.31 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.32 + * contributors may be used to endorse or promote products derived 1.33 + * from this software without specific prior written permission. 1.34 + * 1.35 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.36 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.37 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.38 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.39 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.40 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.41 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.42 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.43 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.44 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.45 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.46 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.47 + * 1.48 + */ 1.49 + 1.50 +#ifndef SHA1_H 1.51 +#define SHA1_H 1.52 + 1.53 +#include "err.h" 1.54 +#include "datatypes.h" 1.55 + 1.56 +typedef struct { 1.57 + uint32_t H[5]; /* state vector */ 1.58 + uint32_t M[16]; /* message buffer */ 1.59 + int octets_in_buffer; /* octets of message in buffer */ 1.60 + uint32_t num_bits_in_msg; /* total number of bits in message */ 1.61 +} sha1_ctx_t; 1.62 + 1.63 +/* 1.64 + * sha1(&ctx, msg, len, output) hashes the len octets starting at msg 1.65 + * into the SHA1 context, then writes the result to the 20 octets at 1.66 + * output 1.67 + * 1.68 + */ 1.69 + 1.70 +void 1.71 +sha1(const uint8_t *message, int octets_in_msg, uint32_t output[5]); 1.72 + 1.73 +/* 1.74 + * sha1_init(&ctx) initializes the SHA1 context ctx 1.75 + * 1.76 + * sha1_update(&ctx, msg, len) hashes the len octets starting at msg 1.77 + * into the SHA1 context 1.78 + * 1.79 + * sha1_final(&ctx, output) performs the final processing of the SHA1 1.80 + * context and writes the result to the 20 octets at output 1.81 + * 1.82 + */ 1.83 + 1.84 +void 1.85 +sha1_init(sha1_ctx_t *ctx); 1.86 + 1.87 +void 1.88 +sha1_update(sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg); 1.89 + 1.90 +void 1.91 +sha1_final(sha1_ctx_t *ctx, uint32_t output[5]); 1.92 + 1.93 +/* 1.94 + * The sha1_core function is INTERNAL to SHA-1, but it is declared 1.95 + * here because it is also used by the cipher SEAL 3.0 in its key 1.96 + * setup algorithm. 1.97 + */ 1.98 + 1.99 +/* 1.100 + * sha1_core(M, H) computes the core sha1 compression function, where M is 1.101 + * the next part of the message and H is the intermediate state {H0, 1.102 + * H1, ...} 1.103 + * 1.104 + * this function does not do any of the padding required in the 1.105 + * complete sha1 function 1.106 + */ 1.107 + 1.108 +void 1.109 +sha1_core(const uint32_t M[16], uint32_t hash_value[5]); 1.110 + 1.111 +#endif /* SHA1_H */