X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=serpent.c;h=e41f3ceb19c6cad35a7286693bbf24be5f7c16c1;hp=51b27ba688b9581121c36e562f541f969dc7a93a;hb=59938e0ed0c8ac267c3715a25a0a3ed27f7a7e47;hpb=2fe58dfd10216a37f1ece081f926971882de112e diff --git a/serpent.c b/serpent.c index 51b27ba..e41f3ce 100644 --- a/serpent.c +++ b/serpent.c @@ -32,9 +32,10 @@ void serpent_makekey(struct keyInstance *key, int keyLen, uint32_t w[132],k[132]; for(i=0; isubkeys[ 0]); @@ -195,23 +196,23 @@ void serpent_encrypt(struct keyInstance *key, keying(x0, x1, x2, x3, key->subkeys[32]); /* The ciphertext is now in x */ - ciphertext[0] = x0; - ciphertext[1] = x1; - ciphertext[2] = x2; - ciphertext[3] = x3; + PUT_32BIT_MSB_FIRST(ciphertext+12, x0); + PUT_32BIT_MSB_FIRST(ciphertext+8, x1); + PUT_32BIT_MSB_FIRST(ciphertext+4, x2); + PUT_32BIT_MSB_FIRST(ciphertext, x3); } void serpent_decrypt(struct keyInstance *key, - uint32_t ciphertext[4], - uint32_t plaintext[4]) + uint8_t ciphertext[16], + uint8_t plaintext[16]) { register uint32_t x0, x1, x2, x3; register uint32_t y0, y1, y2, y3; - x0=ciphertext[0]; - x1=ciphertext[1]; - x2=ciphertext[2]; - x3=ciphertext[3]; + x0=GET_32BIT_MSB_FIRST(ciphertext+12); + x1=GET_32BIT_MSB_FIRST(ciphertext+8); + x2=GET_32BIT_MSB_FIRST(ciphertext+4); + x3=GET_32BIT_MSB_FIRST(ciphertext); /* Start to decrypt the ciphertext x */ keying(x0, x1, x2, x3, key->subkeys[32]); @@ -313,8 +314,8 @@ void serpent_decrypt(struct keyInstance *key, keying(x0, x1, x2, x3, key->subkeys[ 0]); /* The plaintext is now in x */ - plaintext[0] = x0; - plaintext[1] = x1; - plaintext[2] = x2; - plaintext[3] = x3; + PUT_32BIT_MSB_FIRST(plaintext+12, x0); + PUT_32BIT_MSB_FIRST(plaintext+8, x1); + PUT_32BIT_MSB_FIRST(plaintext+4, x2); + PUT_32BIT_MSB_FIRST(plaintext, x3); }