Fri, 28 Feb 2014 20:56:22 +0100
Merge release-2.x.y
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
1 | /* $Id$ */ |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
2 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
3 | /* |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
4 | * (C) Copyright 2007 Wojtek Kaniewski <wojtekka@irc.pl> |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
5 | * |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
6 | * Public domain SHA-1 implementation by Steve Reid <steve@edmweb.com> |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
7 | * |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
9 | * it under the terms of the GNU Lesser General Public License Version |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
10 | * 2.1 as published by the Free Software Foundation. |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
11 | * |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
12 | * This program is distributed in the hope that it will be useful, |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
15 | * GNU Lesser General Public License for more details. |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
16 | * |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
17 | * You should have received a copy of the GNU Lesser General Public |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
18 | * License along with this program; if not, write to the Free Software |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
20 | * USA. |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
21 | */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
22 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
23 | /** |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
24 | * \file sha1.c |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
25 | * |
|
31826
0f6ab56fbf9d
Update libgadu to 0.11.0 plus local changes; thanks to Tomasz Wasilczyk.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
26 | * \brief Funkcje wyznaczania skrótu SHA1 |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
27 | */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
28 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
29 | #include <errno.h> |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
30 | #include <string.h> |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
31 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
32 | #include "libgadu.h" |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
33 | #include "internal.h" |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
34 | #include "fileio.h" |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
35 | #include "config.h" |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
36 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
37 | /** \cond ignore */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
38 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
39 | #ifdef GG_CONFIG_HAVE_OPENSSL |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
40 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
41 | #include <openssl/sha.h> |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
42 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
43 | #elif defined(GG_CONFIG_HAVE_GNUTLS) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
44 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
45 | #include <gnutls/gnutls.h> |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
46 | #include <gnutls/crypto.h> |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
47 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
48 | #define SHA_CTX gnutls_hash_hd_t |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
49 | #define SHA1_Init(ctx) (gnutls_hash_init((ctx), GNUTLS_DIG_SHA1) == 0 ? 1 : 0) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
50 | #define SHA1_Update(ctx, ptr, len) (gnutls_hash(*(ctx), (ptr), (len)) == 0 ? 1 : 0) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
51 | #define SHA1_Final(digest, ctx) (gnutls_hash_deinit(*(ctx), (digest)), 1) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
52 | |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
53 | #else |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
54 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
55 | /* |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
56 | SHA-1 in C |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
57 | By Steve Reid <steve@edmweb.com> |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
58 | 100% Public Domain |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
59 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
60 | Modified by Wojtek Kaniewski <wojtekka@toxygen.net> for compatibility |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
61 | with libgadu and OpenSSL API. |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
62 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
63 | Test Vectors (from FIPS PUB 180-1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
64 | "abc" |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
65 | A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
66 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
67 | 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
68 | A million repetitions of "a" |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
69 | 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
70 | */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
71 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
72 | /* #define LITTLE_ENDIAN * This should be #define'd if true. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
73 | /* #define SHA1HANDSOFF * Copies data before messing with it. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
74 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
75 | typedef struct { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
76 | uint32_t state[5]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
77 | uint32_t count[2]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
78 | unsigned char buffer[64]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
79 | } SHA_CTX; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
80 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
81 | static void SHA1_Transform(uint32_t state[5], const unsigned char buffer[64]); |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
82 | static int SHA1_Init(SHA_CTX* context); |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
83 | static int SHA1_Update(SHA_CTX* context, const unsigned char* data, unsigned int len); |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
84 | static int SHA1_Final(unsigned char digest[20], SHA_CTX* context); |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
85 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
86 | #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
87 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
88 | /* blk0() and blk() perform the initial expand. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
89 | /* I got the idea of expanding during the round function from SSLeay */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
90 | #ifndef GG_CONFIG_BIGENDIAN |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
91 | #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
92 | |(rol(block->l[i],8)&0x00FF00FF)) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
93 | #else |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
94 | #define blk0(i) block->l[i] |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
95 | #endif |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
96 | #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
97 | ^block->l[(i+2)&15]^block->l[i&15],1)) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
98 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
99 | /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
100 | #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
101 | #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
102 | #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
103 | #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
104 | #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
105 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
106 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
107 | /* Hash a single 512-bit block. This is the core of the algorithm. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
108 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
109 | static void SHA1_Transform(uint32_t state[5], const unsigned char buffer[64]) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
110 | { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
111 | uint32_t a, b, c, d, e; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
112 | typedef union { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
113 | unsigned char c[64]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
114 | uint32_t l[16]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
115 | } CHAR64LONG16; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
116 | CHAR64LONG16* block; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
117 | static unsigned char workspace[64]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
118 | block = (CHAR64LONG16*)workspace; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
119 | memcpy(block, buffer, 64); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
120 | /* Copy context->state[] to working vars */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
121 | a = state[0]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
122 | b = state[1]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
123 | c = state[2]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
124 | d = state[3]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
125 | e = state[4]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
126 | /* 4 rounds of 20 operations each. Loop unrolled. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
127 | R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
128 | R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
129 | R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
130 | R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
131 | R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
132 | R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
133 | R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
134 | R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
135 | R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
136 | R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
137 | R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
138 | R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
139 | R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
140 | R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
141 | R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
142 | R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
143 | R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
144 | R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
145 | R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
146 | R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
147 | /* Add the working vars back into context.state[] */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
148 | state[0] += a; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
149 | state[1] += b; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
150 | state[2] += c; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
151 | state[3] += d; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
152 | state[4] += e; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
153 | /* Wipe variables */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
154 | a = b = c = d = e = 0; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
155 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
156 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
157 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
158 | /* SHA1_Init - Initialize new context */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
159 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
160 | static int SHA1_Init(SHA_CTX* context) |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
161 | { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
162 | /* SHA1 initialization constants */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
163 | context->state[0] = 0x67452301; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
164 | context->state[1] = 0xEFCDAB89; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
165 | context->state[2] = 0x98BADCFE; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
166 | context->state[3] = 0x10325476; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
167 | context->state[4] = 0xC3D2E1F0; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
168 | context->count[0] = context->count[1] = 0; |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
169 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
170 | return 1; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
171 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
172 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
173 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
174 | /* Run your data through this. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
175 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
176 | static int SHA1_Update(SHA_CTX* context, const unsigned char* data, unsigned int len) |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
177 | { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
178 | unsigned int i, j; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
179 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
180 | j = (context->count[0] >> 3) & 63; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
181 | if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
182 | context->count[1] += (len >> 29); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
183 | if ((j + len) > 63) { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
184 | memcpy(&context->buffer[j], data, (i = 64-j)); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
185 | SHA1_Transform(context->state, context->buffer); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
186 | for ( ; i + 63 < len; i += 64) { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
187 | SHA1_Transform(context->state, &data[i]); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
188 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
189 | j = 0; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
190 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
191 | else i = 0; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
192 | memcpy(&context->buffer[j], &data[i], len - i); |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
193 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
194 | return 1; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
195 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
196 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
197 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
198 | /* Add padding and return the message digest. */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
199 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
200 | static int SHA1_Final(unsigned char digest[20], SHA_CTX* context) |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
201 | { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
202 | uint32_t i, j; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
203 | unsigned char finalcount[8]; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
204 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
205 | for (i = 0; i < 8; i++) { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
206 | finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
207 | >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
208 | } |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
209 | SHA1_Update(context, (const unsigned char *)"\200", 1); |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
210 | while ((context->count[0] & 504) != 448) { |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
211 | SHA1_Update(context, (const unsigned char *)"\0", 1); |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
212 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
213 | SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
214 | for (i = 0; i < 20; i++) { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
215 | digest[i] = (unsigned char) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
216 | ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
217 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
218 | /* Wipe variables */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
219 | i = j = 0; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
220 | memset(context->buffer, 0, 64); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
221 | memset(context->state, 0, 20); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
222 | memset(context->count, 0, 8); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
223 | memset(&finalcount, 0, 8); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
224 | #ifdef SHA1HANDSOFF /* make SHA1_Transform overwrite it's own static vars */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
225 | SHA1_Transform(context->state, context->buffer); |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
226 | #endif |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
227 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
228 | return 1; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
229 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
230 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
231 | #endif /* GG_CONFIG_HAVE_OPENSSL */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
232 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
233 | /** \endcond */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
234 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
235 | /** \cond internal */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
236 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
237 | /** |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
238 | * \internal Liczy skrót SHA1 z ziarna i hasła. |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
239 | * |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
240 | * \param password Hasło |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
241 | * \param seed Ziarno |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
242 | * \param result Bufor na wynik funkcji skrótu (20 bajtów) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
243 | * |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
244 | * \return 0 lub -1 |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
245 | */ |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
246 | int gg_login_hash_sha1_2(const char *password, uint32_t seed, uint8_t *result) |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
247 | { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
248 | SHA_CTX ctx; |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
249 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
250 | if (!SHA1_Init(&ctx)) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
251 | return -1; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
252 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
253 | if (!SHA1_Update(&ctx, (const unsigned char*) password, strlen(password))) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
254 | goto fail; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
255 | |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
256 | seed = gg_fix32(seed); |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
257 | if (!SHA1_Update(&ctx, (uint8_t*) &seed, 4)) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
258 | goto fail; |
|
31826
0f6ab56fbf9d
Update libgadu to 0.11.0 plus local changes; thanks to Tomasz Wasilczyk.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
259 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
260 | if (!SHA1_Final(result, &ctx)) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
261 | return -1; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
262 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
263 | return 0; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
264 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
265 | fail: |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
266 | /* Zwolnij zasoby. Tylko GnuTLS przyjęłoby NULL zamiast result, więc przekaż result. */ |
|
35557
e83a87761544
Gadu-Gadu: update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
267 | (void)SHA1_Final(result, &ctx); |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
268 | return -1; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
269 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
270 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
271 | /** |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
272 | * \internal Liczy skrót SHA1 z fragmentu pliku. |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
273 | * |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
274 | * \param fd Deskryptor pliku |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
275 | * \param ctx Kontekst SHA-1 |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
276 | * \param pos Położenie fragmentu pliku |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
277 | * \param len Długość fragmentu pliku |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
278 | * |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
279 | * \return 0 lub -1 |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
280 | */ |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
281 | static int gg_file_hash_sha1_part(int fd, SHA_CTX *ctx, off_t pos, size_t len) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
282 | { |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
283 | unsigned char buf[4096]; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
284 | size_t chunk_len; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
285 | int res = 0; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
286 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
287 | while (len > 0) { |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
288 | if (lseek(fd, pos, SEEK_SET) == (off_t) -1) { |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
289 | res = -1; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
290 | break; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
291 | } |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
292 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
293 | chunk_len = len; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
294 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
295 | if (chunk_len > sizeof(buf)) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
296 | chunk_len = sizeof(buf); |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
297 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
298 | res = read(fd, buf, chunk_len); |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
299 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
300 | if (res == -1 && errno != EINTR) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
301 | break; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
302 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
303 | if (res != -1) { |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
304 | if (!SHA1_Update(ctx, buf, res)) { |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
305 | res = -1; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
306 | break; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
307 | } |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
308 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
309 | pos += res; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
310 | len -= res; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
311 | } |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
312 | } |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
313 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
314 | return res; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
315 | } |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
316 | |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
317 | /** |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
318 | * \internal Liczy skrót SHA1 z pliku. |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
319 | * |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
320 | * Dla plików poniżej 10MB liczony jest skrót z całego pliku, dla plików |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
321 | * powyżej 10MB liczy się 9 jednomegabajtowych fragmentów. |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
322 | * |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
323 | * \param fd Deskryptor pliku |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
324 | * \param result Bufor na wynik funkcji skrótu (20 bajtów) |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
325 | * |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
326 | * \return 0 lub -1 |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
327 | */ |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
328 | int gg_file_hash_sha1(int fd, uint8_t *result) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
329 | { |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
330 | SHA_CTX ctx; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
331 | off_t pos, len; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
332 | int res; |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
333 | const size_t part_len = 1048576; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
334 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
335 | if ((pos = lseek(fd, 0, SEEK_CUR)) == (off_t) -1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
336 | return -1; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
337 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
338 | if ((len = lseek(fd, 0, SEEK_END)) == (off_t) -1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
339 | return -1; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
340 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
341 | if (lseek(fd, 0, SEEK_SET) == (off_t) -1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
342 | return -1; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
343 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
344 | if (!SHA1_Init(&ctx)) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
345 | return -1; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
346 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
347 | if (len <= (off_t)part_len * 10) { |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
348 | res = gg_file_hash_sha1_part(fd, &ctx, 0, len); |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
349 | } else { |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
350 | unsigned int i; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
351 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
352 | for (i = 0; i < 9; i++) { |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
353 | off_t part_pos = (len - part_len) / 9 * i; |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
354 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
355 | res = gg_file_hash_sha1_part(fd, &ctx, part_pos, part_len); |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
356 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
357 | if (res == -1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
358 | break; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
359 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
360 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
361 | |
|
35617
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
362 | if (!SHA1_Final(result, &ctx)) |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
363 | return -1; |
|
c9069e0e3c36
Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31826
diff
changeset
|
364 | |
|
29751
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
365 | if (res == -1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
366 | return -1; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
367 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
368 | if (lseek(fd, pos, SEEK_SET) == (off_t) -1) |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
369 | return -1; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
370 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
371 | return 0; |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
372 | } |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
373 | |
|
438f88ecc11e
Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
374 | /** \endcond */ |