Download | Plain Text | Line Numbers


#ifdef NDEBUG
# undef NDEBUG
#endif
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "hexdump.h"
#include "cipher.h"
 
#define BLOCKSIZE 8192
 
int main()
{
  /* allocate buffer for decrypted stuff */
  char *out = malloc(BLOCKSIZE);
  memset(out, 0, BLOCKSIZE);
 
  /* cipher */
  ctx_t *cipher = malloc(sizeof(ctx_t));
  memset(cipher, 0, sizeof(ctx_t));
  int ret = CipherInit(cipher);
  printf("CipherInit()=%d\n", ret);
 
  /* set pointer to output buffer */
  cipher->out = out;
  printf("cipher:\n");
  hex_dump(cipher, sizeof(ctx_t));
 
  /* some sanity checks */
  assert(cipher->out  == out);
  assert(cipher->ret  == 0);
  assert(cipher->off1 == 0);
  assert(cipher->off2 == 0);
  assert(cipher->prepend_hashkey == 1);
 
  /* allocate input buffer */
  char *in = malloc(BLOCKSIZE);
  memset(in, 0, BLOCKSIZE);
  uint32_t in_len = 0;
 
  /* copy test data
   * encrypted data for:
   * #73'cgy5l%~cn*=tjb[go),:{(@yx
   * print $Confixx::Filter::VERSION,"\n";
   */
  unsigned char test[] = {
    0xd8, 0xb0, 0x73, 0x62, 0xc2, 0xf8, 0x17, 0x92, 0x8c, 0x68, 0x5f,
    0xf5, 0x8e, 0x25, 0x66, 0x37, 0x43, 0x34, 0x92, 0xfa, 0x94, 0xc5, 0x26,
    0xb4, 0x1c, 0x16, 0xa8, 0x2c, 0x1c, 0x8e, 0xa3, 0x37, 0x42, 0xf6, 0xb2,
    0x62, 0x90, 0xd3, 0x99, 0xa7, 0x9d, 0x80, 0x16, 0x7f, 0x2d, 0x1c, 0xf7,
    0x9d, 0xf0, 0xee, 0xbc, 0xaa, 0xa0, 0x66, 0xc3, 0xb1, 0xdc, 0x7a, 0xda,
    0xda, 0xbc, 0x95, 0x4c, 0x88, 0xe6, 0x6f, 0x4d
  };
  in_len = sizeof(test);
  memcpy(in, test, in_len);
 
  printf("\ninput: len=%u\n", in_len);
 
  uint32_t out_len = CipherUpdate(cipher, in, in_len);
  printf("CipherUpdate()=%u\n", out_len);
  printf("cipher:\n");
  hex_dump(cipher, sizeof(ctx_t));
 
  /* some afterwards sanit checks */
  assert(cipher->out  == out);
  assert(cipher->ret  == out_len);
  assert(cipher->off1 == out_len - 1);
  assert(cipher->prepend_hashkey == 0);
 
  printf("\noutput:\n");
  printf("%s", out);
 
  free(cipher);
  free(in);
  free(out);
 
  return 0;
}