File: test_main.c

package info (click to toggle)
openswan 1%3A2.4.6%2Bdfsg.2-1.1%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 25,000 kB
  • ctags: 16,877
  • sloc: ansic: 121,112; sh: 19,782; xml: 9,699; asm: 4,422; perl: 4,087; makefile: 3,367; tcl: 713; exp: 657; yacc: 396; pascal: 328; lex: 289; sed: 265; awk: 124; lisp: 3
file content (34 lines) | stat: -rw-r--r-- 943 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <string.h>
#include "twofish_cbc.h"
#define BLOCK_SIZE	16
#define KEY_SIZE 	128	/* bits */
#define KEY 		"1234567890123456"
#define STR 		"hola guaso como estaisss ... 012"
#define STRSZ		(sizeof(STR)-1)

#define BLKLEN 		BLOCK_SIZE
#define CONTEXT_T  	twofish_context
static int pretty_print(const unsigned char *buf, int count) {
	int i=0;
	for (;i<count;i++) printf ("%02hhx ", buf[i]);
	putchar('\n');
	return i;
}
//#define SIZE STRSZ/2
#define SIZE STRSZ
int main() {
	int ret;
	char buf0[SIZE+1], buf1[SIZE+1];
	char IV[BLOCK_SIZE];
	CONTEXT_T ac;	
	twofish_set_key(&ac, (void *)KEY, KEY_SIZE);
	memset(buf0, 0, sizeof (buf0));
	memset(buf1, 0, sizeof (buf1));
	twofish_cbc_encrypt(&ac, STR, buf0, SIZE, IV, 1);
	pretty_print(buf0, SIZE);
	printf("size=%d ret=%d\n%s\n", SIZE, ret, buf0);
	ret=twofish_cbc_encrypt(&ac, buf0, buf1, SIZE, IV, 0);
	printf("size=%d ret=%d\n%s\n", SIZE, ret, buf1);
	return 0;
}