-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 (!p)
+ {
+ fprintf(stderr, "Virtual memory exhausted.\n");
+ abort();
+ }
+
+ return p;
+}
+
unsigned
decode_hex_length(const char *h)
{
uint8_t *p;
unsigned length = decode_hex_length(hex);
- p = malloc(length);
- if (!p)
- abort();
+ p = xalloc(length);
if (decode_hex(p, hex))
return p;
const uint8_t *cleartext,
const uint8_t *ciphertext)
{
- void *ctx = alloca(cipher->context_size);
- uint8_t *data = alloca(length);
+ void *ctx = xalloc(cipher->context_size);
+ uint8_t *data = xalloc(length);
cipher->set_encrypt_key(ctx, key_length, key);
cipher->encrypt(ctx, length, data, cleartext);
if (!MEMEQ(length, data, cleartext))
FAIL();
+
+ free(ctx);
+ free(data);
}
void
const uint8_t *ciphertext,
const uint8_t *iiv)
{
- void *ctx = alloca(cipher->context_size);
- uint8_t *data = alloca(length);
- uint8_t *iv = alloca(cipher->block_size);
+ void *ctx = xalloc(cipher->context_size);
+ uint8_t *data = xalloc(length);
+ uint8_t *iv = xalloc(cipher->block_size);
cipher->set_encrypt_key(ctx, key_length, key);
memcpy(iv, iiv, cipher->block_size);
if (!MEMEQ(length, data, cleartext))
FAIL();
+
+ free(ctx);
+ free(data);
+ free(iv);
}
void
{
unsigned block;
- void *ctx = alloca(cipher->context_size);
- uint8_t *data = alloca(length + 1);
+ void *ctx = xalloc(cipher->context_size);
+ uint8_t *data = xalloc(length + 1);
for (block = 1; block <= length; block++)
{
if (!MEMEQ(length, data, cleartext))
FAIL();
+
+ free(ctx);
+ free(data);
}
void
const uint8_t *data,
const uint8_t *digest)
{
- void *ctx = alloca(hash->context_size);
- uint8_t *buffer = alloca(hash->digest_size);
+ void *ctx = xalloc(hash->context_size);
+ uint8_t *buffer = xalloc(hash->digest_size);
hash->init(ctx);
hash->update(ctx, length, data);
if (buffer[hash->digest_size - 1])
FAIL();
+
+ free(ctx);
+ free(buffer);
}
void
const uint8_t *ascii)
{
unsigned ascii_length = strlen(ascii);
- uint8_t *buffer = alloca(1 + ascii_length);
- uint8_t *check = alloca(1 + armor->decode_length(ascii_length));
- void *encode = alloca(armor->encode_context_size);
- void *decode = alloca(armor->decode_context_size);
+ uint8_t *buffer = xalloc(1 + ascii_length);
+ uint8_t *check = xalloc(1 + armor->decode_length(ascii_length));
+ void *encode = xalloc(armor->encode_context_size);
+ void *decode = xalloc(armor->decode_context_size);
unsigned done;
ASSERT(ascii_length
if (0x55 != check[data_length])
FAIL();
+
+ free(buffer);
+ free(check);
+ free(encode);
+ free(decode);
}
#if HAVE_LIBGMP