diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2000-10-23 19:31:55 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2000-10-23 19:31:55 +0000 |
commit | 72eea491b3871d914ed964644c6450737c555632 (patch) | |
tree | cbf4677706a82528b8d374db824fcb4d790b4ad3 /usr.bin/ssh/cipher.c | |
parent | 3d97cd5ca69719e7254162249efd8a8cbc86fe45 (diff) |
non-alignment dependent swap_bytes(); from simonb@wasabisystems.com/netbsd
Diffstat (limited to 'usr.bin/ssh/cipher.c')
-rw-r--r-- | usr.bin/ssh/cipher.c | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/usr.bin/ssh/cipher.c b/usr.bin/ssh/cipher.c index b9c1b28abf8..65cde4732a4 100644 --- a/usr.bin/ssh/cipher.c +++ b/usr.bin/ssh/cipher.c @@ -35,7 +35,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: cipher.c,v 1.36 2000/10/14 10:01:15 markus Exp $"); +RCSID("$OpenBSD: cipher.c,v 1.37 2000/10/23 19:31:54 markus Exp $"); #include "ssh.h" #include "xmalloc.h" @@ -218,28 +218,21 @@ 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) -{ - /* dst must be properly aligned. */ - u_int32_t *dst = (u_int32_t *) dst_; - union { - u_int32_t i; - char c[4]; - } t; - - /* Process 8 bytes every lap. */ - for (n = n / 8; n > 0; n--) { - t.c[3] = *src++; - t.c[2] = *src++; - t.c[1] = *src++; - t.c[0] = *src++; - *dst++ = t.i; - - t.c[3] = *src++; - t.c[2] = *src++; - t.c[1] = *src++; - t.c[0] = *src++; - *dst++ = t.i; +swap_bytes(const unsigned char *src, unsigned char *dst, int n) +{ + char c[4]; + + /* Process 4 bytes every lap. */ + for (n = n / 4; n > 0; n--) { + c[3] = *src++; + c[2] = *src++; + c[1] = *src++; + c[0] = *src++; + + *dst++ = c[0]; + *dst++ = c[1]; + *dst++ = c[2]; + *dst++ = c[3]; } } |