Skip to content
Snippets Groups Projects
Select Git revision
  • 5b67753541e77676685af9c3aa9624fb24ed2b25
  • master default protected
  • streebog
  • gost28147
  • master-updates
  • ed448
  • shake256
  • curve448
  • ecc-sqrt
  • gosthash94cp
  • cmac64
  • block16-refactor
  • siv-mode
  • cmac-layout
  • delete-des-compat
  • delete-rsa_blind
  • aes-struct-layout
  • release-3.4-fixes
  • struct-layout
  • attribute-deprecated
  • rename-data-symbols
  • nettle_3.5.1_release_20190627
  • nettle_3.5_release_20190626
  • nettle_3.5rc1
  • nettle_3.4.1_release_20181204
  • nettle_3.4.1rc1
  • nettle_3.4_release_20171119
  • nettle_3.4rc2
  • nettle_3.4rc1
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
41 results

testutils.h

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    camellia-test.c 3.39 KiB
    #include "testutils.h"
    #include "camellia.h"
    
    static void
    test_invert(const struct tstring *key,
    	    const struct tstring *cleartext,
    	    const struct tstring *ciphertext)
    {
      uint8_t *data;
      size_t length;
    
      ASSERT (cleartext->length == ciphertext->length);
      length = cleartext->length;
    
      data = xalloc(length);
    
      if (key->length == 16)
        {
          struct camellia128_ctx encrypt;
          struct camellia128_ctx decrypt;
    
          camellia128_set_encrypt_key (&encrypt, key->data);
          camellia128_crypt (&encrypt, length, data, cleartext->data);
      
          if (!MEMEQ(length, data, ciphertext->data))
    	{
    	fail_encrypt:
    	  tstring_print_hex(cleartext);
    	  fprintf(stderr, "\nOutput: ");
    	  print_hex(length, data);
    	  fprintf(stderr, "\nExpected:");
    	  tstring_print_hex(ciphertext);
    	  fprintf(stderr, "\n");
    	  FAIL();
    	}
    
          camellia128_invert_key (&decrypt, &encrypt);
          camellia128_crypt (&decrypt, length, data, data);
        }
      else
        {
          struct camellia256_ctx encrypt;
          struct camellia256_ctx decrypt;
    
          if (key->length == 24)
    	camellia192_set_encrypt_key (&encrypt, key->data);
          else if (key->length == 32)
    	camellia256_set_encrypt_key (&encrypt, key->data);
          else
    	abort ();
    
          camellia256_crypt (&encrypt, length, data, cleartext->data);
      
          if (!MEMEQ(length, data, ciphertext->data))
    	goto fail_encrypt;
    
          camellia256_invert_key (&decrypt, &encrypt);
          camellia256_crypt (&decrypt, length, data, data);
        }
    
      if (!MEMEQ(length, data, cleartext->data))
        {
          fprintf(stderr, "test_invert: Decrypt failed:\nInput:");
          tstring_print_hex(ciphertext);
          fprintf(stderr, "\nOutput: ");
          print_hex(length, data);
          fprintf(stderr, "\nExpected:");
          tstring_print_hex(cleartext);
          fprintf(stderr, "\n");
          FAIL();