Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

dsa-verify.c

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    gostdsa-vko-test.c 6.46 KiB
    #include "testutils.h"
    #include "gostdsa.h"
    #include "streebog.h"
    
    static void
    test_vko (const struct ecc_curve *ecc,
    	  const char *priv,
    	  const char *x,
    	  const char *y,
    	  const struct tstring *ukm,
    	  const struct nettle_hash *hash,
    	  void * hash_ctx,
    	  const struct tstring *res)
    {
        struct ecc_scalar ecc_key;
        struct ecc_point ecc_pub;
        mpz_t temp1, temp2;
        uint8_t out[128];
        size_t out_len = ((ecc_bit_size(ecc) + 7) / 8) * 2;
    
        ASSERT(out_len <= sizeof(out));
    
        ecc_point_init (&ecc_pub, ecc);
        mpz_init_set_str (temp1, x, 16);
        mpz_init_set_str (temp2, y, 16);
        ASSERT (ecc_point_set (&ecc_pub, temp1, temp2) != 0);
    
        ecc_scalar_init (&ecc_key, ecc);
        mpz_set_str (temp1, priv, 16);
        ASSERT (ecc_scalar_set (&ecc_key, temp1) != 0);
    
        mpz_clear (temp1);
        mpz_clear (temp2);
    
        gostdsa_vko (&ecc_key, &ecc_pub,
    		 ukm->length, ukm->data,
    		 out);
    
        ecc_scalar_clear (&ecc_key);
        ecc_point_clear (&ecc_pub);
    
        if (hash)
          {
    	hash->init (hash_ctx);
    	hash->update (hash_ctx, out_len, out);
    	hash->digest (hash_ctx, hash->digest_size, out);
    
    	ASSERT (hash->digest_size == res->length);
    	ASSERT (MEMEQ (res->length, out, res->data));
          }
        else
          {
    	ASSERT (out_len == res->length);
    	ASSERT (MEMEQ (res->length, out, res->data));
          }
    }
    
    void
    test_main (void)
    {
        struct streebog256_ctx ctx_256;
        struct streebog256_ctx ctx_512;
    
        /* RFC 7836, App B, provides test vectors, values there are little endian.
         *
         * However those test vectors depend on the availability of Streebog hash
         * functions, which is not available (yet). So these test vectors capture
         * the VKO value just before hash function. One can verify them by
         * calculating the Streeebog function and comparing the result with RFC
         * 7836, App B. */