]> andersk Git - openssh.git/blobdiff - cipher.c
20010115
[openssh.git] / cipher.c
index 46ca830e3b9f7a770e7edf1c7df9a3b2d5405c7f..89e3c279fcc52179b403a2e1885a043297bc34f7 100644 (file)
--- a/cipher.c
+++ b/cipher.c
@@ -35,7 +35,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: cipher.c,v 1.39 2000/12/06 23:05:42 markus Exp $");
+RCSID("$OpenBSD: cipher.c,v 1.41 2000/12/19 23:17:56 markus Exp $");
 
 #include "ssh.h"
 #include "xmalloc.h"
@@ -177,7 +177,7 @@ des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
 void
 blowfish_setkey(CipherContext *cc, const u_char *key, u_int keylen)
 {
-       BF_set_key(&cc->u.bf.key, keylen, (unsigned char *)key);
+       BF_set_key(&cc->u.bf.key, keylen, (u_char *)key);
 }
 void
 blowfish_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
@@ -207,7 +207,7 @@ blowfish_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
  * and after encryption/decryption. Thus the swap_bytes stuff (yuk).
  */
 static void
-swap_bytes(const unsigned char *src, unsigned char *dst, int n)
+swap_bytes(const u_char *src, u_char *dst, int n)
 {
        char c[4];
 
@@ -260,7 +260,7 @@ arcfour_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
 void
 cast_setkey(CipherContext *cc, const u_char *key, u_int keylen)
 {
-       CAST_set_key(&cc->u.cast.key, keylen, (unsigned char *) key);
+       CAST_set_key(&cc->u.cast.key, keylen, (u_char *) key);
 }
 void
 cast_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
@@ -285,45 +285,40 @@ cast_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
 /* RIJNDAEL */
 
 #define RIJNDAEL_BLOCKSIZE 16
-
 void
 rijndael_setkey(CipherContext *cc, const u_char *key, u_int keylen)
 {
-       if (rijndael_makekey(&cc->u.rijndael.enc, RIJNDAEL_ENCRYPT,
-                   8*keylen, (char *)key) == -1)
-               fatal("rijndael_setkey: RIJNDAEL_ENCRYPT");
-       if (rijndael_makekey(&cc->u.rijndael.dec, RIJNDAEL_DECRYPT,
-                   8*keylen, (char *)key) == -1)
-               fatal("rijndael_setkey: RIJNDAEL_DECRYPT");
+       rijndael_set_key(&cc->u.rijndael.enc, (u4byte *)key, 8*keylen, 1);
+       rijndael_set_key(&cc->u.rijndael.dec, (u4byte *)key, 8*keylen, 0);
 }
 void
 rijndael_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
 {
-       if (iv == NULL || ivlen != RIJNDAEL_BLOCKSIZE
-               fatal("bad/no IV for %s.", cc->cipher->name);
-       memcpy(cc->u.rijndael.iv, iv, RIJNDAEL_BLOCKSIZE);
+       if (iv == NULL) 
+               fatal("no IV for %s.", cc->cipher->name);
+       memcpy((u_char *)cc->u.rijndael.iv, iv, RIJNDAEL_BLOCKSIZE);
 }
-
 void
 rijndael_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
     u_int len)
 {
-       rijndael_key *ctx = &cc->u.rijndael.enc;
-       u_char *iv = cc->u.rijndael.iv;
-       u_char in[RIJNDAEL_BLOCKSIZE];
-       u_char *cprev, *cnow, *plain;
-       int i, j, blocks = len / RIJNDAEL_BLOCKSIZE;
+       rijndael_ctx *ctx = &cc->u.rijndael.enc;
+       u4byte *iv = cc->u.rijndael.iv;
+       u4byte in[4];
+       u4byte *cprev, *cnow, *plain;
+       int i, blocks = len / RIJNDAEL_BLOCKSIZE;
        if (len == 0)
                return;
        if (len % RIJNDAEL_BLOCKSIZE)
                fatal("rijndael_cbc_encrypt: bad len %d", len);
-       cnow  = dest;
-       plain = (u_char *) src;
+       cnow  = (u4byte*) dest;
+       plain = (u4byte*) src;
        cprev = iv;
-       for(i = 0; i < blocks; i++, plain+=RIJNDAEL_BLOCKSIZE,
-           cnow+=RIJNDAEL_BLOCKSIZE) {
-               for (j = 0; j < RIJNDAEL_BLOCKSIZE; j++)
-                       in[j] = plain[j] ^ cprev[j];
+       for(i = 0; i < blocks; i++, plain+=4, cnow+=4) {
+               in[0] = plain[0] ^ cprev[0];
+               in[1] = plain[1] ^ cprev[1];
+               in[2] = plain[2] ^ cprev[2];
+               in[3] = plain[3] ^ cprev[3];
                rijndael_encrypt(ctx, in, cnow);
                cprev = cnow;
        }
@@ -334,25 +329,25 @@ void
 rijndael_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
     u_int len)
 {
-       rijndael_key *ctx = &cc->u.rijndael.dec;
-       u_char *iv = cc->u.rijndael.iv;
-       u_char ivsaved[RIJNDAEL_BLOCKSIZE];
-       u_char *cnow  = (u_char *) (src+len-RIJNDAEL_BLOCKSIZE);
-       u_char *plain = dest+len-RIJNDAEL_BLOCKSIZE;
-       u_char *ivp;
-       int i, j, blocks = len / RIJNDAEL_BLOCKSIZE;
+       rijndael_ctx *ctx = &cc->u.rijndael.dec;
+       u4byte *iv = cc->u.rijndael.iv;
+       u4byte ivsaved[4];
+       u4byte *cnow =  (u4byte*) (src+len-RIJNDAEL_BLOCKSIZE);
+       u4byte *plain = (u4byte*) (dest+len-RIJNDAEL_BLOCKSIZE);
+       u4byte *ivp;
+       int i, blocks = len / RIJNDAEL_BLOCKSIZE;
        if (len == 0)
                return;
        if (len % RIJNDAEL_BLOCKSIZE)
                fatal("rijndael_cbc_decrypt: bad len %d", len);
        memcpy(ivsaved, cnow, RIJNDAEL_BLOCKSIZE);
-       for(i = blocks; i > 0; i--, cnow-=RIJNDAEL_BLOCKSIZE,
-           plain-=RIJNDAEL_BLOCKSIZE) {
+       for(i = blocks; i > 0; i--, cnow-=4, plain-=4) {
                rijndael_decrypt(ctx, cnow, plain);
-               //rijndael_decrypt(cnow, plain, ctx->keySched, ctx->ROUNDS);
-               ivp = (i == 1) ? iv : cnow-RIJNDAEL_BLOCKSIZE;
-               for (j = 0; j < RIJNDAEL_BLOCKSIZE; j++)
-                       plain[j] ^= ivp[j];
+               ivp =  (i == 1) ? iv : cnow-4;
+               plain[0] ^= ivp[0];
+               plain[1] ^= ivp[1];
+               plain[2] ^= ivp[2];
+               plain[3] ^= ivp[3];
        }
        memcpy(iv, ivsaved, RIJNDAEL_BLOCKSIZE);
 }
@@ -424,10 +419,10 @@ Cipher ciphers[] = {
 
 /*--*/
 
-unsigned int
+u_int
 cipher_mask_ssh1(int client)
 {
-       unsigned int mask = 0;
+       u_int mask = 0;
        mask |= 1 << SSH_CIPHER_3DES;           /* Mandatory */
        mask |= 1 << SSH_CIPHER_BLOWFISH;
        if (client) {
@@ -546,7 +541,7 @@ cipher_set_key_string(CipherContext *cc, Cipher *cipher,
     const char *passphrase)
 {
        MD5_CTX md;
-       unsigned char digest[16];
+       u_char digest[16];
 
        MD5_Init(&md);
        MD5_Update(&md, (const u_char *)passphrase, strlen(passphrase));
This page took 1.237058 seconds and 4 git commands to generate.