Skip to content
Snippets Groups Projects
Select Git revision
  • 0c029ca03bd9f5853e727e7ed335a1b4ea37b487
  • master default
  • wip-add-ed25519
  • disable-sha1
  • lsh-2.0.4
  • experimental-20050201
  • lsh-1.4.2
  • lsh-1.2
  • lsh_2.1_release_20130626
  • converted-master-branch-to-git
  • nettle_2.4_release_20110903
  • nettle_2.3_release_20110902
  • nettle_2.2_release_20110711
  • nettle_2.1_release_20100725
  • camellia_32bit_20100720
  • nettle_2.0_release_20090608
  • converted-lsh-2.0.4-branch-to-git
  • lsh_2.0.4_release_20070905
  • lsh_2.9_exp_release_20070404
  • nettle_1.15_release_20061128
  • after_experimental_merge_20060516
  • branch_before_experimental_merge_20060516
  • converted-experimental-branch-to-git
  • head_before_experimental_merge_20060516
  • lsh_2.0.3_release_20060509
  • lsh_2.0.2_release_20060127
  • nettle_1.14_release_20051205
  • nettle_1.13_release_20051006
28 results

base16-encode.c

Blame
  • aesdata.c 5.79 KiB
    #if HAVE_CONFIG_H
    # include "config.h"
    #endif
    
    #include <assert.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    #include "nettle-types.h"
    
    #if 1
    # define BYTE_FORMAT "0x%02x"
    # define BYTE_COLUMNS 8
    #else
    # define BYTE_FORMAT "%3d"
    # define BYTE_COLUMNS 0x10
    #endif
    
    #define WORD_FORMAT "0x%08x"
    #define WORD_COLUMNS 4
    
    uint8_t sbox[0x100];
    uint8_t isbox[0x100];
    
    uint8_t gf2_log[0x100];
    uint8_t gf2_exp[0x100];
    
    uint32_t dtable[4][0x100];
    uint32_t itable[4][0x100];
    
    static unsigned
    xtime(unsigned x)
    {
      assert (x < 0x100);
    
      x <<= 1;
      if (x & 0x100)
        x ^= 0x11b;
    
      assert (x < 0x100);
    
      return x;
    }
    
    /* Computes the exponentiatiom and logarithm tables for GF_2, to the
     * base x+1 (0x03). The unit element is 1 (0x01).*/
    static void
    compute_log(void)
    {
      unsigned i = 0;
      unsigned x = 1;
    
      memset(gf2_log, 0, 0x100);
      
      for (i = 0; i < 0x100; i++, x = x ^ xtime(x))
        {
          gf2_exp[i] = x;
          gf2_log[x] = i;
        }
      /* Invalid. */
      gf2_log[0] = 0;
      /* The loop above sets gf2_log[1] = 0xff, which is correct,
       * but gf2_log[1] = 0 is nicer. */
      gf2_log[1] = 0;
    }
    
    static unsigned
    mult(unsigned a, unsigned b)
    {