-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.c
99 lines (88 loc) · 2.13 KB
/
demo.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* aesdemo.c
*
* Demonstration of AES cryptoalgorithm
*
* @author [email protected]
* @version 2.0
*
* For Putty AES NI project
* http://putty-aes-ni.googlecode.com/
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "intf.h"
#define BUF_LEN (1 << 28)
#ifdef _HW_AES
#define MODE 1
#else
#define MODE 0
#endif
void cipher(unsigned char* block)
{
struct ssh_cipher *handle = create_handle(32, MODE, "imtheoperatorwithmypocketcalcula", "initializationve");
#ifdef DECODE
decrypt(handle, block, BUF_LEN);
#else
encrypt(handle, block, BUF_LEN);
#endif
free_handle(handle);
}
int ciphCopy(char* src, char* dst)
{
int result = 0;
FILE* f_dst;
FILE* f_src;
unsigned char* buf;
/* Source file processing */
f_src = fopen(src, "rb");
if (f_src == NULL)
{
fprintf(stderr, "Failed to open '%s'\n", src);
return 1;
}
/* Destination file processing */
f_dst = fopen(dst, "wb");
if (f_dst == NULL)
{
fprintf(stderr, "Failed to create '%s'\n", dst);
fclose(f_src);
return 1;
}
buf = (unsigned char*)calloc(BUF_LEN, sizeof(unsigned char)); /* Read buffer */
while (result = fread(buf, sizeof(unsigned char), BUF_LEN, f_src), result > 0)
{
if (result == -1)
{
fprintf(stderr, "Failed to read from '%s'\n", src);
fclose(f_src);
fclose(f_dst);
return 1;
}
cipher(buf);
result = fwrite(buf, sizeof(unsigned char), result, f_dst);
fflush(f_dst);
if (result == -1)
{
fprintf(stderr,"Failed to write to '%s'\n", dst);
fclose(f_src);
fclose(f_dst);
return 1;
}
}
free(buf);
fclose(f_src);
fclose(f_dst);
return 0;
}
int main(int argc, char** argv)
{
if (argc != 3)
{
fprintf(stderr,
"Syntax error! First parameter is source file, second is dest file\n");
return 1;
}
return ciphCopy(argv[1], argv[2]);
}