845 {
846
847 if (argc != 2) {
848 fprintf(stderr, "usage: /path/to/yubihsm_pkcs11/module\n");
849 exit(EXIT_FAILURE);
850 }
851
852 get_function_list(
argv);
853 open_session();
854 print_session_state();
855
856 int exit_status = EXIT_SUCCESS;
857
858 CK_OBJECT_HANDLE yh_pubkey, yh_privkey;
859
861
863
864 generate_keypair_yh(
CURVE_PARAMS[i], &yh_pubkey, &yh_privkey);
865 CK_OBJECT_HANDLE ecdh1, ecdh2, ecdh3;
866
867 printf(
"Testing the value of ECDH key derived by yubihsm-pkcs11... ");
868 if (test_ecdh_value(
CURVES[i], yh_privkey, yh_pubkey, &ecdh1)) {
870 } else {
872 exit_status = EXIT_FAILURE;
873 goto c_clean;
874 }
875
877 "Testing that 2 ECDH keys derived from the same base keys are equal... ");
878 if (test_duplicate_ecdh(
CURVES[i], yh_privkey, &ecdh2, &ecdh3)) {
880 } else {
882 exit_status = EXIT_FAILURE;
883 goto c_clean;
884 }
885
886 printf(
"Testing deriving ECDH keys with faulty parameters... ");
887 if (test_faulty_ecdh(
CURVES[i],
"prime256v1", &yh_privkey, &ecdh1)) {
889 } else {
891 exit_status = EXIT_FAILURE;
892 goto c_clean;
893 }
894
895 printf(
"Validating ECDH attributes... ");
896 if (validate_ecdh_attributes(ecdh1, "ecdh1")) {
898 } else {
900 exit_status = EXIT_FAILURE;
901 goto c_clean;
902 }
903
904
905
906 printf(
"Finding ECDH keys: secret keys... ");
907 if (find_secret_keys(&ecdh1, &ecdh2, &ecdh3)) {
909 } else {
911 exit_status = EXIT_FAILURE;
912 goto c_clean;
913 }
914
915 printf(
"Finding ECDH keys: public keys... ");
916 if (find_public_keys(&ecdh1, &ecdh2, &ecdh3)) {
918 } else {
920 exit_status = EXIT_FAILURE;
921 goto c_clean;
922 }
923
924 printf(
"Finding ECDH keys: secret, extractable keys... ");
925 if (find_secret_extractable_keys(&ecdh1, &ecdh2, &ecdh3, 3)) {
927 } else {
929 exit_status = EXIT_FAILURE;
930 goto c_clean;
931 }
932
933 printf(
"Finding ECDH keys: secret, un-extractable keys... ");
934 if (find_secret_unextractable_keys(&ecdh1, &ecdh2, &ecdh3)) {
936 } else {
938 exit_status = EXIT_FAILURE;
939 goto c_clean;
940 }
941
942 printf(
"Finding ECDH keys: secret, extractable keys with wrong label... ");
943 if (find_secret_extractable_keys_wrong_label(&ecdh1, &ecdh2, &ecdh3)) {
945 } else {
947 exit_status = EXIT_FAILURE;
948 goto c_clean;
949 }
950
951 printf(
"Finding ECDH keys: secret key with specific ID... ");
952 if (find_secret_key_with_id(&ecdh1, &ecdh2, &ecdh3, &yh_privkey)) {
954 } else {
956 exit_status = EXIT_FAILURE;
957 goto c_clean;
958 }
959
960 printf(
"Finding ECDH keys: secret key with right label... ");
961 if (find_secret_key_right_label(&ecdh1, &ecdh2, &ecdh3)) {
963 } else {
965 exit_status = EXIT_FAILURE;
966 goto c_clean;
967 }
968
969 printf(
"Finding ECDH keys: public key with right label... ");
970 if (find_public_key_right_label(&ecdh1, &ecdh2, &ecdh3)) {
972 } else {
974 exit_status = EXIT_FAILURE;
975 goto c_clean;
976 }
977
978 printf(
"Finding ECDH keys: use empty template... ");
979 if (find_empty_template(&ecdh1, &ecdh2, &ecdh3)) {
981 } else {
983 exit_status = EXIT_FAILURE;
984 goto c_clean;
985 }
986
987
988
989 printf(
"Destroying ECDH key 1... ");
990 destroy_object(ecdh1);
991 if (find_secret_extractable_keys(&ecdh1, &ecdh2, &ecdh3, 2)) {
993 } else {
995 exit_status = EXIT_FAILURE;
996 goto c_clean;
997 }
998
999 printf(
"Destroying ECDH key 2... ");
1000 destroy_object(ecdh3);
1001 if (find_secret_extractable_keys(&ecdh1, &ecdh2, &ecdh3, 1)) {
1003 } else {
1005 exit_status = EXIT_FAILURE;
1006 goto c_clean;
1007 }
1008
1009 printf(
"Testing decryption... ");
1010 if (test_decrypt(&ecdh2)) {
1012 } else {
1014 exit_status = EXIT_FAILURE;
1015 goto c_clean;
1016 }
1017
1018 printf(
"Testing signing... ");
1019 if (test_sign(&ecdh2)) {
1021 } else {
1023 exit_status = EXIT_FAILURE;
1024 goto c_clean;
1025 }
1026
1027 printf(
"Destroying ECDH key 3... ");
1028 destroy_object(ecdh2);
1029 if (find_secret_extractable_keys(&ecdh1, &ecdh2, &ecdh3, 0)) {
1031 } else {
1033 exit_status = EXIT_FAILURE;
1034 goto c_clean;
1035 }
1036
1037 destroy_object(yh_privkey);
1038 }
1039
1040c_clean:
1041 if (exit_status == EXIT_FAILURE) {
1042 destroy_object(yh_privkey);
1043 }
1044 close_session();
1045 return (exit_status);
1046}
LOGGING_API void printf(Category category, const char *format,...)