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

_Image_PSD.pmod

Blame
  • testutils.c 22.35 KiB
    /* testutils.c */
    
    #include "testutils.h"
    
    #include "cbc.h"
    #include "ctr.h"
    #include "knuth-lfib.h"
    
    #include <ctype.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    /* -1 means invalid */
    static const signed char hex_digits[0x100] =
      {
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
        -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
      };
    
    void *
    xalloc(size_t size)
    {
      void *p = malloc(size);
      if (size && !p)
        {
          fprintf(stderr, "Virtual memory exhausted.\n");
          abort();
        }
    
      return p;
    }
    
    unsigned
    decode_hex_length(const char *h)
    {
      const unsigned char *hex = (const unsigned char *) h;
      unsigned count;
      unsigned i;
      
      for (count = i = 0; hex[i]; i++)
        {
          if (isspace(hex[i]))
    	continue;
          if (hex_digits[hex[i]] < 0)
    	abort();
          count++;
        }
    
      if (count % 2)
        abort();
      return count / 2;  
    }
    
    int
    decode_hex(uint8_t *dst, const char *h)