summaryrefslogtreecommitdiff
path: root/sys/miscfs/tcfs/tcfs_cipher_TDES.c
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-06-17 20:25:56 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-06-17 20:25:56 +0000
commit4101354f3e6be5b49e2d61825c2c7cb7901bec22 (patch)
tree8612e39906950509465ad13ef54daa62b57c09a3 /sys/miscfs/tcfs/tcfs_cipher_TDES.c
parentb12347c7401e730593586ffb0a6fcae647c52f93 (diff)
some KNF
Diffstat (limited to 'sys/miscfs/tcfs/tcfs_cipher_TDES.c')
-rw-r--r--sys/miscfs/tcfs/tcfs_cipher_TDES.c88
1 files changed, 49 insertions, 39 deletions
diff --git a/sys/miscfs/tcfs/tcfs_cipher_TDES.c b/sys/miscfs/tcfs/tcfs_cipher_TDES.c
index c6448b2182a..f90d697336d 100644
--- a/sys/miscfs/tcfs/tcfs_cipher_TDES.c
+++ b/sys/miscfs/tcfs/tcfs_cipher_TDES.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcfs_cipher_TDES.c,v 1.2 2000/06/17 17:32:26 provos Exp $ */
+/* $OpenBSD: tcfs_cipher_TDES.c,v 1.3 2000/06/17 20:25:54 provos Exp $ */
/*
* Copyright 2000 The TCFS Project at http://tcfs.dia.unisa.it/
* All rights reserved.
@@ -28,73 +28,83 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
-#include "tcfs_cipher.h"
+
+#include <miscfs/tcfs/tcfs_cipher.h>
+
#include <crypto/des_locl.h>
#include <crypto/des.h>
-void *TDES_init_key (char *key)
+void *
+TDES_init_key (char *key)
{
des_key_schedule *ks;
- ks=(des_key_schedule *)malloc (2*sizeof (des_key_schedule), M_FREE,M_NOWAIT);
+ ks = (des_key_schedule *)malloc (2 * sizeof (des_key_schedule),
+ M_FREE, M_NOWAIT);
if (!ks)
return NULL;
des_set_key ((des_cblock *)key, ks[0]);
- des_set_key ((des_cblock *)(key+8), ks[1]);
+ des_set_key ((des_cblock *)(key + 8), ks[1]);
return (void *)ks;
}
-void TDES_cleanup_key(void *k)
+void
+TDES_cleanup_key(void *k)
{
/* tcfs_keytab_dispnode does it
free((des_key_schedule*)k,M_FREE);
*/
}
-void TDES_encrypt(char *block, int nb, void *key)
+void
+TDES_encrypt(char *block, int nb, void *key)
{
- unsigned long * xi;
+ u_int32_t * xi;
int i;
char *tmp;
- des_key_schedule *ks=(des_key_schedule *)key;
- xi=(long *)block;
- tmp=block;
- des_ecb3_encrypt((des_cblock *)tmp,(des_cblock *)tmp,ks[0],ks[1],ks[0],DES_ENCRYPT);
- tmp+=8;
- for (i=1;i<nb/8;i++) {
- *(xi+2)^=*xi;
- *(xi+3)^=*(xi+1);
- des_ecb3_encrypt((des_cblock *)tmp,(des_cblock *)tmp,ks[0],ks[1],ks[0],DES_ENCRYPT);
- tmp+=8;
- xi+=2;
+ des_key_schedule *ks = (des_key_schedule *)key;
+
+ xi = (u_int32_t *)block;
+ tmp = block;
+ des_ecb3_encrypt((des_cblock *)tmp, (des_cblock *)tmp,
+ ks[0],ks[1],ks[0],DES_ENCRYPT);
+ tmp += 8;
+ for (i = 1;i < nb/8;i++) {
+ *(xi+2) ^= *xi;
+ *(xi+3) ^= *(xi + 1);
+ des_ecb3_encrypt((des_cblock *)tmp, (des_cblock *)tmp,
+ ks[0], ks[1], ks[0], DES_ENCRYPT);
+ tmp += 8;
+ xi += 2;
}
}
-void TDES_decrypt(char *block, int nb, void *key)
+void
+TDES_decrypt(char *block, int nb, void *key)
{
- unsigned long * xi,xo[2],xa[2];
+ u_int32_t * xi, xo[2], xa[2];
int i;
char *tmp;
- des_key_schedule *ks=(des_key_schedule *)key;
+ des_key_schedule *ks = (des_key_schedule *)key;
- xi=(long *)block;
- tmp=block;
- xo[0]=*xi; xo[1]=*(xi+1);
- des_ecb3_encrypt((des_cblock *)tmp,(des_cblock *)tmp,ks[0],ks[1],ks[0],DES_DECRYPT);
- tmp+=8;
- xi=(long *)tmp;
- for (i=1;i<nb/8;i++) {
- xa[0]=*xi; xa[1]=*(xi+1);
- des_ecb3_encrypt((des_cblock *)tmp,(des_cblock *)tmp,ks[0],ks[1],ks[0],DES_DECRYPT);
- *(xi)^=xo[0];
- *(xi+1)^=xo[1];
- xo[0]=xa[0];
- xo[1]=xa[1];
- tmp+=8;
- xi+=2;
+ xi = (u_int32_t *)block;
+ tmp = block;
+ xo[0] = *xi; xo[1] = *(xi+1);
+ des_ecb3_encrypt((des_cblock *)tmp, (des_cblock *)tmp,
+ ks[0], ks[1], ks[0], DES_DECRYPT);
+ tmp += 8;
+ xi = (u_int32_t *)tmp;
+ for (i = 1;i < nb/8; i++) {
+ xa[0] = *xi; xa[1] = *(xi+1);
+ des_ecb3_encrypt((des_cblock *)tmp, (des_cblock *)tmp,
+ ks[0], ks[1], ks[0], DES_DECRYPT);
+ *(xi) ^= xo[0];
+ *(xi+1)^= xo[1];
+ xo[0] = xa[0];
+ xo[1] = xa[1];
+ tmp += 8;
+ xi += 2;
}
}
-
-