0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef _CRYPTO_INTERNAL_CIPHER_H
0012 #define _CRYPTO_INTERNAL_CIPHER_H
0013
0014 #include <crypto/algapi.h>
0015
0016 struct crypto_cipher {
0017 struct crypto_tfm base;
0018 };
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
0038 {
0039 return (struct crypto_cipher *)tfm;
0040 }
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
0057 u32 type, u32 mask)
0058 {
0059 type &= ~CRYPTO_ALG_TYPE_MASK;
0060 type |= CRYPTO_ALG_TYPE_CIPHER;
0061 mask |= CRYPTO_ALG_TYPE_MASK;
0062
0063 return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
0064 }
0065
0066 static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
0067 {
0068 return &tfm->base;
0069 }
0070
0071
0072
0073
0074
0075 static inline void crypto_free_cipher(struct crypto_cipher *tfm)
0076 {
0077 crypto_free_tfm(crypto_cipher_tfm(tfm));
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
0091 {
0092 type &= ~CRYPTO_ALG_TYPE_MASK;
0093 type |= CRYPTO_ALG_TYPE_CIPHER;
0094 mask |= CRYPTO_ALG_TYPE_MASK;
0095
0096 return crypto_has_alg(alg_name, type, mask);
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
0110 {
0111 return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
0112 }
0113
0114 static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
0115 {
0116 return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
0117 }
0118
0119 static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
0120 {
0121 return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
0122 }
0123
0124 static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
0125 u32 flags)
0126 {
0127 crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
0128 }
0129
0130 static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
0131 u32 flags)
0132 {
0133 crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
0134 }
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 int crypto_cipher_setkey(struct crypto_cipher *tfm,
0153 const u8 *key, unsigned int keylen);
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
0165 u8 *dst, const u8 *src);
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
0177 u8 *dst, const u8 *src);
0178
0179 struct crypto_cipher_spawn {
0180 struct crypto_spawn base;
0181 };
0182
0183 static inline int crypto_grab_cipher(struct crypto_cipher_spawn *spawn,
0184 struct crypto_instance *inst,
0185 const char *name, u32 type, u32 mask)
0186 {
0187 type &= ~CRYPTO_ALG_TYPE_MASK;
0188 type |= CRYPTO_ALG_TYPE_CIPHER;
0189 mask |= CRYPTO_ALG_TYPE_MASK;
0190 return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
0191 }
0192
0193 static inline void crypto_drop_cipher(struct crypto_cipher_spawn *spawn)
0194 {
0195 crypto_drop_spawn(&spawn->base);
0196 }
0197
0198 static inline struct crypto_alg *crypto_spawn_cipher_alg(
0199 struct crypto_cipher_spawn *spawn)
0200 {
0201 return spawn->base.alg;
0202 }
0203
0204 static inline struct crypto_cipher *crypto_spawn_cipher(
0205 struct crypto_cipher_spawn *spawn)
0206 {
0207 u32 type = CRYPTO_ALG_TYPE_CIPHER;
0208 u32 mask = CRYPTO_ALG_TYPE_MASK;
0209
0210 return __crypto_cipher_cast(crypto_spawn_tfm(&spawn->base, type, mask));
0211 }
0212
0213 static inline struct cipher_alg *crypto_cipher_alg(struct crypto_cipher *tfm)
0214 {
0215 return &crypto_cipher_tfm(tfm)->__crt_alg->cra_cipher;
0216 }
0217
0218 #endif