diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/tcrypt.c | 106 | ||||
-rw-r--r-- | crypto/tcrypt.h | 179 |
2 files changed, 180 insertions, 105 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 606777074671..56d0d8b3bcf2 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -762,108 +762,6 @@ out: | |||
762 | crypto_free_tfm(tfm); | 762 | crypto_free_tfm(tfm); |
763 | } | 763 | } |
764 | 764 | ||
765 | static void test_crc32c(void) | ||
766 | { | ||
767 | #define NUMVEC 6 | ||
768 | #define VECSIZE 40 | ||
769 | |||
770 | int i, j, pass; | ||
771 | u32 crc; | ||
772 | u8 b, test_vec[NUMVEC][VECSIZE]; | ||
773 | static u32 vec_results[NUMVEC] = { | ||
774 | 0x0e2c157f, 0xe980ebf6, 0xde74bded, | ||
775 | 0xd579c862, 0xba979ad0, 0x2b29d913 | ||
776 | }; | ||
777 | static u32 tot_vec_results = 0x24c5d375; | ||
778 | |||
779 | struct scatterlist sg[NUMVEC]; | ||
780 | struct crypto_tfm *tfm; | ||
781 | char *fmtdata = "testing crc32c initialized to %08x: %s\n"; | ||
782 | #define SEEDTESTVAL 0xedcba987 | ||
783 | u32 seed; | ||
784 | |||
785 | printk("\ntesting crc32c\n"); | ||
786 | |||
787 | tfm = crypto_alloc_tfm("crc32c", 0); | ||
788 | if (tfm == NULL) { | ||
789 | printk("failed to load transform for crc32c\n"); | ||
790 | return; | ||
791 | } | ||
792 | |||
793 | crypto_digest_init(tfm); | ||
794 | crypto_digest_final(tfm, (u8*)&crc); | ||
795 | printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR"); | ||
796 | |||
797 | /* | ||
798 | * stuff test_vec with known values, simple incrementing | ||
799 | * byte values. | ||
800 | */ | ||
801 | b = 0; | ||
802 | for (i = 0; i < NUMVEC; i++) { | ||
803 | for (j = 0; j < VECSIZE; j++) | ||
804 | test_vec[i][j] = ++b; | ||
805 | sg_set_buf(&sg[i], test_vec[i], VECSIZE); | ||
806 | } | ||
807 | |||
808 | seed = SEEDTESTVAL; | ||
809 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); | ||
810 | crypto_digest_init(tfm); | ||
811 | crypto_digest_final(tfm, (u8*)&crc); | ||
812 | printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ? | ||
813 | "pass" : "ERROR"); | ||
814 | |||
815 | printk("testing crc32c using update/final:\n"); | ||
816 | |||
817 | pass = 1; /* assume all is well */ | ||
818 | |||
819 | for (i = 0; i < NUMVEC; i++) { | ||
820 | seed = ~(u32)0; | ||
821 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); | ||
822 | crypto_digest_init(tfm); | ||
823 | crypto_digest_update(tfm, &sg[i], 1); | ||
824 | crypto_digest_final(tfm, (u8*)&crc); | ||
825 | if (crc == vec_results[i]) { | ||
826 | printk(" %08x:OK", crc); | ||
827 | } else { | ||
828 | printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]); | ||
829 | pass = 0; | ||
830 | } | ||
831 | } | ||
832 | |||
833 | printk("\ntesting crc32c using incremental accumulator:\n"); | ||
834 | crc = 0; | ||
835 | for (i = 0; i < NUMVEC; i++) { | ||
836 | seed = (crc ^ ~(u32)0); | ||
837 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); | ||
838 | crypto_digest_init(tfm); | ||
839 | crypto_digest_update(tfm, &sg[i], 1); | ||
840 | crypto_digest_final(tfm, (u8*)&crc); | ||
841 | } | ||
842 | if (crc == tot_vec_results) { | ||
843 | printk(" %08x:OK", crc); | ||
844 | } else { | ||
845 | printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results); | ||
846 | pass = 0; | ||
847 | } | ||
848 | |||
849 | printk("\ntesting crc32c using digest:\n"); | ||
850 | seed = ~(u32)0; | ||
851 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); | ||
852 | crypto_digest_init(tfm); | ||
853 | crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc); | ||
854 | if (crc == tot_vec_results) { | ||
855 | printk(" %08x:OK", crc); | ||
856 | } else { | ||
857 | printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results); | ||
858 | pass = 0; | ||
859 | } | ||
860 | |||
861 | printk("\n%s\n", pass ? "pass" : "ERROR"); | ||
862 | |||
863 | crypto_free_tfm(tfm); | ||
864 | printk("crc32c test complete\n"); | ||
865 | } | ||
866 | |||
867 | static void test_available(void) | 765 | static void test_available(void) |
868 | { | 766 | { |
869 | char **name = check; | 767 | char **name = check; |
@@ -969,7 +867,7 @@ static void do_test(void) | |||
969 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); | 867 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
970 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); | 868 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
971 | test_deflate(); | 869 | test_deflate(); |
972 | test_crc32c(); | 870 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
973 | #ifdef CONFIG_CRYPTO_HMAC | 871 | #ifdef CONFIG_CRYPTO_HMAC |
974 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); | 872 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); |
975 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); | 873 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); |
@@ -1065,7 +963,7 @@ static void do_test(void) | |||
1065 | break; | 963 | break; |
1066 | 964 | ||
1067 | case 18: | 965 | case 18: |
1068 | test_crc32c(); | 966 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
1069 | break; | 967 | break; |
1070 | 968 | ||
1071 | case 19: | 969 | case 19: |
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h index 1fac5602f633..408d5aad5864 100644 --- a/crypto/tcrypt.h +++ b/crypto/tcrypt.h | |||
@@ -28,7 +28,7 @@ | |||
28 | struct hash_testvec { | 28 | struct hash_testvec { |
29 | /* only used with keyed hash algorithms */ | 29 | /* only used with keyed hash algorithms */ |
30 | char key[128] __attribute__ ((__aligned__(4))); | 30 | char key[128] __attribute__ ((__aligned__(4))); |
31 | char plaintext[128]; | 31 | char plaintext[240]; |
32 | char digest[MAX_DIGEST_SIZE]; | 32 | char digest[MAX_DIGEST_SIZE]; |
33 | unsigned char tap[MAX_TAP]; | 33 | unsigned char tap[MAX_TAP]; |
34 | unsigned char psize; | 34 | unsigned char psize; |
@@ -2897,6 +2897,183 @@ static struct hash_testvec michael_mic_tv_template[] = { | |||
2897 | }; | 2897 | }; |
2898 | 2898 | ||
2899 | /* | 2899 | /* |
2900 | * CRC32C test vectors | ||
2901 | */ | ||
2902 | #define CRC32C_TEST_VECTORS 14 | ||
2903 | |||
2904 | static struct hash_testvec crc32c_tv_template[] = { | ||
2905 | { | ||
2906 | .psize = 0, | ||
2907 | .digest = { 0x00, 0x00, 0x00, 0x00 } | ||
2908 | }, | ||
2909 | { | ||
2910 | .key = { 0x87, 0xa9, 0xcb, 0xed }, | ||
2911 | .ksize = 4, | ||
2912 | .psize = 0, | ||
2913 | .digest = { 0x78, 0x56, 0x34, 0x12 }, | ||
2914 | }, | ||
2915 | { | ||
2916 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
2917 | .ksize = 4, | ||
2918 | .plaintext = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | ||
2919 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | ||
2920 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, | ||
2921 | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, | ||
2922 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28 }, | ||
2923 | .psize = 40, | ||
2924 | .digest = { 0x7f, 0x15, 0x2c, 0x0e } | ||
2925 | }, | ||
2926 | { | ||
2927 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
2928 | .ksize = 4, | ||
2929 | .plaintext = { 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, | ||
2930 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, | ||
2931 | 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, | ||
2932 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | ||
2933 | 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50 }, | ||
2934 | .psize = 40, | ||
2935 | .digest = { 0xf6, 0xeb, 0x80, 0xe9 } | ||
2936 | }, | ||
2937 | { | ||
2938 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
2939 | .ksize = 4, | ||
2940 | .plaintext = { 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | ||
2941 | 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, | ||
2942 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, | ||
2943 | 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, | ||
2944 | 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78 }, | ||
2945 | .psize = 40, | ||
2946 | .digest = { 0xed, 0xbd, 0x74, 0xde } | ||
2947 | }, | ||
2948 | { | ||
2949 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
2950 | .ksize = 4, | ||
2951 | .plaintext = { 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, | ||
2952 | 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, | ||
2953 | 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, | ||
2954 | 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, | ||
2955 | 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0 }, | ||
2956 | .psize = 40, | ||
2957 | .digest = { 0x62, 0xc8, 0x79, 0xd5 } | ||
2958 | }, | ||
2959 | { | ||
2960 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
2961 | .ksize = 4, | ||
2962 | .plaintext = { 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, | ||
2963 | 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, | ||
2964 | 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, | ||
2965 | 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, | ||
2966 | 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8 }, | ||
2967 | .psize = 40, | ||
2968 | .digest = { 0xd0, 0x9a, 0x97, 0xba } | ||
2969 | }, | ||
2970 | { | ||
2971 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
2972 | .ksize = 4, | ||
2973 | .plaintext = { 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, | ||
2974 | 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, | ||
2975 | 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, | ||
2976 | 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, | ||
2977 | 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0 }, | ||
2978 | .psize = 40, | ||
2979 | .digest = { 0x13, 0xd9, 0x29, 0x2b } | ||
2980 | }, | ||
2981 | { | ||
2982 | .key = { 0x80, 0xea, 0xd3, 0xf1 }, | ||
2983 | .ksize = 4, | ||
2984 | .plaintext = { 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, | ||
2985 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, | ||
2986 | 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, | ||
2987 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | ||
2988 | 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50 }, | ||
2989 | .psize = 40, | ||
2990 | .digest = { 0x0c, 0xb5, 0xe2, 0xa2 } | ||
2991 | }, | ||
2992 | { | ||
2993 | .key = { 0xf3, 0x4a, 0x1d, 0x5d }, | ||
2994 | .ksize = 4, | ||
2995 | .plaintext = { 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | ||
2996 | 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, | ||
2997 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, | ||
2998 | 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, | ||
2999 | 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78 }, | ||
3000 | .psize = 40, | ||
3001 | .digest = { 0xd1, 0x7f, 0xfb, 0xa6 } | ||
3002 | }, | ||
3003 | { | ||
3004 | .key = { 0x2e, 0x80, 0x04, 0x59 }, | ||
3005 | .ksize = 4, | ||
3006 | .plaintext = { 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, | ||
3007 | 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, | ||
3008 | 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, | ||
3009 | 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, | ||
3010 | 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0 }, | ||
3011 | .psize = 40, | ||
3012 | .digest = { 0x59, 0x33, 0xe6, 0x7a } | ||
3013 | }, | ||
3014 | { | ||
3015 | .key = { 0xa6, 0xcc, 0x19, 0x85 }, | ||
3016 | .ksize = 4, | ||
3017 | .plaintext = { 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, | ||
3018 | 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, | ||
3019 | 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, | ||
3020 | 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, | ||
3021 | 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8 }, | ||
3022 | .psize = 40, | ||
3023 | .digest = { 0xbe, 0x03, 0x01, 0xd2 } | ||
3024 | }, | ||
3025 | { | ||
3026 | .key = { 0x41, 0xfc, 0xfe, 0x2d }, | ||
3027 | .ksize = 4, | ||
3028 | .plaintext = { 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, | ||
3029 | 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, | ||
3030 | 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, | ||
3031 | 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, | ||
3032 | 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0 }, | ||
3033 | .psize = 40, | ||
3034 | .digest = { 0x75, 0xd3, 0xc5, 0x24 } | ||
3035 | }, | ||
3036 | { | ||
3037 | .key = { 0xff, 0xff, 0xff, 0xff }, | ||
3038 | .ksize = 4, | ||
3039 | .plaintext = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | ||
3040 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | ||
3041 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, | ||
3042 | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, | ||
3043 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, | ||
3044 | 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, | ||
3045 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, | ||
3046 | 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, | ||
3047 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | ||
3048 | 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, | ||
3049 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | ||
3050 | 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, | ||
3051 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, | ||
3052 | 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, | ||
3053 | 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, | ||
3054 | 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, | ||
3055 | 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, | ||
3056 | 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, | ||
3057 | 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, | ||
3058 | 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, | ||
3059 | 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, | ||
3060 | 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, | ||
3061 | 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, | ||
3062 | 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, | ||
3063 | 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, | ||
3064 | 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, | ||
3065 | 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, | ||
3066 | 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, | ||
3067 | 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, | ||
3068 | 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0 }, | ||
3069 | .psize = 240, | ||
3070 | .digest = { 0x75, 0xd3, 0xc5, 0x24 }, | ||
3071 | .np = 2, | ||
3072 | .tap = { 31, 209 } | ||
3073 | }, | ||
3074 | }; | ||
3075 | |||
3076 | /* | ||
2900 | * Cipher speed tests | 3077 | * Cipher speed tests |
2901 | */ | 3078 | */ |
2902 | static struct cipher_speed aes_speed_template[] = { | 3079 | static struct cipher_speed aes_speed_template[] = { |