Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
ecdh_derive_test.c File Reference
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <openssl/ec.h>
#include <openssl/x509.h>
#include "../pkcs11.h"
Include dependency graph for ecdh_derive_test.c:

Go to the source code of this file.

Macros

#define DEFAULT_CONNECTOR_URL   "http://127.0.0.1:12345"
 
#define BUFSIZE   1024
 

Functions

int main (int argc, char **argv)
 

Variables

CK_BYTE P224_PARAMS [] = {0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x21}
 
CK_BYTE P256_PARAMS []
 
CK_BYTE P384_PARAMS [] = {0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22}
 
CK_BYTE P521_PARAMS [] = {0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23}
 
CK_FUNCTION_LIST_PTR p11
 
CK_SESSION_HANDLE session = NULL
 
char * CURVES [] = {"secp224r1", "secp384r1", "secp521r1"}
 
CK_BYTECURVE_PARAMS [] = {P224_PARAMS, P384_PARAMS, P521_PARAMS}
 
int CURVE_COUNT = 3
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   1024

Definition at line 36 of file ecdh_derive_test.c.

◆ DEFAULT_CONNECTOR_URL

#define DEFAULT_CONNECTOR_URL   "http://127.0.0.1:12345"

Definition at line 33 of file ecdh_derive_test.c.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 845 of file ecdh_derive_test.c.

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
860 for (int i = 0; i < CURVE_COUNT; i++) {
861
862 printf("\n/////// Testing curve %s\n", CURVES[i]);
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)) {
869 printf("OK!\n");
870 } else {
871 printf("FAIL!\n");
872 exit_status = EXIT_FAILURE;
873 goto c_clean;
874 }
875
876 printf(
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)) {
879 printf("OK!\n");
880 } else {
881 printf("FAIL!\n");
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)) {
888 printf("OK!\n");
889 } else {
890 printf("FAIL!\n");
891 exit_status = EXIT_FAILURE;
892 goto c_clean;
893 }
894
895 printf("Validating ECDH attributes... ");
896 if (validate_ecdh_attributes(ecdh1, "ecdh1")) {
897 printf("OK!\n");
898 } else {
899 printf("FAIL!\n");
900 exit_status = EXIT_FAILURE;
901 goto c_clean;
902 }
903
904 // ------- Start C_FindObjects functions test
905
906 printf("Finding ECDH keys: secret keys... ");
907 if (find_secret_keys(&ecdh1, &ecdh2, &ecdh3)) {
908 printf("OK!\n");
909 } else {
910 printf("FAIL!\n");
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)) {
917 printf("OK!\n");
918 } else {
919 printf("FAIL!\n");
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)) {
926 printf("OK!\n");
927 } else {
928 printf("FAIL!\n");
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)) {
935 printf("OK!\n");
936 } else {
937 printf("FAIL!\n");
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)) {
944 printf("OK!\n");
945 } else {
946 printf("FAIL!\n");
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)) {
953 printf("OK!\n");
954 } else {
955 printf("FAIL!\n");
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)) {
962 printf("OK!\n");
963 } else {
964 printf("FAIL!\n");
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)) {
971 printf("OK!\n");
972 } else {
973 printf("FAIL!\n");
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)) {
980 printf("OK!\n");
981 } else {
982 printf("FAIL!\n");
983 exit_status = EXIT_FAILURE;
984 goto c_clean;
985 }
986
987 // ------- End C_FindObjects functions test
988
989 printf("Destroying ECDH key 1... ");
990 destroy_object(ecdh1);
991 if (find_secret_extractable_keys(&ecdh1, &ecdh2, &ecdh3, 2)) {
992 printf("OK!\n");
993 } else {
994 printf("FAIL!\n");
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)) {
1002 printf("OK!\n");
1003 } else {
1004 printf("FAIL!\n");
1005 exit_status = EXIT_FAILURE;
1006 goto c_clean;
1007 }
1008
1009 printf("Testing decryption... ");
1010 if (test_decrypt(&ecdh2)) {
1011 printf("OK!\n");
1012 } else {
1013 printf("FAIL!\n");
1014 exit_status = EXIT_FAILURE;
1015 goto c_clean;
1016 }
1017
1018 printf("Testing signing... ");
1019 if (test_sign(&ecdh2)) {
1020 printf("OK!\n");
1021 } else {
1022 printf("FAIL!\n");
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)) {
1030 printf("OK!\n");
1031 } else {
1032 printf("FAIL!\n");
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}
int CURVE_COUNT
CK_BYTE * CURVE_PARAMS[]
char * CURVES[]
char ** argv
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30

Variable Documentation

◆ CURVE_COUNT

int CURVE_COUNT = 3

Definition at line 49 of file ecdh_derive_test.c.

◆ CURVE_PARAMS

CK_BYTE* CURVE_PARAMS[] = {P224_PARAMS, P384_PARAMS, P521_PARAMS}

Definition at line 48 of file ecdh_derive_test.c.

CK_BYTE P384_PARAMS[]
CK_BYTE P224_PARAMS[]
CK_BYTE P521_PARAMS[]

◆ CURVES

char* CURVES[] = {"secp224r1", "secp384r1", "secp521r1"}

Definition at line 47 of file ecdh_derive_test.c.

47{"secp224r1", "secp384r1", "secp521r1"};

◆ p11

Definition at line 44 of file ecdh_derive_test.c.

◆ P224_PARAMS

CK_BYTE P224_PARAMS[] = {0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x21}

Definition at line 38 of file ecdh_derive_test.c.

38{0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x21};

◆ P256_PARAMS

CK_BYTE P256_PARAMS[]
Initial value:
= {0x06, 0x08, 0x2a, 0x86, 0x48,
0xce, 0x3d, 0x03, 0x01, 0x07}

Definition at line 39 of file ecdh_derive_test.c.

39 {0x06, 0x08, 0x2a, 0x86, 0x48,
40 0xce, 0x3d, 0x03, 0x01, 0x07};

◆ P384_PARAMS

CK_BYTE P384_PARAMS[] = {0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22}

Definition at line 41 of file ecdh_derive_test.c.

41{0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22};

◆ P521_PARAMS

CK_BYTE P521_PARAMS[] = {0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23}

Definition at line 42 of file ecdh_derive_test.c.

42{0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23};

◆ session

c_gr_out session = NULL

Definition at line 45 of file ecdh_derive_test.c.