frosix

Multiparty signature service (experimental)
Log | Files | Refs | README | LICENSE

test_frosix.c (6660B)


      1 /**
      2  *
      3 */
      4 #include <stdio.h>
      5 #include <string.h>
      6 #include <time.h>
      7 #include "frosix_service.h"
      8 #include "frosix_backend.h"
      9 #include <gnunet/gnunet_util_lib.h>
     10 #include <gnunet/gnunet_curl_lib.h>
     11 #include "platform.h"
     12 #include "frost_high.h"
     13 
     14 #define HASHCONTEXTVAL "FROSIX-DKG-ID"
     15 
     16 
     17 /**
     18  * State for a "config" CMD.
     19  */
     20 struct ConfigState
     21 {
     22   /**
     23    * The interpreter state.
     24    */
     25   struct GNUNET_CURL_Context *ctx;
     26 
     27   struct GNUNET_CURL_RescheduleContext *rc;
     28 
     29   /**
     30    * URL of the frosix backend.
     31    */
     32   const char *frosix_url;
     33 
     34   /**
     35    * Expected status code.
     36    */
     37   unsigned int http_status;
     38 
     39   /**
     40    * The /config GET operation handle.
     41    */
     42   struct FROSIX_ConfigOperation *so;
     43 
     44   /**
     45    * The salt value from server.
     46    */
     47   struct FROSIX_ProviderSaltP provider_salt;
     48 };
     49 
     50 static void
     51 config_cb (void *cls,
     52            unsigned int http_status,
     53            const struct FROSIX_Config *config)
     54 {
     55   fprintf (stderr, "test\n");
     56   struct ConfigState *ss = cls;
     57 
     58   ss->so = NULL;
     59   if (http_status != ss->http_status)
     60   {
     61     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     62                 "Unexpected response code %u",
     63                 http_status);
     64     return;
     65   }
     66   if (NULL == config)
     67   {
     68     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     69                 "Config is NULL");
     70     return;
     71   }
     72   ss->provider_salt = config->provider_salt;
     73 
     74 }
     75 
     76 
     77 int
     78 main (void)
     79 {
     80   GNUNET_log_setup ("WARNING",
     81                     NULL,
     82                     NULL);
     83 
     84   struct ConfigState *ss;
     85   ss = GNUNET_new (struct ConfigState);
     86   ss->frosix_url = "http://localhost:9977/";
     87   ss->http_status = MHD_HTTP_OK;
     88   ss->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
     89                               &ss->rc);
     90 
     91   /*ss->so = FROSIX_get_config (&ss->ctx,
     92                               ss->frosix_url,
     93                               &config_cb,
     94                               ss);*/
     95 
     96   FROST_init ();
     97 
     98   uint8_t identifier = 1;
     99   uint8_t num_of_participants = 5;
    100   uint8_t threshold = 3;
    101 
    102   /* Challenge Method */
    103   struct FROST_Scalar scalar_method;
    104   FROST_scalar_random (&scalar_method);
    105 
    106   struct FROST_HashCode challenge_method;
    107   struct FROST_HashState state_method;
    108   FROST_hash_init (&state_method);
    109   FROST_hash_scalar_update (&state_method, &scalar_method);
    110   FROST_hash_final (&state_method, &challenge_method);
    111 
    112   /*Convert to crockford 32 and print*/
    113   char *chall_method;
    114   chall_method = GNUNET_STRINGS_data_to_string_alloc (&challenge_method,
    115                                                       sizeof (challenge_method));
    116   fprintf (stderr, "challenge_method: %s\n", chall_method);
    117 
    118   /* Challenge Data */
    119   struct FROST_Scalar scalar_data;
    120   FROST_scalar_random (&scalar_data);
    121 
    122   struct FROST_HashCode challenge_data;
    123   struct FROST_HashState state_data;
    124   FROST_hash_init (&state_data);
    125   FROST_hash_scalar_update (&state_data, &scalar_data);
    126   FROST_hash_final (&state_data, &challenge_data);
    127 
    128   /*Convert to crockford 32 and print*/
    129   char *chall_data;
    130   chall_data = GNUNET_STRINGS_data_to_string_alloc (&challenge_data,
    131                                                     sizeof (challenge_data));
    132   fprintf (stderr, "challenge_data: %s\n", chall_data);
    133 
    134   /* Context String*/
    135   struct FROST_Scalar scalar_context;
    136   FROST_scalar_random (&scalar_context);
    137 
    138   struct FROST_HashCode context_string;
    139   struct FROST_HashState state_context;
    140   FROST_hash_init (&state_context);
    141   FROST_hash_scalar_update (&state_context, &scalar_context);
    142   FROST_hash_final (&state_context, &context_string);
    143 
    144   /*Convert to crockford 32 and print*/
    145   char *chall_context;
    146   chall_context = GNUNET_STRINGS_data_to_string_alloc (&context_string,
    147                                                        sizeof (context_string));
    148   fprintf (stderr, "context_string: %s\n", chall_context);
    149 
    150   /* ID */
    151   char *secret = "gUfO1KGOKYIFlFQg";
    152   struct FROSIX_ProviderSaltP provider_salt;
    153 
    154   GNUNET_CRYPTO_kdf (&provider_salt,
    155                      sizeof (provider_salt),
    156                      "frosix-provider-salt",
    157                      strlen ("frosix-provider-salt"),
    158                      secret,
    159                      strlen (secret),
    160                      NULL,
    161                      0);
    162 
    163   struct FROST_HashState id_state;
    164   struct FROST_HashCode id;
    165 
    166   FROST_hash_init (&id_state);
    167   FROST_hash_hash_update (&id_state,
    168                           &context_string);
    169   FROST_hash_hash_update (&id_state,
    170                           &challenge_method);
    171   FROST_hash_hash_update (&id_state,
    172                           &challenge_data);
    173   FROST_hash_uint8_update (&id_state,
    174                            identifier);
    175   FROST_hash_uint8_update (&id_state,
    176                            num_of_participants);
    177   FROST_hash_uint8_update (&id_state,
    178                            threshold);
    179   FROST_hash_fixed_update (&id_state,
    180                            &provider_salt.salt,
    181                            sizeof (provider_salt.salt));
    182   FROST_hash_fixed_update (&id_state,
    183                            HASHCONTEXTVAL,
    184                            sizeof (HASHCONTEXTVAL));
    185   FROST_hash_final (&id_state,
    186                     &id);
    187 
    188   /*Convert to crockford 32 and print*/
    189   char *crock_id;
    190   crock_id = GNUNET_STRINGS_data_to_string_alloc (&id,
    191                                                   sizeof (id));
    192   fprintf (stderr, "caller_id: %s\n", crock_id);
    193 
    194   /* Encryption Key */
    195   struct FROST_Scalar enc_key;
    196   FROST_scalar_random (&enc_key);
    197 
    198   /* Convert to crockford 32 and print */
    199   char *crock_key;
    200   crock_key = GNUNET_STRINGS_data_to_string_alloc (&enc_key,
    201                                                    sizeof (enc_key));
    202   fprintf (stderr, "encryption_key: %s\n", crock_key);
    203 
    204   /* Random signing keys */
    205   struct GNUNET_CRYPTO_EddsaPrivateKey private_key;
    206   struct GNUNET_CRYPTO_EddsaPublicKey public_key;
    207   GNUNET_CRYPTO_eddsa_key_create (&private_key);
    208   GNUNET_CRYPTO_eddsa_key_get_public (&private_key,
    209                                       &public_key);
    210 
    211   /* Convert to crockford 32 and pring */
    212   char *priv_key;
    213   char *pub_key;
    214   priv_key = GNUNET_STRINGS_data_to_string_alloc (&private_key,
    215                                                   sizeof (private_key));
    216   pub_key = GNUNET_STRINGS_data_to_string_alloc (&public_key,
    217                                                  sizeof (public_key));
    218 
    219   fprintf (stderr, "private signing key: %s\n", priv_key);
    220   fprintf (stderr, "public signing key: %s\n", pub_key);
    221 
    222 
    223   free (chall_method);
    224   free (chall_data);
    225   free (chall_context);
    226   free (crock_id);
    227   free (crock_key);
    228   free (priv_key);
    229   free (pub_key);
    230 
    231   struct FROST_HashState sig_id_state;
    232   struct FROST_HashCode sig_id_hash;
    233   FROST_hash_init (&sig_id_state);
    234 
    235   return 0;
    236 }