Skip to content
Snippets Groups Projects
Select Git revision
  • 974514e16189c01aad598e875171d6794474eb0f
  • master default
  • wip-slh-dsa-sha2-128s
  • master-updates
  • release-3.10-fixes
  • getopt-prototype
  • fix-bcrypt-warning
  • refactor-hmac
  • wip-use-alignas
  • trim-sha3-context
  • fix-gitlab-ci
  • check-fat-emulate
  • delete-digest_func-size
  • slh-dsa-shake-128f-nettle
  • slh-dsa-shake-128s-nettle
  • slh-dsa-shake-128s
  • delete-openpgp
  • ppc64-sha512
  • delete-md5-compat
  • cleanup-hmac-tests
  • ppc64-sha256
  • nettle_3.10.2_release_20250626
  • nettle_3.10.1_release_20241230
  • nettle_3.10_release_20240616
  • nettle_3.10rc2
  • nettle_3.10rc1
  • nettle_3.9.1_release_20230601
  • nettle_3.9_release_20230514
  • nettle_3.8.1_release_20220727
  • nettle_3.8_release_20220602
  • nettle_3.7.3_release_20210606
  • 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
41 results

testutils.c

Blame
  • testutils.c 36.34 KiB
    /* testutils.c */
    
    #include "testutils.h"
    
    #include "base16.h"
    #include "cbc.h"
    #include "ctr.h"
    #include "knuth-lfib.h"
    #include "macros.h"
    #include "nettle-internal.h"
    
    #include <assert.h>
    #include <ctype.h>
    
    void
    die(const char *format, ...)
    {
      va_list args;
      va_start(args, format);
      vfprintf(stderr, format, args);
      va_end(args);
    
      abort ();
    }
    
    void *
    xalloc(size_t size)
    {
      void *p = malloc(size);
      if (size && !p)
        {
          fprintf(stderr, "Virtual memory exhausted.\n");
          abort();
        }
    
      return p;
    }
    
    static struct tstring *tstring_first = NULL;
    
    struct tstring *
    tstring_alloc (size_t length)
    {
      struct tstring *s = xalloc(sizeof(struct tstring) + length);
      s->length = length;
      s->next = tstring_first;
      /* NUL-terminate, for convenience. */
      s->data[length] = '\0';
      tstring_first = s;
      return s;
    }
    
    void
    tstring_clear(void)
    {
      while (tstring_first)
        {
          struct tstring *s = tstring_first;
          tstring_first = s->next;
          free(s);
        }
    }
    
    struct tstring *
    tstring_data(size_t length, const char *data)
    {
      struct tstring *s = tstring_alloc (length);
      memcpy (s->data, data, length);
      return s;
    }