aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/des.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-05-16 08:09:29 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-06-26 03:34:39 -0400
commit6c2bb98bc33ae33c7a33a133a4cd5a06395fece5 (patch)
tree96684cd2c473cd05d651ce1fa3dd72b1b4b19b09 /crypto/des.c
parent43600106e32809a4dead79fec67a63e9860e3d5d (diff)
[CRYPTO] all: Pass tfm instead of ctx to algorithms
Up until now algorithms have been happy to get a context pointer since they know everything that's in the tfm already (e.g., alignment, block size). However, once we have parameterised algorithms, such information will be specific to each tfm. So the algorithm API needs to be changed to pass the tfm structure instead of the context pointer. This patch is basically a text substitution. The only tricky bit is the assembly routines that need to get the context pointer offset through asm-offsets.h. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/des.c')
-rw-r--r--crypto/des.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/crypto/des.c b/crypto/des.c
index 2d74cab40c3e..a9d3c235a6af 100644
--- a/crypto/des.c
+++ b/crypto/des.c
@@ -783,9 +783,10 @@ static void dkey(u32 *pe, const u8 *k)
783 } 783 }
784} 784}
785 785
786static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 786static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
787 unsigned int keylen, u32 *flags)
787{ 788{
788 struct des_ctx *dctx = ctx; 789 struct des_ctx *dctx = crypto_tfm_ctx(tfm);
789 u32 tmp[DES_EXPKEY_WORDS]; 790 u32 tmp[DES_EXPKEY_WORDS];
790 int ret; 791 int ret;
791 792
@@ -803,9 +804,10 @@ static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
803 return 0; 804 return 0;
804} 805}
805 806
806static void des_encrypt(void *ctx, u8 *dst, const u8 *src) 807static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
807{ 808{
808 const u32 *K = ((struct des_ctx *)ctx)->expkey; 809 struct des_ctx *ctx = crypto_tfm_ctx(tfm);
810 const u32 *K = ctx->expkey;
809 const __le32 *s = (const __le32 *)src; 811 const __le32 *s = (const __le32 *)src;
810 __le32 *d = (__le32 *)dst; 812 __le32 *d = (__le32 *)dst;
811 u32 L, R, A, B; 813 u32 L, R, A, B;
@@ -825,9 +827,10 @@ static void des_encrypt(void *ctx, u8 *dst, const u8 *src)
825 d[1] = cpu_to_le32(L); 827 d[1] = cpu_to_le32(L);
826} 828}
827 829
828static void des_decrypt(void *ctx, u8 *dst, const u8 *src) 830static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
829{ 831{
830 const u32 *K = ((struct des_ctx *)ctx)->expkey + DES_EXPKEY_WORDS - 2; 832 struct des_ctx *ctx = crypto_tfm_ctx(tfm);
833 const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2;
831 const __le32 *s = (const __le32 *)src; 834 const __le32 *s = (const __le32 *)src;
832 __le32 *d = (__le32 *)dst; 835 __le32 *d = (__le32 *)dst;
833 u32 L, R, A, B; 836 u32 L, R, A, B;
@@ -860,11 +863,11 @@ static void des_decrypt(void *ctx, u8 *dst, const u8 *src)
860 * property. 863 * property.
861 * 864 *
862 */ 865 */
863static int des3_ede_setkey(void *ctx, const u8 *key, 866static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
864 unsigned int keylen, u32 *flags) 867 unsigned int keylen, u32 *flags)
865{ 868{
866 const u32 *K = (const u32 *)key; 869 const u32 *K = (const u32 *)key;
867 struct des3_ede_ctx *dctx = ctx; 870 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
868 u32 *expkey = dctx->expkey; 871 u32 *expkey = dctx->expkey;
869 872
870 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || 873 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
@@ -881,9 +884,9 @@ static int des3_ede_setkey(void *ctx, const u8 *key,
881 return 0; 884 return 0;
882} 885}
883 886
884static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src) 887static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
885{ 888{
886 struct des3_ede_ctx *dctx = ctx; 889 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
887 const u32 *K = dctx->expkey; 890 const u32 *K = dctx->expkey;
888 const __le32 *s = (const __le32 *)src; 891 const __le32 *s = (const __le32 *)src;
889 __le32 *d = (__le32 *)dst; 892 __le32 *d = (__le32 *)dst;
@@ -912,9 +915,9 @@ static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src)
912 d[1] = cpu_to_le32(L); 915 d[1] = cpu_to_le32(L);
913} 916}
914 917
915static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src) 918static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
916{ 919{
917 struct des3_ede_ctx *dctx = ctx; 920 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
918 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; 921 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2;
919 const __le32 *s = (const __le32 *)src; 922 const __le32 *s = (const __le32 *)src;
920 __le32 *d = (__le32 *)dst; 923 __le32 *d = (__le32 *)dst;