diff options
author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-07-11 16:51:25 +0000 |
---|---|---|
committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-07-11 16:51:25 +0000 |
commit | ca5bb76d2b8f65aa97e50b633f828c1deb241526 (patch) | |
tree | 453a1b2de3a0dc0d0b2f7080d10d033bf8fbcdf1 /utils/zenutils/source/shared/crypt.cpp | |
parent | 141774be48940d56e3ad4dbf451d245b61d4f8b2 (diff) | |
download | rockbox-ca5bb76d2b8f65aa97e50b633f828c1deb241526.tar.gz rockbox-ca5bb76d2b8f65aa97e50b633f828c1deb241526.zip |
Delete the svn:executable property and set svn:eol-style to native for all those text files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18012 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils/source/shared/crypt.cpp')
-rw-r--r--[-rwxr-xr-x] | utils/zenutils/source/shared/crypt.cpp | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/utils/zenutils/source/shared/crypt.cpp b/utils/zenutils/source/shared/crypt.cpp index 9c2d33870c..3f15ac64f1 100755..100644 --- a/utils/zenutils/source/shared/crypt.cpp +++ b/utils/zenutils/source/shared/crypt.cpp | |||
@@ -1,91 +1,91 @@ | |||
1 | /* zenutils - Utilities for working with creative firmwares. | 1 | /* zenutils - Utilities for working with creative firmwares. |
2 | * Copyright 2007 (c) Rasmus Ry <rasmus.ry{at}gmail.com> | 2 | * Copyright 2007 (c) Rasmus Ry <rasmus.ry{at}gmail.com> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or | 6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. | 7 | * (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include "crypt.h" | 19 | #include "crypt.h" |
20 | #include <stdexcept> | 20 | #include <stdexcept> |
21 | #include <beecrypt/hmacsha1.h> | 21 | #include <beecrypt/hmacsha1.h> |
22 | #include <beecrypt/blockmode.h> | 22 | #include <beecrypt/blockmode.h> |
23 | #include <beecrypt/blowfish.h> | 23 | #include <beecrypt/blowfish.h> |
24 | 24 | ||
25 | 25 | ||
26 | bool zen::hmac_sha1_calc(const byte* key, size_t keylen, const byte* data, | 26 | bool zen::hmac_sha1_calc(const byte* key, size_t keylen, const byte* data, |
27 | size_t datalen, byte* sig, size_t* siglen) | 27 | size_t datalen, byte* sig, size_t* siglen) |
28 | { | 28 | { |
29 | hmacsha1Param param; | 29 | hmacsha1Param param; |
30 | if (hmacsha1Setup(¶m, key, keylen * 8)) | 30 | if (hmacsha1Setup(¶m, key, keylen * 8)) |
31 | return false; | 31 | return false; |
32 | if (hmacsha1Update(¶m, data, datalen)) | 32 | if (hmacsha1Update(¶m, data, datalen)) |
33 | return false; | 33 | return false; |
34 | if (hmacsha1Digest(¶m, sig)) | 34 | if (hmacsha1Digest(¶m, sig)) |
35 | return false; | 35 | return false; |
36 | return true; | 36 | return true; |
37 | } | 37 | } |
38 | 38 | ||
39 | bool zen::bf_cbc_encrypt(const byte* key, size_t keylen, byte* data, | 39 | bool zen::bf_cbc_encrypt(const byte* key, size_t keylen, byte* data, |
40 | size_t datalen, const byte* iv) | 40 | size_t datalen, const byte* iv) |
41 | { | 41 | { |
42 | if (datalen % blowfish.blocksize) | 42 | if (datalen % blowfish.blocksize) |
43 | throw std::invalid_argument( | 43 | throw std::invalid_argument( |
44 | "The length must be aligned on a 8 byte boundary."); | 44 | "The length must be aligned on a 8 byte boundary."); |
45 | 45 | ||
46 | blowfishParam param; | 46 | blowfishParam param; |
47 | if (blowfishSetup(¶m, key, keylen * 8, ENCRYPT)) | 47 | if (blowfishSetup(¶m, key, keylen * 8, ENCRYPT)) |
48 | return false; | 48 | return false; |
49 | if (blowfishSetIV(¶m, iv)) | 49 | if (blowfishSetIV(¶m, iv)) |
50 | return false; | 50 | return false; |
51 | 51 | ||
52 | byte* plain = new byte[datalen]; | 52 | byte* plain = new byte[datalen]; |
53 | memcpy(plain, data, datalen); | 53 | memcpy(plain, data, datalen); |
54 | 54 | ||
55 | unsigned int nblocks = datalen / blowfish.blocksize; | 55 | unsigned int nblocks = datalen / blowfish.blocksize; |
56 | if (blockEncryptCBC(&blowfish, ¶m, (uint32_t*)data, (uint32_t*)plain, | 56 | if (blockEncryptCBC(&blowfish, ¶m, (uint32_t*)data, (uint32_t*)plain, |
57 | nblocks)) | 57 | nblocks)) |
58 | { | 58 | { |
59 | delete [] plain; | 59 | delete [] plain; |
60 | return false; | 60 | return false; |
61 | } | 61 | } |
62 | 62 | ||
63 | return true; | 63 | return true; |
64 | } | 64 | } |
65 | 65 | ||
66 | bool zen::bf_cbc_decrypt(const byte* key, size_t keylen, byte* data, | 66 | bool zen::bf_cbc_decrypt(const byte* key, size_t keylen, byte* data, |
67 | size_t datalen, const byte* iv) | 67 | size_t datalen, const byte* iv) |
68 | { | 68 | { |
69 | if (datalen % blowfish.blocksize) | 69 | if (datalen % blowfish.blocksize) |
70 | throw std::invalid_argument( | 70 | throw std::invalid_argument( |
71 | "The length must be aligned on a 8 byte boundary."); | 71 | "The length must be aligned on a 8 byte boundary."); |
72 | 72 | ||
73 | blowfishParam param; | 73 | blowfishParam param; |
74 | if (blowfishSetup(¶m, key, keylen * 8, ENCRYPT)) | 74 | if (blowfishSetup(¶m, key, keylen * 8, ENCRYPT)) |
75 | return false; | 75 | return false; |
76 | if (blowfishSetIV(¶m, iv)) | 76 | if (blowfishSetIV(¶m, iv)) |
77 | return false; | 77 | return false; |
78 | 78 | ||
79 | byte* cipher = new byte[datalen]; | 79 | byte* cipher = new byte[datalen]; |
80 | memcpy(cipher, data, datalen); | 80 | memcpy(cipher, data, datalen); |
81 | 81 | ||
82 | unsigned int nblocks = datalen / blowfish.blocksize; | 82 | unsigned int nblocks = datalen / blowfish.blocksize; |
83 | if (blockDecryptCBC(&blowfish, ¶m, (uint32_t*)data, (uint32_t*)cipher, | 83 | if (blockDecryptCBC(&blowfish, ¶m, (uint32_t*)data, (uint32_t*)cipher, |
84 | nblocks)) | 84 | nblocks)) |
85 | { | 85 | { |
86 | delete [] cipher; | 86 | delete [] cipher; |
87 | return false; | 87 | return false; |
88 | } | 88 | } |
89 | 89 | ||
90 | return true; | 90 | return true; |
91 | } | 91 | } |