5
5
* Copyright (c) 2022 StarFive Technology
6
6
*/
7
7
8
- #include <linux/iopoll .h>
8
+ #include <crypto/engine .h>
9
9
#include <crypto/gcm.h>
10
- #include <crypto/scatterwalk.h>
11
10
#include <crypto/internal/aead.h>
12
11
#include <crypto/internal/skcipher.h>
12
+ #include <crypto/scatterwalk.h>
13
13
#include "jh7110-cryp.h"
14
+ #include <linux/err.h>
15
+ #include <linux/iopoll.h>
16
+ #include <linux/kernel.h>
17
+ #include <linux/slab.h>
18
+ #include <linux/string.h>
14
19
15
20
#define STARFIVE_AES_REGS_OFFSET 0x100
16
21
#define STARFIVE_AES_AESDIO0R (STARFIVE_AES_REGS_OFFSET + 0x0)
@@ -554,8 +559,6 @@ static int starfive_aes_init_tfm(struct crypto_skcipher *tfm)
554
559
crypto_skcipher_set_reqsize (tfm , sizeof (struct starfive_cryp_request_ctx ) +
555
560
sizeof (struct skcipher_request ));
556
561
557
- ctx -> enginectx .op .do_one_request = starfive_aes_do_one_req ;
558
-
559
562
return 0 ;
560
563
}
561
564
@@ -638,8 +641,6 @@ static int starfive_aes_aead_init_tfm(struct crypto_aead *tfm)
638
641
crypto_aead_set_reqsize (tfm , sizeof (struct starfive_cryp_ctx ) +
639
642
sizeof (struct aead_request ));
640
643
641
- ctx -> enginectx .op .do_one_request = starfive_aes_aead_do_one_req ;
642
-
643
644
return 0 ;
644
645
}
645
646
@@ -844,15 +845,15 @@ static int starfive_aes_ccm_decrypt(struct aead_request *req)
844
845
return starfive_aes_aead_crypt (req , STARFIVE_AES_MODE_CCM );
845
846
}
846
847
847
- static struct skcipher_alg skcipher_algs [] = {
848
+ static struct skcipher_engine_alg skcipher_algs [] = {
848
849
{
849
- .init = starfive_aes_init_tfm ,
850
- .setkey = starfive_aes_setkey ,
851
- .encrypt = starfive_aes_ecb_encrypt ,
852
- .decrypt = starfive_aes_ecb_decrypt ,
853
- .min_keysize = AES_MIN_KEY_SIZE ,
854
- .max_keysize = AES_MAX_KEY_SIZE ,
855
- .base = {
850
+ .base . init = starfive_aes_init_tfm ,
851
+ .base . setkey = starfive_aes_setkey ,
852
+ .base . encrypt = starfive_aes_ecb_encrypt ,
853
+ .base . decrypt = starfive_aes_ecb_decrypt ,
854
+ .base . min_keysize = AES_MIN_KEY_SIZE ,
855
+ .base . max_keysize = AES_MAX_KEY_SIZE ,
856
+ .base . base = {
856
857
.cra_name = "ecb(aes)" ,
857
858
.cra_driver_name = "starfive-ecb-aes" ,
858
859
.cra_priority = 200 ,
@@ -862,15 +863,18 @@ static struct skcipher_alg skcipher_algs[] = {
862
863
.cra_alignmask = 0xf ,
863
864
.cra_module = THIS_MODULE ,
864
865
},
866
+ .op = {
867
+ .do_one_request = starfive_aes_do_one_req ,
868
+ },
865
869
}, {
866
- .init = starfive_aes_init_tfm ,
867
- .setkey = starfive_aes_setkey ,
868
- .encrypt = starfive_aes_cbc_encrypt ,
869
- .decrypt = starfive_aes_cbc_decrypt ,
870
- .min_keysize = AES_MIN_KEY_SIZE ,
871
- .max_keysize = AES_MAX_KEY_SIZE ,
872
- .ivsize = AES_BLOCK_SIZE ,
873
- .base = {
870
+ .base . init = starfive_aes_init_tfm ,
871
+ .base . setkey = starfive_aes_setkey ,
872
+ .base . encrypt = starfive_aes_cbc_encrypt ,
873
+ .base . decrypt = starfive_aes_cbc_decrypt ,
874
+ .base . min_keysize = AES_MIN_KEY_SIZE ,
875
+ .base . max_keysize = AES_MAX_KEY_SIZE ,
876
+ .base . ivsize = AES_BLOCK_SIZE ,
877
+ .base . base = {
874
878
.cra_name = "cbc(aes)" ,
875
879
.cra_driver_name = "starfive-cbc-aes" ,
876
880
.cra_priority = 200 ,
@@ -880,15 +884,18 @@ static struct skcipher_alg skcipher_algs[] = {
880
884
.cra_alignmask = 0xf ,
881
885
.cra_module = THIS_MODULE ,
882
886
},
887
+ .op = {
888
+ .do_one_request = starfive_aes_do_one_req ,
889
+ },
883
890
}, {
884
- .init = starfive_aes_init_tfm ,
885
- .setkey = starfive_aes_setkey ,
886
- .encrypt = starfive_aes_ctr_encrypt ,
887
- .decrypt = starfive_aes_ctr_decrypt ,
888
- .min_keysize = AES_MIN_KEY_SIZE ,
889
- .max_keysize = AES_MAX_KEY_SIZE ,
890
- .ivsize = AES_BLOCK_SIZE ,
891
- .base = {
891
+ .base . init = starfive_aes_init_tfm ,
892
+ .base . setkey = starfive_aes_setkey ,
893
+ .base . encrypt = starfive_aes_ctr_encrypt ,
894
+ .base . decrypt = starfive_aes_ctr_decrypt ,
895
+ .base . min_keysize = AES_MIN_KEY_SIZE ,
896
+ .base . max_keysize = AES_MAX_KEY_SIZE ,
897
+ .base . ivsize = AES_BLOCK_SIZE ,
898
+ .base . base = {
892
899
.cra_name = "ctr(aes)" ,
893
900
.cra_driver_name = "starfive-ctr-aes" ,
894
901
.cra_priority = 200 ,
@@ -898,15 +905,18 @@ static struct skcipher_alg skcipher_algs[] = {
898
905
.cra_alignmask = 0xf ,
899
906
.cra_module = THIS_MODULE ,
900
907
},
908
+ .op = {
909
+ .do_one_request = starfive_aes_do_one_req ,
910
+ },
901
911
}, {
902
- .init = starfive_aes_init_tfm ,
903
- .setkey = starfive_aes_setkey ,
904
- .encrypt = starfive_aes_cfb_encrypt ,
905
- .decrypt = starfive_aes_cfb_decrypt ,
906
- .min_keysize = AES_MIN_KEY_SIZE ,
907
- .max_keysize = AES_MAX_KEY_SIZE ,
908
- .ivsize = AES_BLOCK_SIZE ,
909
- .base = {
912
+ .base . init = starfive_aes_init_tfm ,
913
+ .base . setkey = starfive_aes_setkey ,
914
+ .base . encrypt = starfive_aes_cfb_encrypt ,
915
+ .base . decrypt = starfive_aes_cfb_decrypt ,
916
+ .base . min_keysize = AES_MIN_KEY_SIZE ,
917
+ .base . max_keysize = AES_MAX_KEY_SIZE ,
918
+ .base . ivsize = AES_BLOCK_SIZE ,
919
+ .base . base = {
910
920
.cra_name = "cfb(aes)" ,
911
921
.cra_driver_name = "starfive-cfb-aes" ,
912
922
.cra_priority = 200 ,
@@ -916,15 +926,18 @@ static struct skcipher_alg skcipher_algs[] = {
916
926
.cra_alignmask = 0xf ,
917
927
.cra_module = THIS_MODULE ,
918
928
},
929
+ .op = {
930
+ .do_one_request = starfive_aes_do_one_req ,
931
+ },
919
932
}, {
920
- .init = starfive_aes_init_tfm ,
921
- .setkey = starfive_aes_setkey ,
922
- .encrypt = starfive_aes_ofb_encrypt ,
923
- .decrypt = starfive_aes_ofb_decrypt ,
924
- .min_keysize = AES_MIN_KEY_SIZE ,
925
- .max_keysize = AES_MAX_KEY_SIZE ,
926
- .ivsize = AES_BLOCK_SIZE ,
927
- .base = {
933
+ .base . init = starfive_aes_init_tfm ,
934
+ .base . setkey = starfive_aes_setkey ,
935
+ .base . encrypt = starfive_aes_ofb_encrypt ,
936
+ .base . decrypt = starfive_aes_ofb_decrypt ,
937
+ .base . min_keysize = AES_MIN_KEY_SIZE ,
938
+ .base . max_keysize = AES_MAX_KEY_SIZE ,
939
+ .base . ivsize = AES_BLOCK_SIZE ,
940
+ .base . base = {
928
941
.cra_name = "ofb(aes)" ,
929
942
.cra_driver_name = "starfive-ofb-aes" ,
930
943
.cra_priority = 200 ,
@@ -934,20 +947,23 @@ static struct skcipher_alg skcipher_algs[] = {
934
947
.cra_alignmask = 0xf ,
935
948
.cra_module = THIS_MODULE ,
936
949
},
950
+ .op = {
951
+ .do_one_request = starfive_aes_do_one_req ,
952
+ },
937
953
},
938
954
};
939
955
940
- static struct aead_alg aead_algs [] = {
941
- {
942
- .setkey = starfive_aes_aead_setkey ,
943
- .setauthsize = starfive_aes_gcm_setauthsize ,
944
- .encrypt = starfive_aes_gcm_encrypt ,
945
- .decrypt = starfive_aes_gcm_decrypt ,
946
- .init = starfive_aes_aead_init_tfm ,
947
- .exit = starfive_aes_aead_exit_tfm ,
948
- .ivsize = GCM_AES_IV_SIZE ,
949
- .maxauthsize = AES_BLOCK_SIZE ,
950
- .base = {
956
+ static struct aead_engine_alg aead_algs [] = {
957
+ {
958
+ .base . setkey = starfive_aes_aead_setkey ,
959
+ .base . setauthsize = starfive_aes_gcm_setauthsize ,
960
+ .base . encrypt = starfive_aes_gcm_encrypt ,
961
+ .base . decrypt = starfive_aes_gcm_decrypt ,
962
+ .base . init = starfive_aes_aead_init_tfm ,
963
+ .base . exit = starfive_aes_aead_exit_tfm ,
964
+ .base . ivsize = GCM_AES_IV_SIZE ,
965
+ .base . maxauthsize = AES_BLOCK_SIZE ,
966
+ .base . base = {
951
967
.cra_name = "gcm(aes)" ,
952
968
.cra_driver_name = "starfive-gcm-aes" ,
953
969
.cra_priority = 200 ,
@@ -957,16 +973,19 @@ static struct aead_alg aead_algs[] = {
957
973
.cra_alignmask = 0xf ,
958
974
.cra_module = THIS_MODULE ,
959
975
},
976
+ .op = {
977
+ .do_one_request = starfive_aes_aead_do_one_req ,
978
+ },
960
979
}, {
961
- .setkey = starfive_aes_aead_setkey ,
962
- .setauthsize = starfive_aes_ccm_setauthsize ,
963
- .encrypt = starfive_aes_ccm_encrypt ,
964
- .decrypt = starfive_aes_ccm_decrypt ,
965
- .init = starfive_aes_aead_init_tfm ,
966
- .exit = starfive_aes_aead_exit_tfm ,
967
- .ivsize = AES_BLOCK_SIZE ,
968
- .maxauthsize = AES_BLOCK_SIZE ,
969
- .base = {
980
+ .base . setkey = starfive_aes_aead_setkey ,
981
+ .base . setauthsize = starfive_aes_ccm_setauthsize ,
982
+ .base . encrypt = starfive_aes_ccm_encrypt ,
983
+ .base . decrypt = starfive_aes_ccm_decrypt ,
984
+ .base . init = starfive_aes_aead_init_tfm ,
985
+ .base . exit = starfive_aes_aead_exit_tfm ,
986
+ .base . ivsize = AES_BLOCK_SIZE ,
987
+ .base . maxauthsize = AES_BLOCK_SIZE ,
988
+ .base . base = {
970
989
.cra_name = "ccm(aes)" ,
971
990
.cra_driver_name = "starfive-ccm-aes" ,
972
991
.cra_priority = 200 ,
@@ -977,26 +996,29 @@ static struct aead_alg aead_algs[] = {
977
996
.cra_alignmask = 0xf ,
978
997
.cra_module = THIS_MODULE ,
979
998
},
999
+ .op = {
1000
+ .do_one_request = starfive_aes_aead_do_one_req ,
1001
+ },
980
1002
},
981
1003
};
982
1004
983
1005
int starfive_aes_register_algs (void )
984
1006
{
985
1007
int ret ;
986
1008
987
- ret = crypto_register_skciphers (skcipher_algs , ARRAY_SIZE (skcipher_algs ));
1009
+ ret = crypto_engine_register_skciphers (skcipher_algs , ARRAY_SIZE (skcipher_algs ));
988
1010
if (ret )
989
1011
return ret ;
990
1012
991
- ret = crypto_register_aeads (aead_algs , ARRAY_SIZE (aead_algs ));
1013
+ ret = crypto_engine_register_aeads (aead_algs , ARRAY_SIZE (aead_algs ));
992
1014
if (ret )
993
- crypto_unregister_skciphers (skcipher_algs , ARRAY_SIZE (skcipher_algs ));
1015
+ crypto_engine_unregister_skciphers (skcipher_algs , ARRAY_SIZE (skcipher_algs ));
994
1016
995
1017
return ret ;
996
1018
}
997
1019
998
1020
void starfive_aes_unregister_algs (void )
999
1021
{
1000
- crypto_unregister_aeads (aead_algs , ARRAY_SIZE (aead_algs ));
1001
- crypto_unregister_skciphers (skcipher_algs , ARRAY_SIZE (skcipher_algs ));
1022
+ crypto_engine_unregister_aeads (aead_algs , ARRAY_SIZE (aead_algs ));
1023
+ crypto_engine_unregister_skciphers (skcipher_algs , ARRAY_SIZE (skcipher_algs ));
1002
1024
}
0 commit comments