Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • wip/dueno/ml-dsa2
  • wip/pacbti2
  • wip/dueno/pacbti
  • wip/dueno/deterministic-ecdsa
  • wip/dueno/kyber2
  • wip/dueno/shake-streaming-update
  • wip/dueno/shake-streaming
  • master-updates
  • release-3.7-fixes
  • fix-chacha-counter
  • arm64
  • delete-1-way-neon
  • fat-build-by-default
  • ppc-chacha-4core
  • delete-internal-name-mangling
  • ppc-gcm
  • ppc-chacha-2core
  • refactor-ecc-mod
  • ppc-chacha-core
  • nettle_3.7.2_release_20210321
  • nettle_3.7.1_release_20210217
  • nettle_3.7_release_20210104
  • nettle_3.7rc1
  • nettle_3.6_release_20200429
  • nettle_3.6rc3
  • nettle_3.6rc2
  • nettle_3.6rc1
  • 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
40 results

camellia-test.c

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();