forked from xieyugui/drm_flv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdes.cc
61 lines (42 loc) · 1.06 KB
/
des.cc
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
/*
* Copyright (C) GS
*/
#ifndef __DES_CC__
#define __DES_CC__
#include "des.h"
//#define ngx_memcpy(dst, src, n) (void) memcpy(dst, src, n)
static u_char des_block_size = 8;
// note: Because each block size is 8, so not less than 8 bytes
TSReturnCode
des_encrypt(const u_char *key, u_char *data, unsigned len)
{
int rc;
char pkey[8], pad, pads;
memcpy(pkey, key, 8);
des_setparity(pkey);
pad = des_block_size - len % des_block_size;
pads = pad;
while (pads) {
data[len++] = pad;
pads--;
}
rc = ecb_crypt(pkey, (char *)data, len, DES_ENCRYPT);
if (DES_FAILED(rc)) {
return TS_ERROR;
}
return TS_SUCCESS;
}
TSReturnCode
des_decrypt(const u_char *key, u_char *data, unsigned len)
{
int rc;
char pkey[8];
memcpy(pkey, key, 8);
des_setparity(pkey);
rc = ecb_crypt(pkey, (char *)data, len, DES_DECRYPT);
if (DES_FAILED(rc)) {
return TS_ERROR;
}
return TS_SUCCESS;
}
#endif /* __DES_CC__ */