3 * Release $Name: MATRIXSSL_1_8_8_OPEN $
8 * Copyright (c) PeerSec Networks, 2002-2009. All Rights Reserved.
9 * The latest version of this code is available at http://www.matrixssl.org
11 * This software is open source; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This General Public License does NOT permit incorporating this software
17 * into proprietary programs. If you are unable to comply with the GPL, a
18 * commercial license for this software may be purchased from PeerSec Networks
19 * at http://www.peersec.com
21 * This program is distributed in WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * http://www.gnu.org/copyleft/gpl.html
30 /******************************************************************************/
32 #include "../cryptoLayer.h"
34 static const unsigned char map
[256] = {
35 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
36 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
37 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
38 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
39 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
40 255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6,
41 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
42 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
43 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
44 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
45 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255,
46 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
47 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
48 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
49 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
50 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
51 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
52 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
53 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
54 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
55 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
58 int32
ps_base64_decode(const unsigned char *in
, uint32 len
,
59 unsigned char *out
, uint32
*outlen
)
61 unsigned long t
, x
, y
, z
;
65 if (in
== NULL
|| out
== NULL
|| outlen
== NULL
) {
69 for (x
= y
= z
= t
= 0; x
< len
; x
++) {
75 the final = symbols are read and used to trim the remaining bytes
80 prevent g < 0 which would potentially allow an overflow later
83 return CRYPT_INVALID_PACKET
;
87 we only allow = to be at the end
89 return CRYPT_INVALID_PACKET
;
95 if (z
+ g
> *outlen
) {
96 return CRYPT_BUFFER_OVERFLOW
;
98 out
[z
++] = (unsigned char)((t
>>16)&255);
100 out
[z
++] = (unsigned char)((t
>>8)&255);
103 out
[z
++] = (unsigned char)(t
&255);
115 /******************************************************************************/