ffi-hydrogen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +46 -0
- data/bench/both.rb +86 -0
- data/bench/encode.rb +57 -0
- data/bench/encrypt.rb +80 -0
- data/bench/init.rb +5 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ffi-hydrogen.gemspec +31 -0
- data/lib/ffi/hydrogen.rb +216 -0
- data/vendor/.clang-format +2 -0
- data/vendor/.gitignore +3 -0
- data/vendor/README.md +2 -0
- data/vendor/libhydrogen/.clang-format +95 -0
- data/vendor/libhydrogen/.gitignore +32 -0
- data/vendor/libhydrogen/.travis.yml +22 -0
- data/vendor/libhydrogen/LICENSE +18 -0
- data/vendor/libhydrogen/Makefile +61 -0
- data/vendor/libhydrogen/Makefile.arduino +51 -0
- data/vendor/libhydrogen/README.md +29 -0
- data/vendor/libhydrogen/hydrogen.c +18 -0
- data/vendor/libhydrogen/hydrogen.h +317 -0
- data/vendor/libhydrogen/impl/common.h +316 -0
- data/vendor/libhydrogen/impl/core.h +220 -0
- data/vendor/libhydrogen/impl/gimli-core/portable.h +39 -0
- data/vendor/libhydrogen/impl/gimli-core/sse2.h +97 -0
- data/vendor/libhydrogen/impl/gimli-core.h +25 -0
- data/vendor/libhydrogen/impl/hash.h +138 -0
- data/vendor/libhydrogen/impl/hydrogen_p.h +83 -0
- data/vendor/libhydrogen/impl/kdf.h +20 -0
- data/vendor/libhydrogen/impl/kx.h +441 -0
- data/vendor/libhydrogen/impl/pwhash.h +281 -0
- data/vendor/libhydrogen/impl/random.h +376 -0
- data/vendor/libhydrogen/impl/secretbox.h +236 -0
- data/vendor/libhydrogen/impl/sign.h +207 -0
- data/vendor/libhydrogen/impl/x25519.h +383 -0
- data/vendor/libhydrogen/library.properties +10 -0
- data/vendor/libhydrogen/logo.png +0 -0
- data/vendor/libhydrogen/tests/tests.c +431 -0
- data/vendor/main.c +140 -0
- data/vendor/stringencoders/.gitignore +25 -0
- data/vendor/stringencoders/.travis.yml +13 -0
- data/vendor/stringencoders/AUTHORS +1 -0
- data/vendor/stringencoders/COPYING +2 -0
- data/vendor/stringencoders/ChangeLog +170 -0
- data/vendor/stringencoders/Doxyfile +276 -0
- data/vendor/stringencoders/INSTALL +119 -0
- data/vendor/stringencoders/LICENSE +22 -0
- data/vendor/stringencoders/Makefile.am +3 -0
- data/vendor/stringencoders/NEWS +3 -0
- data/vendor/stringencoders/README +2 -0
- data/vendor/stringencoders/README.md +32 -0
- data/vendor/stringencoders/bootstrap.sh +3 -0
- data/vendor/stringencoders/configure-gcc-hardened.sh +16 -0
- data/vendor/stringencoders/configure.ac +44 -0
- data/vendor/stringencoders/doxy/footer.html +34 -0
- data/vendor/stringencoders/doxy/header.html +85 -0
- data/vendor/stringencoders/indent.sh +9 -0
- data/vendor/stringencoders/javascript/base64-speed.html +43 -0
- data/vendor/stringencoders/javascript/base64-test.html +209 -0
- data/vendor/stringencoders/javascript/base64.html +18 -0
- data/vendor/stringencoders/javascript/base64.js +176 -0
- data/vendor/stringencoders/javascript/qunit.css +119 -0
- data/vendor/stringencoders/javascript/qunit.js +1062 -0
- data/vendor/stringencoders/javascript/urlparse-test.html +367 -0
- data/vendor/stringencoders/javascript/urlparse.js +328 -0
- data/vendor/stringencoders/make-ci.sh +13 -0
- data/vendor/stringencoders/makerelease.sh +16 -0
- data/vendor/stringencoders/python/b85.py +176 -0
- data/vendor/stringencoders/src/Makefile.am +134 -0
- data/vendor/stringencoders/src/arraytoc.c +85 -0
- data/vendor/stringencoders/src/arraytoc.h +43 -0
- data/vendor/stringencoders/src/extern_c_begin.h +3 -0
- data/vendor/stringencoders/src/extern_c_end.h +3 -0
- data/vendor/stringencoders/src/html_named_entities_generator.py +203 -0
- data/vendor/stringencoders/src/modp_ascii.c +159 -0
- data/vendor/stringencoders/src/modp_ascii.h +162 -0
- data/vendor/stringencoders/src/modp_ascii_data.h +84 -0
- data/vendor/stringencoders/src/modp_ascii_gen.c +55 -0
- data/vendor/stringencoders/src/modp_b16.c +125 -0
- data/vendor/stringencoders/src/modp_b16.h +148 -0
- data/vendor/stringencoders/src/modp_b16_data.h +104 -0
- data/vendor/stringencoders/src/modp_b16_gen.c +65 -0
- data/vendor/stringencoders/src/modp_b2.c +69 -0
- data/vendor/stringencoders/src/modp_b2.h +130 -0
- data/vendor/stringencoders/src/modp_b2_data.h +44 -0
- data/vendor/stringencoders/src/modp_b2_gen.c +36 -0
- data/vendor/stringencoders/src/modp_b36.c +108 -0
- data/vendor/stringencoders/src/modp_b36.h +170 -0
- data/vendor/stringencoders/src/modp_b64.c +254 -0
- data/vendor/stringencoders/src/modp_b64.h +236 -0
- data/vendor/stringencoders/src/modp_b64_data.h +477 -0
- data/vendor/stringencoders/src/modp_b64_gen.c +168 -0
- data/vendor/stringencoders/src/modp_b64r.c +254 -0
- data/vendor/stringencoders/src/modp_b64r.h +242 -0
- data/vendor/stringencoders/src/modp_b64r_data.h +477 -0
- data/vendor/stringencoders/src/modp_b64w.c +254 -0
- data/vendor/stringencoders/src/modp_b64w.h +231 -0
- data/vendor/stringencoders/src/modp_b64w_data.h +477 -0
- data/vendor/stringencoders/src/modp_b85.c +109 -0
- data/vendor/stringencoders/src/modp_b85.h +171 -0
- data/vendor/stringencoders/src/modp_b85_data.h +36 -0
- data/vendor/stringencoders/src/modp_b85_gen.c +65 -0
- data/vendor/stringencoders/src/modp_bjavascript.c +65 -0
- data/vendor/stringencoders/src/modp_bjavascript.h +105 -0
- data/vendor/stringencoders/src/modp_bjavascript_data.h +84 -0
- data/vendor/stringencoders/src/modp_bjavascript_gen.c +58 -0
- data/vendor/stringencoders/src/modp_burl.c +228 -0
- data/vendor/stringencoders/src/modp_burl.h +259 -0
- data/vendor/stringencoders/src/modp_burl_data.h +136 -0
- data/vendor/stringencoders/src/modp_burl_gen.c +121 -0
- data/vendor/stringencoders/src/modp_html.c +128 -0
- data/vendor/stringencoders/src/modp_html.h +53 -0
- data/vendor/stringencoders/src/modp_html_named_entities.h +9910 -0
- data/vendor/stringencoders/src/modp_json.c +315 -0
- data/vendor/stringencoders/src/modp_json.h +103 -0
- data/vendor/stringencoders/src/modp_json_data.h +57 -0
- data/vendor/stringencoders/src/modp_json_gen.py +60 -0
- data/vendor/stringencoders/src/modp_mainpage.h +120 -0
- data/vendor/stringencoders/src/modp_numtoa.c +350 -0
- data/vendor/stringencoders/src/modp_numtoa.h +100 -0
- data/vendor/stringencoders/src/modp_qsiter.c +76 -0
- data/vendor/stringencoders/src/modp_qsiter.h +71 -0
- data/vendor/stringencoders/src/modp_stdint.h +43 -0
- data/vendor/stringencoders/src/modp_utf8.c +88 -0
- data/vendor/stringencoders/src/modp_utf8.h +38 -0
- data/vendor/stringencoders/src/modp_xml.c +311 -0
- data/vendor/stringencoders/src/modp_xml.h +166 -0
- data/vendor/stringencoders/src/stringencoders.pc +10 -0
- data/vendor/stringencoders/src/stringencoders.pc.in +10 -0
- data/vendor/stringencoders/test/Makefile.am +113 -0
- data/vendor/stringencoders/test/apr_base64.c +262 -0
- data/vendor/stringencoders/test/apr_base64.h +120 -0
- data/vendor/stringencoders/test/cxx_test.cc +482 -0
- data/vendor/stringencoders/test/minunit.h +82 -0
- data/vendor/stringencoders/test/modp_ascii_test.c +281 -0
- data/vendor/stringencoders/test/modp_b16_test.c +288 -0
- data/vendor/stringencoders/test/modp_b2_test.c +250 -0
- data/vendor/stringencoders/test/modp_b64_test.c +266 -0
- data/vendor/stringencoders/test/modp_b85_test.c +130 -0
- data/vendor/stringencoders/test/modp_bjavascript_test.c +137 -0
- data/vendor/stringencoders/test/modp_burl_test.c +423 -0
- data/vendor/stringencoders/test/modp_html_test.c +296 -0
- data/vendor/stringencoders/test/modp_json_test.c +336 -0
- data/vendor/stringencoders/test/modp_numtoa_test.c +545 -0
- data/vendor/stringencoders/test/modp_qsiter_test.c +280 -0
- data/vendor/stringencoders/test/modp_utf8_test.c +188 -0
- data/vendor/stringencoders/test/modp_xml_test.c +339 -0
- data/vendor/stringencoders/test/speedtest.c +241 -0
- data/vendor/stringencoders/test/speedtest_ascii.c +345 -0
- data/vendor/stringencoders/test/speedtest_msg.c +78 -0
- data/vendor/stringencoders/test/speedtest_numtoa.c +276 -0
- metadata +314 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* \file modp_b64.h
|
|
3
|
+
* \brief High performance base 64 encode and decode
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* \file
|
|
9
|
+
* <PRE>
|
|
10
|
+
* High performance base64 encoder / decoder
|
|
11
|
+
*
|
|
12
|
+
* Copyright © 2005-2016 Nick Galbreath
|
|
13
|
+
* All rights reserved.
|
|
14
|
+
*
|
|
15
|
+
* https://github.com/client9/stringencoders
|
|
16
|
+
*
|
|
17
|
+
* Released under MIT license. See LICENSE for details.
|
|
18
|
+
* </pre>
|
|
19
|
+
*
|
|
20
|
+
* This uses the standard base 64 alphabet. If you are planning
|
|
21
|
+
* to embed a base 64 encoding inside a URL use modp_b64w instead.
|
|
22
|
+
*
|
|
23
|
+
* ATTENTION: the algorithm may require ALIGNED strings. For Intel
|
|
24
|
+
* chips alignment doens't (perhaps a performance issues). But for
|
|
25
|
+
* Sparc and maybe ARM, use of unaligned strings can core dump.
|
|
26
|
+
* see https://github.com/client9/stringencoders/issues/1
|
|
27
|
+
* see https://github.com/client9/stringencoders/issues/42
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef COM_MODP_STRINGENCODERS_B64
|
|
31
|
+
#define COM_MODP_STRINGENCODERS_B64
|
|
32
|
+
|
|
33
|
+
#include "extern_c_begin.h"
|
|
34
|
+
#include "modp_stdint.h"
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* \brief Encode a raw binary string into base 64.
|
|
38
|
+
* \param[out] dest should be allocated by the caller to contain
|
|
39
|
+
* at least modp_b64_encode_len(len) bytes (see below)
|
|
40
|
+
* This will contain the null-terminated b64 encoded result
|
|
41
|
+
* \param[in] src contains the bytes
|
|
42
|
+
* \param[in] len contains the number of bytes in the src
|
|
43
|
+
* \return length of the destination string plus the ending null byte
|
|
44
|
+
* i.e. the result will be equal to strlen(dest) + 1
|
|
45
|
+
*
|
|
46
|
+
* Example
|
|
47
|
+
*
|
|
48
|
+
* \code
|
|
49
|
+
* char* src = ...;
|
|
50
|
+
* int srclen = ...; //the length of number of bytes in src
|
|
51
|
+
* char* dest = (char*) malloc(modp_b64_encode_len);
|
|
52
|
+
* int len = modp_b64_encode(dest, src, sourcelen);
|
|
53
|
+
* if (len == -1) {
|
|
54
|
+
* printf("Error\n");
|
|
55
|
+
* } else {
|
|
56
|
+
* printf("b64 = %s\n", dest);
|
|
57
|
+
* }
|
|
58
|
+
* \endcode
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
size_t modp_b64_encode(char* dest, const char* str, size_t len);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Decode a base64 encoded string
|
|
65
|
+
*
|
|
66
|
+
* \param[out] dest should be allocated by the caller to contain at least
|
|
67
|
+
* len * 3 / 4 bytes. The destination cannot be the same as the source
|
|
68
|
+
* They must be different buffers.
|
|
69
|
+
* \param[in] src should contain exactly len bytes of b64 characters.
|
|
70
|
+
* if src contains -any- non-base characters (such as white
|
|
71
|
+
* space, -1 is returned.
|
|
72
|
+
* \param[in] len is the length of src
|
|
73
|
+
*
|
|
74
|
+
* \return the length (strlen) of the output, or -1 if unable to
|
|
75
|
+
* decode
|
|
76
|
+
*
|
|
77
|
+
* \code
|
|
78
|
+
* char* src = ...;
|
|
79
|
+
* int srclen = ...; // or if you don't know use strlen(src)
|
|
80
|
+
* char* dest = (char*) malloc(modp_b64_decode_len(srclen));
|
|
81
|
+
* int len = modp_b64_decode(dest, src, sourcelen);
|
|
82
|
+
* if (len == -1) { error }
|
|
83
|
+
* \endcode
|
|
84
|
+
*/
|
|
85
|
+
size_t modp_b64_decode(char* dest, const char* src, size_t len);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Given a source string of length len, this returns the amount of
|
|
89
|
+
* memory the destination string should have.
|
|
90
|
+
*
|
|
91
|
+
* remember, this is integer math
|
|
92
|
+
* 3 bytes turn into 4 chars
|
|
93
|
+
* ceiling[len / 3] * 4 + 1
|
|
94
|
+
*
|
|
95
|
+
* +1 is for any extra null.
|
|
96
|
+
*/
|
|
97
|
+
#define modp_b64_encode_len(A) ((A + 2) / 3 * 4 + 1)
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Given a base64 string of length len,
|
|
101
|
+
* this returns the amount of memory required for output string
|
|
102
|
+
* It maybe be more than the actual number of bytes written.
|
|
103
|
+
* NOTE: remember this is integer math
|
|
104
|
+
* this allocates a bit more memory than traditional versions of b64
|
|
105
|
+
* decode 4 chars turn into 3 bytes
|
|
106
|
+
* floor[len * 3/4] + 2
|
|
107
|
+
*/
|
|
108
|
+
#define modp_b64_decode_len(A) (A / 4 * 3 + 2)
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Will return the strlen of the output from encoding.
|
|
112
|
+
* This may be less than the required number of bytes allocated.
|
|
113
|
+
*
|
|
114
|
+
* This allows you to 'deserialized' a struct
|
|
115
|
+
* \code
|
|
116
|
+
* char* b64encoded = "...";
|
|
117
|
+
* int len = strlen(b64encoded);
|
|
118
|
+
*
|
|
119
|
+
* struct datastuff foo;
|
|
120
|
+
* if (modp_b64_encode_strlen(sizeof(struct datastuff)) != len) {
|
|
121
|
+
* // wrong size
|
|
122
|
+
* return false;
|
|
123
|
+
* } else {
|
|
124
|
+
* // safe to do;
|
|
125
|
+
* if (modp_b64_decode((char*) &foo, b64encoded, len) == -1) {
|
|
126
|
+
* // bad characters
|
|
127
|
+
* return false;
|
|
128
|
+
* }
|
|
129
|
+
* }
|
|
130
|
+
* // foo is filled out now
|
|
131
|
+
* \endcode
|
|
132
|
+
*/
|
|
133
|
+
#define modp_b64_encode_strlen(A) ((A + 2) / 3 * 4)
|
|
134
|
+
|
|
135
|
+
#include "extern_c_end.h"
|
|
136
|
+
|
|
137
|
+
#ifdef __cplusplus
|
|
138
|
+
#include <cstring>
|
|
139
|
+
#include <string>
|
|
140
|
+
|
|
141
|
+
namespace modp {
|
|
142
|
+
/** \brief b64 encode a cstr with len
|
|
143
|
+
*
|
|
144
|
+
* \param[in] s the input string to encode
|
|
145
|
+
* \param[in] len the length of the input string
|
|
146
|
+
* \return a newly allocated b64 string. Empty if failed.
|
|
147
|
+
*/
|
|
148
|
+
inline std::string b64_encode(const char* s, size_t len)
|
|
149
|
+
{
|
|
150
|
+
std::string x(modp_b64_encode_len(len), '\0');
|
|
151
|
+
size_t d = modp_b64_encode(const_cast<char*>(x.data()), s, len);
|
|
152
|
+
if (d == (size_t)-1) {
|
|
153
|
+
x.clear();
|
|
154
|
+
} else {
|
|
155
|
+
x.erase(d, std::string::npos);
|
|
156
|
+
}
|
|
157
|
+
return x;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** \brief b64 encode a cstr
|
|
161
|
+
*
|
|
162
|
+
* \param[in] s the input string to encode
|
|
163
|
+
* \return a newly allocated b64 string. Empty if failed.
|
|
164
|
+
*/
|
|
165
|
+
inline std::string b64_encode(const char* s)
|
|
166
|
+
{
|
|
167
|
+
return b64_encode(s, strlen(s));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** \brief b64 encode a const std::string
|
|
171
|
+
*
|
|
172
|
+
* \param[in] s the input string to encode
|
|
173
|
+
* \return a newly allocated b64 string. Empty if failed.
|
|
174
|
+
*/
|
|
175
|
+
inline std::string b64_encode(const std::string& s)
|
|
176
|
+
{
|
|
177
|
+
return b64_encode(s.data(), s.size());
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* base 64 encode a string (self-modifing)
|
|
182
|
+
*
|
|
183
|
+
* This function is for C++ only (duh)
|
|
184
|
+
*
|
|
185
|
+
* \param[in,out] s the string to be decoded
|
|
186
|
+
* \return a reference to the input string
|
|
187
|
+
*/
|
|
188
|
+
inline std::string& b64_encode(std::string& s)
|
|
189
|
+
{
|
|
190
|
+
std::string x(b64_encode(s.data(), s.size()));
|
|
191
|
+
s.swap(x);
|
|
192
|
+
return s;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
inline std::string b64_decode(const char* src, size_t len)
|
|
196
|
+
{
|
|
197
|
+
std::string x(modp_b64_decode_len(len) + 1, '\0');
|
|
198
|
+
size_t d = modp_b64_decode(const_cast<char*>(x.data()), src, len);
|
|
199
|
+
if (d == (size_t)-1) {
|
|
200
|
+
x.clear();
|
|
201
|
+
} else {
|
|
202
|
+
x.erase(d, std::string::npos);
|
|
203
|
+
}
|
|
204
|
+
return x;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
inline std::string b64_decode(const char* src)
|
|
208
|
+
{
|
|
209
|
+
return b64_decode(src, strlen(src));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* base 64 decode a string (self-modifing)
|
|
214
|
+
* On failure, the string is empty.
|
|
215
|
+
*
|
|
216
|
+
* This function is for C++ only (duh)
|
|
217
|
+
*
|
|
218
|
+
* \param[in,out] s the string to be decoded
|
|
219
|
+
* \return a reference to the input string
|
|
220
|
+
*/
|
|
221
|
+
inline std::string& b64_decode(std::string& s)
|
|
222
|
+
{
|
|
223
|
+
std::string x(b64_decode(s.data(), s.size()));
|
|
224
|
+
s.swap(x);
|
|
225
|
+
return s;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
inline std::string b64_decode(const std::string& s)
|
|
229
|
+
{
|
|
230
|
+
return b64_decode(s.data(), s.size());
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
#endif /* __cplusplus */
|
|
235
|
+
|
|
236
|
+
#endif /* MODP_B64 */
|