4 * s390 implementation of the SHA256 Secure Hash Algorithm.
7 * Copyright IBM Corp. 2005,2007
8 * Author(s): Jan Glauber (jang@de.ibm.com)
10 * Derived from "crypto/sha256_generic.c"
11 * and "arch/s390/crypto/sha1_s390.c"
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
19 #include <crypto/internal/hash.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <crypto/sha.h>
24 #include "crypt_s390.h"
27 static int sha256_init(struct shash_desc
*desc
)
29 struct s390_sha_ctx
*sctx
= shash_desc_ctx(desc
);
31 sctx
->state
[0] = SHA256_H0
;
32 sctx
->state
[1] = SHA256_H1
;
33 sctx
->state
[2] = SHA256_H2
;
34 sctx
->state
[3] = SHA256_H3
;
35 sctx
->state
[4] = SHA256_H4
;
36 sctx
->state
[5] = SHA256_H5
;
37 sctx
->state
[6] = SHA256_H6
;
38 sctx
->state
[7] = SHA256_H7
;
40 sctx
->func
= KIMD_SHA_256
;
45 static int sha256_export(struct shash_desc
*desc
, void *out
)
47 struct s390_sha_ctx
*sctx
= shash_desc_ctx(desc
);
48 struct sha256_state
*octx
= out
;
50 octx
->count
= sctx
->count
;
51 memcpy(octx
->state
, sctx
->state
, sizeof(octx
->state
));
52 memcpy(octx
->buf
, sctx
->buf
, sizeof(octx
->buf
));
56 static int sha256_import(struct shash_desc
*desc
, const void *in
)
58 struct s390_sha_ctx
*sctx
= shash_desc_ctx(desc
);
59 const struct sha256_state
*ictx
= in
;
61 sctx
->count
= ictx
->count
;
62 memcpy(sctx
->state
, ictx
->state
, sizeof(ictx
->state
));
63 memcpy(sctx
->buf
, ictx
->buf
, sizeof(ictx
->buf
));
64 sctx
->func
= KIMD_SHA_256
;
68 static struct shash_alg alg
= {
69 .digestsize
= SHA256_DIGEST_SIZE
,
71 .update
= s390_sha_update
,
72 .final
= s390_sha_final
,
73 .export
= sha256_export
,
74 .import
= sha256_import
,
75 .descsize
= sizeof(struct s390_sha_ctx
),
76 .statesize
= sizeof(struct sha256_state
),
79 .cra_driver_name
= "sha256-s390",
80 .cra_priority
= CRYPT_S390_PRIORITY
,
81 .cra_flags
= CRYPTO_ALG_TYPE_SHASH
,
82 .cra_blocksize
= SHA256_BLOCK_SIZE
,
83 .cra_module
= THIS_MODULE
,
87 static int sha256_s390_init(void)
89 if (!crypt_s390_func_available(KIMD_SHA_256
))
92 return crypto_register_shash(&alg
);
95 static void __exit
sha256_s390_fini(void)
97 crypto_unregister_shash(&alg
);
100 module_init(sha256_s390_init
);
101 module_exit(sha256_s390_fini
);
103 MODULE_ALIAS("sha256");
104 MODULE_LICENSE("GPL");
105 MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm");