annotate src/xs_support.c @ 771:469b341734b2

Move MD5 implementation into xs_support, and some related Audacious ifdeffery too.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Nov 2012 11:23:58 +0200
parents 61a527ac3baa
children 91a36a4b79c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 Miscellaneous support functions
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
324
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
723
9321ffa2ea7e Update copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 714
diff changeset
7 (C) Copyright 1999-2009 Tecnic Software productions (TNSP)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 (at your option) any later version.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 GNU General Public License for more details.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
412
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
19 You should have received a copy of the GNU General Public License along
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
20 with this program; if not, write to the Free Software Foundation, Inc.,
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
49
3518ca5c8b0f Support for compile-time big/little-endian optimizations in audio output
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
23 #include "xs_support.h"
224
df4cb5115322 Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
24 #include <ctype.h>
771
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
25 #include <glib.h>
202
fe684a2ccdc7 Reworking code.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
26
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
27
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 748
diff changeset
28 guint16 xs_fread_be16(XSFile *f)
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
29 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
30 return (((guint16) xs_fgetc(f)) << 8) | ((guint16) xs_fgetc(f));
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
31 }
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
32
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
33
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 748
diff changeset
34 guint32 xs_fread_be32(XSFile *f)
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
35 {
763
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
36 return
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
37 (((guint32) xs_fgetc(f)) << 24) |
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
38 (((guint32) xs_fgetc(f)) << 16) |
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
39 (((guint32) xs_fgetc(f)) << 8) |
763
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
40 ((guint32) xs_fgetc(f));
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
41 }
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
42
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
43
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
44 /* Load a file to a buffer, return 0 on success, negative value on error
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
45 */
657
acaba070cf49 Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents: 634
diff changeset
46 gint xs_fload_buffer(const gchar *filename, guint8 **buf, size_t *bufSize)
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
47 {
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 748
diff changeset
48 XSFile *f;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
49 glong seekPos;
763
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
50
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
51 if (filename == NULL)
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
52 return -15;
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
53
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
54 if ((f = xs_fopen(filename, "rb")) == NULL)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
55 return -1;
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
56
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
57 xs_fseek(f, 0, SEEK_END);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
58 seekPos = xs_ftell(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
59
763
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
60 if (seekPos > 0)
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
61 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
62 size_t readSize = seekPos;
763
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
63 if (readSize >= *bufSize || *buf == NULL)
61a527ac3baa Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
64 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
65 /* Only re-allocate if the required size > current */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
66 if (*buf != NULL) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
67 g_free(*buf);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
68 *buf = NULL;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
69 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
70
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
71 *bufSize = seekPos;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
72
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
73 *buf = (guint8 *) g_malloc(*bufSize * sizeof(guint8));
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
74 if (*buf == NULL) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
75 xs_fclose(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
76 return -2;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
77 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
78 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
79
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
80 /* Read data */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
81 xs_fseek(f, 0, SEEK_SET);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
82 readSize = xs_fread(*buf, sizeof(guint8), *bufSize, f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
83 xs_fclose(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
84
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
85 if (readSize != *bufSize)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
86 return -3;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
87 else
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
88 return 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
89 } else {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
90 xs_fclose(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
91 return -4;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
92 }
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
93 }
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
94
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
95
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
96 /* Copy a given string over in *result.
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
97 */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
98 gint xs_pstrcpy(gchar **result, const gchar *str)
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
99 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
100 /* Check the string pointers */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
101 if (!result || !str)
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
102 return -1;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
103
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
104 /* Allocate memory for destination */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
105 if (*result)
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
106 g_free(*result);
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
107 *result = (gchar *) g_malloc(strlen(str) + 1);
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
108 if (!*result)
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
109 return -2;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
110
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
111 /* Copy to the destination */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
112 strcpy(*result, str);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
114 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
118 /* Concatenates a given string into string pointed by *result.
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
119 */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
120 gint xs_pstrcat(gchar **result, const gchar *str)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
122 /* Check the string pointers */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
123 if (!result || !str)
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
124 return -1;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
125
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
126 if (*result != NULL) {
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
127 *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1);
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
128 if (*result == NULL)
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
129 return -1;
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
130 strcat(*result, str);
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
131 } else {
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
132 *result = (gchar *) g_malloc(strlen(str) + 1);
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
133 if (*result == NULL)
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
134 return -1;
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
135 strcpy(*result, str);
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
136 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
138 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
142 /* Concatenate a given string up to given dest size or \n.
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
143 * If size max is reached, change the end to "..."
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
144 */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
145 void xs_pnstrcat(gchar *dest, size_t iSize, const gchar *str)
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
146 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
147 size_t i, n;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
148 const gchar *s;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
149 gchar *d;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
150
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
151 d = dest;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
152 i = 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
153 while (*d && (i < iSize)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
154 i++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
155 d++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
156 }
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
157
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
158 s = str;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
159 while (*s && (*s != '\n') && (i < iSize)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
160 *d = *s;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
161 d++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
162 s++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
163 i++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
164 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
165
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
166 *d = 0;
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
167
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
168 if (i >= iSize) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
169 i--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
170 d--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
171 n = 3;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
172 while ((i > 0) && (n > 0)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
173 *d = '.';
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
174 d--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
175 i--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
176 n--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
177 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
178 }
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
179 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
180
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
181
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
182 /* Locate character in string
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
183 */
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
184 void xs_findnext(const gchar *str, size_t *pos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 {
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
186 while (str[*pos] && isspace(str[*pos]))
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
187 (*pos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
191 void xs_findeol(const gchar *str, size_t *pos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 {
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
193 while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r'))
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
194 (*pos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
198 void xs_findnum(const gchar *str, size_t *pos)
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
199 {
663
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
200 while (str[*pos] && isdigit(str[*pos]))
180d7a0250d8 More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
201 (*pos)++;
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
202 }
771
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
203
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
204
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
205 /*
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
206 * MD5 implementation, modified for XMMS-SID from
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
207 * Colin Plumb's implementation by Matti 'ccr' Hämäläinen.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
208 *
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
209 * This code implements the MD5 message-digest algorithm.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
210 * The algorithm is due to Ron Rivest. This code was
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
211 * written by Colin Plumb in 1993, no copyright is claimed.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
212 * This code is in the public domain; do with it what you wish.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
213 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
214
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
215 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
216 #define xs_md5_bytereverse(buf, len) /* Nothing */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
217 #else
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
218 #if G_BYTE_ORDER == G_BIG_ENDIAN
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
219 static void xs_md5_bytereverse(guint8 *buf, guint l)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
220 {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
221 guint32 t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
222 do {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
223 t = (guint32) ((guint) buf[3] << 8 | buf[2]) << 16 | ((guint) buf[1] << 8 | buf[0]);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
224 *(guint32 *) buf = t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
225 buf += sizeof(guint32);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
226 } while (--l);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
227 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
228 #else
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
229 #error Unsupported endianess!
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
230 #endif
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
231 #endif
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
232
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
233
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
234 /* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
235 * initialization constants.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
236 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
237 void xs_md5_init(xs_md5state_t *ctx)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
238 {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
239 ctx->buf[0] = 0x67452301;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
240 ctx->buf[1] = 0xefcdab89;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
241 ctx->buf[2] = 0x98badcfe;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
242 ctx->buf[3] = 0x10325476;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
243
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
244 ctx->bits[0] = 0;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
245 ctx->bits[1] = 0;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
246 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
247
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
248
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
249 /* The core of the MD5 algorithm, this alters an existing MD5 hash to
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
250 * reflect the addition of 16 longwords of new data. xs_md5_update blocks
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
251 * the data and converts bytes into longwords for this routine.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
252 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
253 #define F1(x, y, z) (z ^ (x & (y ^ z)))
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
254 #define F2(x, y, z) F1(z, x, y)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
255 #define F3(x, y, z) (x ^ y ^ z)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
256 #define F4(x, y, z) (y ^ (x | ~z))
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
257 #define MD5STEP(f, w, x, y, z, data, s) \
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
258 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
259
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
260 static void xs_md5_transform(guint32 buf[4], guint32 const in[16])
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
261 {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
262 register guint32 a, b, c, d;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
263
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
264 a = buf[0];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
265 b = buf[1];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
266 c = buf[2];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
267 d = buf[3];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
268
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
269 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
270 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
271 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
272 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
273 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
274 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
275 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
276 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
277 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
278 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
279 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
280 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
281 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
282 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
283 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
284 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
285
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
286 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
287 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
288 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
289 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
290 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
291 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
292 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
293 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
294 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
295 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
296 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
297 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
298 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
299 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
300 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
301 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
302
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
303 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
304 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
305 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
306 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
307 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
308 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
309 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
310 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
311 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
312 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
313 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
314 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
315 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
316 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
317 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
318 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
319
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
320 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
321 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
322 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
323 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
324 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
325 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
326 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
327 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
328 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
329 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
330 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
331 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
332 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
333 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
334 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
335 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
336
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
337 buf[0] += a;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
338 buf[1] += b;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
339 buf[2] += c;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
340 buf[3] += d;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
341 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
342
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
343
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
344 /* Update context to reflect the concatenation of another buffer full
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
345 * of bytes.
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
346 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
347 void xs_md5_append(xs_md5state_t *ctx, const guint8 *buf, guint len)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
348 {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
349 guint32 t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
350
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
351 /* Update bitcount */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
352 t = ctx->bits[0];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
353 if ((ctx->bits[0] = t + ((guint32) len << 3)) < t)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
354 ctx->bits[1]++; /* Carry from low to high */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
355 ctx->bits[1] += len >> 29;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
356
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
357 t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
358
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
359 /* Handle any leading odd-sized chunks */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
360 if (t) {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
361 guint8 *p = (guint8 *) ctx->in + t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
362
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
363 t = 64 - t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
364 if (len < t) {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
365 memcpy(p, buf, len);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
366 return;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
367 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
368 memcpy(p, buf, t);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
369 xs_md5_bytereverse(ctx->in, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
370 xs_md5_transform(ctx->buf, (guint32 *) ctx->in);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
371 buf += t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
372 len -= t;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
373 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
374
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
375 /* Process data in 64-byte chunks */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
376 while (len >= 64) {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
377 memcpy(ctx->in, buf, 64);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
378 xs_md5_bytereverse(ctx->in, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
379 xs_md5_transform(ctx->buf, (guint32 *) ctx->in);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
380 buf += 64;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
381 len -= 64;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
382 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
383
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
384 /* Handle any remaining bytes of data. */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
385 memcpy(ctx->in, buf, len);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
386 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
387
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
388 /* Final wrapup - pad to 64-byte boundary with the bit pattern
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
389 * 1 0* (64-bit count of bits processed, MSB-first)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
390 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
391 void xs_md5_finish(xs_md5state_t *ctx, xs_md5hash_t digest)
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
392 {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
393 guint count;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
394 guint8 *p;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
395
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
396 /* Compute number of bytes mod 64 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
397 count = (ctx->bits[0] >> 3) & 0x3F;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
398
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
399 /* Set the first char of padding to 0x80. This is safe since there is
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
400 always at least one byte free */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
401 p = ctx->in + count;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
402 *p++ = 0x80;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
403
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
404 /* Bytes of padding needed to make 64 bytes */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
405 count = 64 - 1 - count;
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
406
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
407 /* Pad out to 56 mod 64 */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
408 if (count < 8) {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
409 /* Two lots of padding: Pad the first block to 64 bytes */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
410 memset(p, 0, count);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
411 xs_md5_bytereverse(ctx->in, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
412 xs_md5_transform(ctx->buf, (guint32 *) ctx->in);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
413
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
414 /* Now fill the next block with 56 bytes */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
415 memset(ctx->in, 0, 56);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
416 } else {
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
417 /* Pad block to 56 bytes */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
418 memset(p, 0, count - 8);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
419 }
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
420 xs_md5_bytereverse(ctx->in, 14);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
421
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
422 /* Append length in bits and transform */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
423 ((guint32 *) ctx->in)[14] = ctx->bits[0];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
424 ((guint32 *) ctx->in)[15] = ctx->bits[1];
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
425
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
426 xs_md5_transform(ctx->buf, (guint32 *) ctx->in);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
427 xs_md5_bytereverse((guint8 *) ctx->buf, 4);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
428 memcpy(digest, ctx->buf, 16);
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
429 memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
469b341734b2 Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents: 763
diff changeset
430 }