summaryrefslogtreecommitdiff
path: root/cipher/sha1.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1998-06-16 15:13:27 +0000
committerWerner Koch <wk@gnupg.org>1998-06-16 15:13:27 +0000
commita436a4553609f4c231f2c4200ad011e109a1a568 (patch)
tree89abc6d0a21e37aae0d40ec87de9ea4d323d29f2 /cipher/sha1.c
parent91d9566516ffa468ebd1034f32f927d8864b1998 (diff)
downloadlibgcrypt-a436a4553609f4c231f2c4200ad011e109a1a568.tar.gz
some more internall structure changes
Diffstat (limited to 'cipher/sha1.c')
-rw-r--r--cipher/sha1.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/cipher/sha1.c b/cipher/sha1.c
index 941e69b8..0a6ffab2 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -41,6 +41,12 @@
#include "sha1.h"
+typedef struct {
+ u32 h0,h1,h2,h3,h4;
+ u32 nblocks;
+ byte buf[64];
+ int count;
+} SHA1_CONTEXT;
#if defined(__GNUC__) && defined(__i386__)
@@ -216,7 +222,7 @@ transform( SHA1_CONTEXT *hd, byte *data )
/* Update the message digest with the contents
* of INBUF with length INLEN.
*/
-void
+static void
sha1_write( SHA1_CONTEXT *hd, byte *inbuf, size_t inlen)
{
if( hd->count == 64 ) { /* flush the buffer */
@@ -253,7 +259,7 @@ sha1_write( SHA1_CONTEXT *hd, byte *inbuf, size_t inlen)
* Returns: 20 bytes representing the digest.
*/
-void
+static void
sha1_final(SHA1_CONTEXT *hd)
{
u32 t, msb, lsb;
@@ -313,4 +319,42 @@ sha1_final(SHA1_CONTEXT *hd)
}
+static byte *
+sha1_read( SHA1_CONTEXT *hd )
+{
+ return hd->buf;
+}
+
+/****************
+ * Return some information about the algorithm. We need algo here to
+ * distinguish different flavors of the algorithm.
+ * Returns: A pointer to string describing the algorithm or NULL if
+ * the ALGO is invalid.
+ */
+const char *
+sha1_get_info( int algo, size_t *contextsize,
+ byte **r_asnoid, int *r_asnlen, int *r_mdlen,
+ void (**r_init)( void *c ),
+ void (**r_write)( void *c, byte *buf, size_t nbytes ),
+ void (**r_final)( void *c ),
+ byte *(**r_read)( void *c )
+ )
+{
+ static byte asn[15] = /* Object ID is 1.3.14.3.2.26 */
+ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
+ 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
+ if( algo != 2 )
+ return NULL;
+
+ *contextsize = sizeof(SHA1_CONTEXT);
+ *r_asnoid = asn;
+ *r_asnlen = DIM(asn);
+ *r_mdlen = 20;
+ *r_init = (void (*)(void *))sha1_init;
+ *r_write = (void (*)(void *, byte*, size_t))sha1_write;
+ *r_final = (void (*)(void *))sha1_final;
+ *r_read = (byte *(*)(void *))sha1_read;
+
+ return "SHA1";
+}