summaryrefslogtreecommitdiff
path: root/cipher/des.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-08-14 19:07:57 +0000
committerWerner Koch <wk@gnupg.org>2002-08-14 19:07:57 +0000
commitb356ebe0062c684bc74b8db03c531baaa2db3ce1 (patch)
tree22bd52b574da32dbc94c920cc9797454228c7d6c /cipher/des.c
parentefecf3b78ad57fd6f260af15a669e021f33ee079 (diff)
downloadlibgcrypt-b356ebe0062c684bc74b8db03c531baaa2db3ce1.tar.gz
* gcrypt.h: Add GCRY_CIPGER_DES. Included string.h for size_t.
Suggested by Simon Josefsson. * gcrypt.texi: Typo fixes. * des.c (do_des_setkey,do_des_encrypt, do_des_decrypt): New. (_gcry_des_get_info): Support plain old DES. * cipher.c (setup_cipher_table): Put DES into the table.
Diffstat (limited to 'cipher/des.c')
-rw-r--r--cipher/des.c65
1 files changed, 60 insertions, 5 deletions
diff --git a/cipher/des.c b/cipher/des.c
index 1c86107b..6a9e620f 100644
--- a/cipher/des.c
+++ b/cipher/des.c
@@ -150,10 +150,16 @@ burn_stack (int bytes)
/* Some defines/checks to support standalone modules */
-#ifndef CIPHER_ALGO_3DES
- #define CIPHER_ALGO_3DES 2
-#elif CIPHER_ALGO_3DES != 2
- #error CIPHER_ALGO_3DES is defined to a wrong value.
+#ifndef GCRY_CIPHER_3DES
+# define CIPHER_ALGO_3DES 2
+#elif GCRY_CIPHER_3DES != 2
+# error CIPHER_ALGO_3DES is defined to a wrong value.
+#endif
+
+#ifndef GCRY_CIPHER_DES
+# define CIPHER_ALGO_DES 302
+#elif GCRY_CIPHER_DES != 302
+# error CIPHER_ALGO_DES is defined to a wrong value.
#endif
@@ -988,6 +994,43 @@ do_tripledes_decrypt( struct _tripledes_ctx *ctx, byte *outbuf, byte *inbuf )
}
+
+
+static int
+do_des_setkey ( struct _des_ctx *ctx, byte *key, unsigned keylen )
+{
+ if( selftest_failed )
+ return GCRYERR_SELFTEST;
+ if( keylen != 8 )
+ return GCRYERR_INV_KEYLEN;
+
+ des_setkey (ctx, key);
+
+ if( is_weak_key( key ) ) {
+ burn_stack (64);
+ return GCRYERR_WEAK_KEY;
+ }
+ burn_stack (64);
+
+ return 0;
+}
+
+
+static void
+do_des_encrypt( struct _des_ctx *ctx, byte *outbuf, byte *inbuf )
+{
+ des_ecb_encrypt ( ctx, inbuf, outbuf );
+ burn_stack (32);
+}
+
+static void
+do_des_decrypt( struct _des_ctx *ctx, byte *outbuf, byte *inbuf )
+{
+ des_ecb_decrypt ( ctx, inbuf, outbuf );
+ burn_stack (32);
+}
+
+
/****************
* Return some information about the algorithm. We need algo here to
* distinguish different flavors of the algorithm.
@@ -1015,7 +1058,7 @@ _gcry_des_get_info( int algo, size_t *keylen,
}
- if( algo == CIPHER_ALGO_3DES ) {
+ if( algo == GCRY_CIPHER_3DES ) {
*keylen = 192;
*blocksize = 8;
*contextsize = sizeof(struct _tripledes_ctx);
@@ -1027,6 +1070,18 @@ _gcry_des_get_info( int algo, size_t *keylen,
= do_tripledes_decrypt;
return "3DES";
}
+ else if( algo == GCRY_CIPHER_DES ) {
+ *keylen = 64;
+ *blocksize = 8;
+ *contextsize = sizeof(struct _des_ctx);
+ *(int (**)(struct _des_ctx*, byte*, unsigned))r_setkey
+ = do_des_setkey;
+ *(void (**)(struct _des_ctx*, byte*, byte*))r_encrypt
+ = do_des_encrypt;
+ *(void (**)(struct _des_ctx*, byte*, byte*))r_decrypt
+ = do_des_decrypt;
+ return "DES";
+ }
return NULL;
}