Download | Plain Text | No Line Numbers


  1. #ifdef NDEBUG
  2. # undef NDEBUG
  3. #endif
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include "hexdump.h"
  10. #include "cipher.h"
  11.  
  12. #define BLOCKSIZE 8192
  13.  
  14. int main()
  15. {
  16. /* allocate buffer for decrypted stuff */
  17. char *out = malloc(BLOCKSIZE);
  18. memset(out, 0, BLOCKSIZE);
  19.  
  20. /* cipher */
  21. ctx_t *cipher = malloc(sizeof(ctx_t));
  22. memset(cipher, 0, sizeof(ctx_t));
  23. int ret = CipherInit(cipher);
  24. printf("CipherInit()=%d\n", ret);
  25.  
  26. /* set pointer to output buffer */
  27. cipher->out = out;
  28. printf("cipher:\n");
  29. hex_dump(cipher, sizeof(ctx_t));
  30.  
  31. /* some sanity checks */
  32. assert(cipher->out == out);
  33. assert(cipher->ret == 0);
  34. assert(cipher->off1 == 0);
  35. assert(cipher->off2 == 0);
  36. assert(cipher->prepend_hashkey == 1);
  37.  
  38. /* allocate input buffer */
  39. char *in = malloc(BLOCKSIZE);
  40. memset(in, 0, BLOCKSIZE);
  41. uint32_t in_len = 0;
  42.  
  43. /* copy test data
  44.   * encrypted data for:
  45.   * #73'cgy5l%~cn*=tjb[go),:{(@yx
  46.   * print $Confixx::Filter::VERSION,"\n";
  47.   */
  48. unsigned char test[] = {
  49. 0xd8, 0xb0, 0x73, 0x62, 0xc2, 0xf8, 0x17, 0x92, 0x8c, 0x68, 0x5f,
  50. 0xf5, 0x8e, 0x25, 0x66, 0x37, 0x43, 0x34, 0x92, 0xfa, 0x94, 0xc5, 0x26,
  51. 0xb4, 0x1c, 0x16, 0xa8, 0x2c, 0x1c, 0x8e, 0xa3, 0x37, 0x42, 0xf6, 0xb2,
  52. 0x62, 0x90, 0xd3, 0x99, 0xa7, 0x9d, 0x80, 0x16, 0x7f, 0x2d, 0x1c, 0xf7,
  53. 0x9d, 0xf0, 0xee, 0xbc, 0xaa, 0xa0, 0x66, 0xc3, 0xb1, 0xdc, 0x7a, 0xda,
  54. 0xda, 0xbc, 0x95, 0x4c, 0x88, 0xe6, 0x6f, 0x4d
  55. };
  56. in_len = sizeof(test);
  57. memcpy(in, test, in_len);
  58.  
  59. printf("\ninput: len=%u\n", in_len);
  60.  
  61. uint32_t out_len = CipherUpdate(cipher, in, in_len);
  62. printf("CipherUpdate()=%u\n", out_len);
  63. printf("cipher:\n");
  64. hex_dump(cipher, sizeof(ctx_t));
  65.  
  66. /* some afterwards sanit checks */
  67. assert(cipher->out == out);
  68. assert(cipher->ret == out_len);
  69. assert(cipher->off1 == out_len - 1);
  70. assert(cipher->prepend_hashkey == 0);
  71.  
  72. printf("\noutput:\n");
  73. printf("%s", out);
  74.  
  75. free(cipher);
  76. free(in);
  77. free(out);
  78.  
  79. return 0;
  80. }
  81.