4 * Skein256 Hash Algorithm.
6 * Derived from cryptoapi implementation, adapted for in-place
7 * scatterlist interface.
9 * Copyright (c) Eric Rost <eric.rost@mybabylon.net>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
17 #include <linux/types.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <crypto/internal/hash.h>
21 #include "skein_base.h"
23 static int skein256_init(struct shash_desc
*desc
)
25 return skein_256_init((struct skein_256_ctx
*)shash_desc_ctx(desc
),
26 SKEIN256_DIGEST_BIT_SIZE
);
29 static int skein256_update(struct shash_desc
*desc
, const u8
*data
,
32 return skein_256_update((struct skein_256_ctx
*)shash_desc_ctx(desc
),
36 static int skein256_final(struct shash_desc
*desc
, u8
*out
)
38 return skein_256_final((struct skein_256_ctx
*)shash_desc_ctx(desc
),
42 static int skein256_export(struct shash_desc
*desc
, void *out
)
44 struct skein_256_ctx
*sctx
= shash_desc_ctx(desc
);
46 memcpy(out
, sctx
, sizeof(*sctx
));
50 static int skein256_import(struct shash_desc
*desc
, const void *in
)
52 struct skein_256_ctx
*sctx
= shash_desc_ctx(desc
);
54 memcpy(sctx
, in
, sizeof(*sctx
));
58 static int skein512_init(struct shash_desc
*desc
)
60 return skein_512_init((struct skein_512_ctx
*)shash_desc_ctx(desc
),
61 SKEIN512_DIGEST_BIT_SIZE
);
64 static int skein512_update(struct shash_desc
*desc
, const u8
*data
,
67 return skein_512_update((struct skein_512_ctx
*)shash_desc_ctx(desc
),
71 static int skein512_final(struct shash_desc
*desc
, u8
*out
)
73 return skein_512_final((struct skein_512_ctx
*)shash_desc_ctx(desc
),
77 static int skein512_export(struct shash_desc
*desc
, void *out
)
79 struct skein_512_ctx
*sctx
= shash_desc_ctx(desc
);
81 memcpy(out
, sctx
, sizeof(*sctx
));
85 static int skein512_import(struct shash_desc
*desc
, const void *in
)
87 struct skein_512_ctx
*sctx
= shash_desc_ctx(desc
);
89 memcpy(sctx
, in
, sizeof(*sctx
));
93 static int skein1024_init(struct shash_desc
*desc
)
95 return skein_1024_init((struct skein_1024_ctx
*)shash_desc_ctx(desc
),
96 SKEIN1024_DIGEST_BIT_SIZE
);
99 static int skein1024_update(struct shash_desc
*desc
, const u8
*data
,
102 return skein_1024_update((struct skein_1024_ctx
*)shash_desc_ctx(desc
),
106 static int skein1024_final(struct shash_desc
*desc
, u8
*out
)
108 return skein_1024_final((struct skein_1024_ctx
*)shash_desc_ctx(desc
),
112 static int skein1024_export(struct shash_desc
*desc
, void *out
)
114 struct skein_1024_ctx
*sctx
= shash_desc_ctx(desc
);
116 memcpy(out
, sctx
, sizeof(*sctx
));
120 static int skein1024_import(struct shash_desc
*desc
, const void *in
)
122 struct skein_1024_ctx
*sctx
= shash_desc_ctx(desc
);
124 memcpy(sctx
, in
, sizeof(*sctx
));
128 static struct shash_alg alg256
= {
129 .digestsize
= (SKEIN256_DIGEST_BIT_SIZE
/ 8),
130 .init
= skein256_init
,
131 .update
= skein256_update
,
132 .final
= skein256_final
,
133 .export
= skein256_export
,
134 .import
= skein256_import
,
135 .descsize
= sizeof(struct skein_256_ctx
),
136 .statesize
= sizeof(struct skein_256_ctx
),
138 .cra_name
= "skein256",
139 .cra_driver_name
= "skein",
140 .cra_flags
= CRYPTO_ALG_TYPE_SHASH
,
141 .cra_blocksize
= SKEIN_256_BLOCK_BYTES
,
142 .cra_module
= THIS_MODULE
,
146 static struct shash_alg alg512
= {
147 .digestsize
= (SKEIN512_DIGEST_BIT_SIZE
/ 8),
148 .init
= skein512_init
,
149 .update
= skein512_update
,
150 .final
= skein512_final
,
151 .export
= skein512_export
,
152 .import
= skein512_import
,
153 .descsize
= sizeof(struct skein_512_ctx
),
154 .statesize
= sizeof(struct skein_512_ctx
),
156 .cra_name
= "skein512",
157 .cra_driver_name
= "skein",
158 .cra_flags
= CRYPTO_ALG_TYPE_SHASH
,
159 .cra_blocksize
= SKEIN_512_BLOCK_BYTES
,
160 .cra_module
= THIS_MODULE
,
164 static struct shash_alg alg1024
= {
165 .digestsize
= (SKEIN1024_DIGEST_BIT_SIZE
/ 8),
166 .init
= skein1024_init
,
167 .update
= skein1024_update
,
168 .final
= skein1024_final
,
169 .export
= skein1024_export
,
170 .import
= skein1024_import
,
171 .descsize
= sizeof(struct skein_1024_ctx
),
172 .statesize
= sizeof(struct skein_1024_ctx
),
174 .cra_name
= "skein1024",
175 .cra_driver_name
= "skein",
176 .cra_flags
= CRYPTO_ALG_TYPE_SHASH
,
177 .cra_blocksize
= SKEIN_1024_BLOCK_BYTES
,
178 .cra_module
= THIS_MODULE
,
182 static int __init
skein_generic_init(void)
184 if (crypto_register_shash(&alg256
))
186 if (crypto_register_shash(&alg512
))
188 if (crypto_register_shash(&alg1024
))
194 crypto_unregister_shash(&alg512
);
196 crypto_unregister_shash(&alg256
);
201 static void __exit
skein_generic_fini(void)
203 crypto_unregister_shash(&alg256
);
204 crypto_unregister_shash(&alg512
);
205 crypto_unregister_shash(&alg1024
);
208 module_init(skein_generic_init
);
209 module_exit(skein_generic_fini
);
211 MODULE_LICENSE("GPL");
212 MODULE_DESCRIPTION("Skein Hash Algorithm");
214 MODULE_ALIAS("skein");