diff options
-rw-r--r-- | rijndael.c | 40 |
1 files changed, 6 insertions, 34 deletions
diff --git a/rijndael.c b/rijndael.c index 91ef513c9..0f81a1bd7 100644 --- a/rijndael.c +++ b/rijndael.c | |||
@@ -708,25 +708,20 @@ rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) | |||
708 | return 0; | 708 | return 0; |
709 | } | 709 | } |
710 | 710 | ||
711 | #if 0 | ||
711 | /** | 712 | /** |
712 | * Expand the cipher key into the decryption key schedule. | 713 | * Expand the cipher key into the decryption key schedule. |
713 | * | 714 | * |
714 | * @return the number of rounds for the given cipher key size. | 715 | * @return the number of rounds for the given cipher key size. |
715 | */ | 716 | */ |
716 | int | 717 | int |
717 | rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits, | 718 | rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) |
718 | int have_encrypt) | ||
719 | { | 719 | { |
720 | int Nr, i, j; | 720 | int Nr, i, j; |
721 | u32 temp; | 721 | u32 temp; |
722 | 722 | ||
723 | /* expand the cipher key: */ | 723 | /* expand the cipher key: */ |
724 | if (have_encrypt > 0) { | 724 | Nr = rijndaelKeySetupEnc(rk, cipherKey, keyBits); |
725 | /* Already done */ | ||
726 | Nr = have_encrypt; | ||
727 | } else { | ||
728 | Nr = rijndaelKeySetupEnc(rk, cipherKey, keyBits); | ||
729 | } | ||
730 | 725 | ||
731 | /* invert the order of the round keys: */ | 726 | /* invert the order of the round keys: */ |
732 | for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) { | 727 | for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) { |
@@ -761,6 +756,7 @@ rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits, | |||
761 | } | 756 | } |
762 | return Nr; | 757 | return Nr; |
763 | } | 758 | } |
759 | #endif | ||
764 | 760 | ||
765 | void | 761 | void |
766 | rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], | 762 | rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], |
@@ -946,6 +942,7 @@ rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], | |||
946 | PUTU32(ct + 12, s3); | 942 | PUTU32(ct + 12, s3); |
947 | } | 943 | } |
948 | 944 | ||
945 | #if 0 | ||
949 | static void | 946 | static void |
950 | rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], | 947 | rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], |
951 | u8 pt[16]) | 948 | u8 pt[16]) |
@@ -1129,29 +1126,4 @@ rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], | |||
1129 | rk[3]; | 1126 | rk[3]; |
1130 | PUTU32(pt + 12, s3); | 1127 | PUTU32(pt + 12, s3); |
1131 | } | 1128 | } |
1132 | 1129 | #endif | |
1133 | void | ||
1134 | rijndael_set_key(rijndael_ctx *ctx, u_char *key, int bits, int do_encrypt) | ||
1135 | { | ||
1136 | ctx->Nr = rijndaelKeySetupEnc(ctx->ek, key, bits); | ||
1137 | if (do_encrypt) { | ||
1138 | ctx->decrypt = 0; | ||
1139 | memset(ctx->dk, 0, sizeof(ctx->dk)); | ||
1140 | } else { | ||
1141 | ctx->decrypt = 1; | ||
1142 | memcpy(ctx->dk, ctx->ek, sizeof(ctx->dk)); | ||
1143 | rijndaelKeySetupDec(ctx->dk, key, bits, ctx->Nr); | ||
1144 | } | ||
1145 | } | ||
1146 | |||
1147 | void | ||
1148 | rijndael_decrypt(rijndael_ctx *ctx, u_char *src, u_char *dst) | ||
1149 | { | ||
1150 | rijndaelDecrypt(ctx->dk, ctx->Nr, src, dst); | ||
1151 | } | ||
1152 | |||
1153 | void | ||
1154 | rijndael_encrypt(rijndael_ctx *ctx, u_char *src, u_char *dst) | ||
1155 | { | ||
1156 | rijndaelEncrypt(ctx->ek, ctx->Nr, src, dst); | ||
1157 | } | ||