1#
2# Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the Apache License 2.0 (the "License").  You may not use
5# this file except in compliance with the License.  You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
9# Tests start with one of these keywords
10#       Cipher Decrypt Derive Digest Encoding KDF MAC PBE
11#       PrivPubKeyPair Sign Verify VerifyRecover
12# and continue until a blank line. Lines starting with a pound sign are ignored.
13
14Title = Base64 tests
15
16Encoding = canonical
17Input = ""
18Output = ""
19
20Encoding = canonical
21Input = "h"
22Output = "aA==\n"
23
24Encoding = canonical
25Input = "hello"
26Output = "aGVsbG8=\n"
27
28Encoding = canonical
29Input = "hello world!"
30Output = "aGVsbG8gd29ybGQh\n"
31
32Encoding = canonical
33Input = 00010203040506070809a0b0c0d0e0f000
34Output = "AAECAwQFBgcICaCwwNDg8AA=\n"
35
36# Missing padding
37Encoding = invalid
38Output = "aGVsbG8"
39
40Encoding = invalid
41Output = "aGVsbG8\n"
42
43# Tolerate missing newline
44Encoding = valid
45Input = "hello"
46Output = "aGVsbG8="
47
48# Don't tolerate extra trailing '='
49Encoding = invalid
50Input = "hello"
51Output = "aGVsbG8==\n"
52
53Encoding = invalid
54Output = "aGVsbG8===\n"
55
56# Don't tolerate data after '='
57Encoding = invalid
58Output = "aGV=sbG8=\n"
59
60# Newlines are ignored
61Encoding = valid
62Input = "hello"
63Output = "aGV\nsbG8=\n"
64
65Encoding = canonical
66Input = "hello"
67Output = 614756736247383d0a
68
69# Invalid characters
70Encoding = invalid
71Output = 614756736247383d0a00
72
73Encoding = invalid
74Output = 61475600736247383d0a
75
76Encoding = invalid
77Output = 61475601736247383d0a
78
79Encoding = invalid
80Output = 61475680736247383d0a
81
82Encoding = invalid
83Output = e14756736247383d0a
84
85Encoding = canonical
86Input = "OpenSSLOpenSSL\n"
87Output = "T3BlblNTTE9wZW5TU0wK\n"
88
89Encoding = valid
90Input = "OpenSSLOpenSSL\n"
91Output = "T3BlblNTTE9wZW5TU0wK"
92
93# Truncate 1-3 chars
94Encoding = invalid
95Output = "T3BlblNTTE9wZW5TU0w"
96
97Encoding = invalid
98Output = "T3BlblNTTE9wZW5TU0"
99
100Encoding = invalid
101Output = "T3BlblNTTE9wZW5TU"
102
103Encoding = invalid
104Output = "T3BlblNTTE9wZW5TU0wK===="
105
106Encoding = invalid
107Output = "T3BlblNTTE9wZW5TU0wK============================================\n"
108
109Encoding = invalid
110Output = "YQ==YQ==YQ==\n"
111
112Encoding = invalid
113Output = "A"
114
115Encoding = invalid
116Output = "A\n"
117
118Encoding = invalid
119Output = "A="
120
121Encoding = invalid
122Output = "A==\n"
123
124Encoding = invalid
125Output = "A===\n"
126
127Encoding = invalid
128Output = "A====\n"
129
130Encoding = valid
131Input = "OpenSSLOpenSSL\n"
132Output = "T3BlblNTTE9wZW5TU0wK\n\n"
133
134Encoding = valid
135Input = "OpenSSLOpenSSL\n"
136Output = "T3BlblNTTE\n9wZW5TU0wK"
137
138# CVE 2015-0292
139Encoding = invalid
140Output = "ZW5jb2RlIG1lCg==================================================================\n"
141
142Encoding = canonical
143Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
144Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA==\n"
145
146Encoding = valid
147Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
148Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA\n==\n"
149
150Encoding = valid
151Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
152Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA=\n=\n"
153
154Encoding = invalid
155Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA====\n"
156
157# Multiline output without padding
158Encoding = canonical
159Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
160Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4\neHh4eHh4eHh4eHh4\n"
161
162# Multiline output with padding
163Encoding = canonical
164Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
165Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4\neHh4eHh4eHh4eHh4eHh4eA==\n"
166
167# Multiline output with line break in the middle of a b64 block is accepted
168Encoding = valid
169Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
170Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh\n4eHh4eHh4eHh4eHh4eHh4eA==\n"
171
172# Long lines are accepted
173Encoding = valid
174Input = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
175Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA==\n"
176
177# Multiline input with data after '='.
178Encoding = invalid
179Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eA==\neHh4eHh4eHh4eHh4eHh4eHh4\n"
180
181Encoding = invalid
182Output = "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4\neA==eHh4eHh4eHh4eHh4eHh4\n"
183
184# B64_EOF ('-') terminates input and trailing bytes are ignored
185Encoding = valid
186Input = "OpenSSLOpenSSL\n"
187Output = "T3BlblNTTE9wZW5TU0wK\n-abcd"
188
189Encoding = valid
190Input = "OpenSSLOpenSSL\n"
191Output = "T3BlblNTTE9wZW5TU0wK-abcd"
192
193