ffi-hydrogen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +30 -0
  5. data/.travis.yml +10 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +72 -0
  9. data/Rakefile +46 -0
  10. data/bench/both.rb +86 -0
  11. data/bench/encode.rb +57 -0
  12. data/bench/encrypt.rb +80 -0
  13. data/bench/init.rb +5 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/ffi-hydrogen.gemspec +31 -0
  17. data/lib/ffi/hydrogen.rb +216 -0
  18. data/vendor/.clang-format +2 -0
  19. data/vendor/.gitignore +3 -0
  20. data/vendor/README.md +2 -0
  21. data/vendor/libhydrogen/.clang-format +95 -0
  22. data/vendor/libhydrogen/.gitignore +32 -0
  23. data/vendor/libhydrogen/.travis.yml +22 -0
  24. data/vendor/libhydrogen/LICENSE +18 -0
  25. data/vendor/libhydrogen/Makefile +61 -0
  26. data/vendor/libhydrogen/Makefile.arduino +51 -0
  27. data/vendor/libhydrogen/README.md +29 -0
  28. data/vendor/libhydrogen/hydrogen.c +18 -0
  29. data/vendor/libhydrogen/hydrogen.h +317 -0
  30. data/vendor/libhydrogen/impl/common.h +316 -0
  31. data/vendor/libhydrogen/impl/core.h +220 -0
  32. data/vendor/libhydrogen/impl/gimli-core/portable.h +39 -0
  33. data/vendor/libhydrogen/impl/gimli-core/sse2.h +97 -0
  34. data/vendor/libhydrogen/impl/gimli-core.h +25 -0
  35. data/vendor/libhydrogen/impl/hash.h +138 -0
  36. data/vendor/libhydrogen/impl/hydrogen_p.h +83 -0
  37. data/vendor/libhydrogen/impl/kdf.h +20 -0
  38. data/vendor/libhydrogen/impl/kx.h +441 -0
  39. data/vendor/libhydrogen/impl/pwhash.h +281 -0
  40. data/vendor/libhydrogen/impl/random.h +376 -0
  41. data/vendor/libhydrogen/impl/secretbox.h +236 -0
  42. data/vendor/libhydrogen/impl/sign.h +207 -0
  43. data/vendor/libhydrogen/impl/x25519.h +383 -0
  44. data/vendor/libhydrogen/library.properties +10 -0
  45. data/vendor/libhydrogen/logo.png +0 -0
  46. data/vendor/libhydrogen/tests/tests.c +431 -0
  47. data/vendor/main.c +140 -0
  48. data/vendor/stringencoders/.gitignore +25 -0
  49. data/vendor/stringencoders/.travis.yml +13 -0
  50. data/vendor/stringencoders/AUTHORS +1 -0
  51. data/vendor/stringencoders/COPYING +2 -0
  52. data/vendor/stringencoders/ChangeLog +170 -0
  53. data/vendor/stringencoders/Doxyfile +276 -0
  54. data/vendor/stringencoders/INSTALL +119 -0
  55. data/vendor/stringencoders/LICENSE +22 -0
  56. data/vendor/stringencoders/Makefile.am +3 -0
  57. data/vendor/stringencoders/NEWS +3 -0
  58. data/vendor/stringencoders/README +2 -0
  59. data/vendor/stringencoders/README.md +32 -0
  60. data/vendor/stringencoders/bootstrap.sh +3 -0
  61. data/vendor/stringencoders/configure-gcc-hardened.sh +16 -0
  62. data/vendor/stringencoders/configure.ac +44 -0
  63. data/vendor/stringencoders/doxy/footer.html +34 -0
  64. data/vendor/stringencoders/doxy/header.html +85 -0
  65. data/vendor/stringencoders/indent.sh +9 -0
  66. data/vendor/stringencoders/javascript/base64-speed.html +43 -0
  67. data/vendor/stringencoders/javascript/base64-test.html +209 -0
  68. data/vendor/stringencoders/javascript/base64.html +18 -0
  69. data/vendor/stringencoders/javascript/base64.js +176 -0
  70. data/vendor/stringencoders/javascript/qunit.css +119 -0
  71. data/vendor/stringencoders/javascript/qunit.js +1062 -0
  72. data/vendor/stringencoders/javascript/urlparse-test.html +367 -0
  73. data/vendor/stringencoders/javascript/urlparse.js +328 -0
  74. data/vendor/stringencoders/make-ci.sh +13 -0
  75. data/vendor/stringencoders/makerelease.sh +16 -0
  76. data/vendor/stringencoders/python/b85.py +176 -0
  77. data/vendor/stringencoders/src/Makefile.am +134 -0
  78. data/vendor/stringencoders/src/arraytoc.c +85 -0
  79. data/vendor/stringencoders/src/arraytoc.h +43 -0
  80. data/vendor/stringencoders/src/extern_c_begin.h +3 -0
  81. data/vendor/stringencoders/src/extern_c_end.h +3 -0
  82. data/vendor/stringencoders/src/html_named_entities_generator.py +203 -0
  83. data/vendor/stringencoders/src/modp_ascii.c +159 -0
  84. data/vendor/stringencoders/src/modp_ascii.h +162 -0
  85. data/vendor/stringencoders/src/modp_ascii_data.h +84 -0
  86. data/vendor/stringencoders/src/modp_ascii_gen.c +55 -0
  87. data/vendor/stringencoders/src/modp_b16.c +125 -0
  88. data/vendor/stringencoders/src/modp_b16.h +148 -0
  89. data/vendor/stringencoders/src/modp_b16_data.h +104 -0
  90. data/vendor/stringencoders/src/modp_b16_gen.c +65 -0
  91. data/vendor/stringencoders/src/modp_b2.c +69 -0
  92. data/vendor/stringencoders/src/modp_b2.h +130 -0
  93. data/vendor/stringencoders/src/modp_b2_data.h +44 -0
  94. data/vendor/stringencoders/src/modp_b2_gen.c +36 -0
  95. data/vendor/stringencoders/src/modp_b36.c +108 -0
  96. data/vendor/stringencoders/src/modp_b36.h +170 -0
  97. data/vendor/stringencoders/src/modp_b64.c +254 -0
  98. data/vendor/stringencoders/src/modp_b64.h +236 -0
  99. data/vendor/stringencoders/src/modp_b64_data.h +477 -0
  100. data/vendor/stringencoders/src/modp_b64_gen.c +168 -0
  101. data/vendor/stringencoders/src/modp_b64r.c +254 -0
  102. data/vendor/stringencoders/src/modp_b64r.h +242 -0
  103. data/vendor/stringencoders/src/modp_b64r_data.h +477 -0
  104. data/vendor/stringencoders/src/modp_b64w.c +254 -0
  105. data/vendor/stringencoders/src/modp_b64w.h +231 -0
  106. data/vendor/stringencoders/src/modp_b64w_data.h +477 -0
  107. data/vendor/stringencoders/src/modp_b85.c +109 -0
  108. data/vendor/stringencoders/src/modp_b85.h +171 -0
  109. data/vendor/stringencoders/src/modp_b85_data.h +36 -0
  110. data/vendor/stringencoders/src/modp_b85_gen.c +65 -0
  111. data/vendor/stringencoders/src/modp_bjavascript.c +65 -0
  112. data/vendor/stringencoders/src/modp_bjavascript.h +105 -0
  113. data/vendor/stringencoders/src/modp_bjavascript_data.h +84 -0
  114. data/vendor/stringencoders/src/modp_bjavascript_gen.c +58 -0
  115. data/vendor/stringencoders/src/modp_burl.c +228 -0
  116. data/vendor/stringencoders/src/modp_burl.h +259 -0
  117. data/vendor/stringencoders/src/modp_burl_data.h +136 -0
  118. data/vendor/stringencoders/src/modp_burl_gen.c +121 -0
  119. data/vendor/stringencoders/src/modp_html.c +128 -0
  120. data/vendor/stringencoders/src/modp_html.h +53 -0
  121. data/vendor/stringencoders/src/modp_html_named_entities.h +9910 -0
  122. data/vendor/stringencoders/src/modp_json.c +315 -0
  123. data/vendor/stringencoders/src/modp_json.h +103 -0
  124. data/vendor/stringencoders/src/modp_json_data.h +57 -0
  125. data/vendor/stringencoders/src/modp_json_gen.py +60 -0
  126. data/vendor/stringencoders/src/modp_mainpage.h +120 -0
  127. data/vendor/stringencoders/src/modp_numtoa.c +350 -0
  128. data/vendor/stringencoders/src/modp_numtoa.h +100 -0
  129. data/vendor/stringencoders/src/modp_qsiter.c +76 -0
  130. data/vendor/stringencoders/src/modp_qsiter.h +71 -0
  131. data/vendor/stringencoders/src/modp_stdint.h +43 -0
  132. data/vendor/stringencoders/src/modp_utf8.c +88 -0
  133. data/vendor/stringencoders/src/modp_utf8.h +38 -0
  134. data/vendor/stringencoders/src/modp_xml.c +311 -0
  135. data/vendor/stringencoders/src/modp_xml.h +166 -0
  136. data/vendor/stringencoders/src/stringencoders.pc +10 -0
  137. data/vendor/stringencoders/src/stringencoders.pc.in +10 -0
  138. data/vendor/stringencoders/test/Makefile.am +113 -0
  139. data/vendor/stringencoders/test/apr_base64.c +262 -0
  140. data/vendor/stringencoders/test/apr_base64.h +120 -0
  141. data/vendor/stringencoders/test/cxx_test.cc +482 -0
  142. data/vendor/stringencoders/test/minunit.h +82 -0
  143. data/vendor/stringencoders/test/modp_ascii_test.c +281 -0
  144. data/vendor/stringencoders/test/modp_b16_test.c +288 -0
  145. data/vendor/stringencoders/test/modp_b2_test.c +250 -0
  146. data/vendor/stringencoders/test/modp_b64_test.c +266 -0
  147. data/vendor/stringencoders/test/modp_b85_test.c +130 -0
  148. data/vendor/stringencoders/test/modp_bjavascript_test.c +137 -0
  149. data/vendor/stringencoders/test/modp_burl_test.c +423 -0
  150. data/vendor/stringencoders/test/modp_html_test.c +296 -0
  151. data/vendor/stringencoders/test/modp_json_test.c +336 -0
  152. data/vendor/stringencoders/test/modp_numtoa_test.c +545 -0
  153. data/vendor/stringencoders/test/modp_qsiter_test.c +280 -0
  154. data/vendor/stringencoders/test/modp_utf8_test.c +188 -0
  155. data/vendor/stringencoders/test/modp_xml_test.c +339 -0
  156. data/vendor/stringencoders/test/speedtest.c +241 -0
  157. data/vendor/stringencoders/test/speedtest_ascii.c +345 -0
  158. data/vendor/stringencoders/test/speedtest_msg.c +78 -0
  159. data/vendor/stringencoders/test/speedtest_numtoa.c +276 -0
  160. metadata +314 -0
@@ -0,0 +1,216 @@
1
+ require "ffi"
2
+
3
+ module FFI
4
+ module Hydrogen
5
+ extend FFI::Library
6
+
7
+ # define hydro_secretbox_KEYBYTES 32
8
+ # define hydro_secretbox_HEADERBYTES (20 + 16)
9
+ KEYBYTES = 32
10
+ HEADERBYTES = 36
11
+
12
+ ffi_lib "vendor/main.#{::FFI::Platform::LIBSUFFIX}"
13
+
14
+ # void hydro_secretbox_keygen(uint8_t key[hydro_secretbox_KEYBYTES])
15
+ attach_function :_hydro_secretbox_keygen, :hydro_secretbox_keygen, [:pointer], :void
16
+
17
+ # int hydro_secretbox_encrypt(uint8_t *c, const void *m_, size_t mlen, uint64_t msg_id,
18
+ # const char ctx[hydro_secretbox_CONTEXTBYTES],
19
+ # const uint8_t key[hydro_secretbox_KEYBYTES])
20
+ attach_function :_hydro_secretbox_encrypt, :hydro_secretbox_encrypt, [:pointer, :pointer, :size_t, :uint64, :pointer, :pointer], :int32
21
+
22
+ # int hydro_secretbox_decrypt(void *m_, const uint8_t *c, size_t clen, uint64_t msg_id,
23
+ # const char ctx[hydro_secretbox_CONTEXTBYTES],
24
+ # const uint8_t key[hydro_secretbox_KEYBYTES])
25
+ attach_function :_hydro_secretbox_decrypt, :hydro_secretbox_decrypt, [:pointer, :pointer, :size_t, :uint64, :pointer, :pointer], :int32
26
+
27
+ # size_t modp_b64_encode(char* dest, const char* str, size_t len)
28
+ attach_function :_modp_b64_encode, :modp_b64_encode, [:pointer, :pointer, :size_t], :size_t
29
+
30
+ # size_t modp_b64_decode(char* dest, const char* src, size_t len)
31
+ attach_function :_modp_b64_decode, :modp_b64_decode, [:pointer, :pointer, :size_t], :size_t
32
+
33
+ # size_t encrypt_encode(char* dest, const char* message, size_t message_len,
34
+ # uint64_t message_id,
35
+ # const char context[hydro_secretbox_CONTEXTBYTES],
36
+ # const uint8_t key[hydro_secretbox_KEYBYTES])
37
+ attach_function :_encrypt_encode, :encrypt_encode, [:pointer, :pointer, :size_t, :uint64, :pointer, :pointer], :size_t
38
+
39
+ # size_t decode_decrypt(char* dest, const void* message, size_t message_len,
40
+ # uint64_t message_id,
41
+ # const char context[hydro_secretbox_CONTEXTBYTES],
42
+ # const uint8_t key[hydro_secretbox_KEYBYTES])
43
+ attach_function :_decode_decrypt, :decode_decrypt, [:pointer, :pointer, :size_t, :uint64, :pointer, :pointer], :size_t
44
+
45
+ def self.encrypt_encode(text, context, key, message_id = 0)
46
+ result = nil
47
+ text_len = text.bytesize
48
+ max_len = modp_b64_encode_len(text_len + HEADERBYTES)
49
+
50
+ create_key(key) do |key_ptr|
51
+ create_context(context) do |context_ptr|
52
+ create_string_and_buffer(text, max_len) do |text_ptr, buff_ptr|
53
+ size = _encrypt_encode(buff_ptr, text_ptr, text_len, message_id, context_ptr, key_ptr)
54
+ result = buff_ptr.get_bytes(0, size)
55
+ end
56
+ end
57
+ end
58
+
59
+ result
60
+ end
61
+
62
+ def self.decode_decrypt(text, context, key, message_id = 0)
63
+ result = nil
64
+ text_len = text.bytesize
65
+ max_len = modp_b64_decode_len(text_len)
66
+
67
+ create_key(key) do |key_ptr|
68
+ create_context(context) do |context_ptr|
69
+ create_string_and_buffer(text, max_len) do |text_ptr, buff_ptr|
70
+ size = _decode_decrypt(buff_ptr, text_ptr, text_len, message_id, context_ptr, key_ptr)
71
+ result = buff_ptr.get_bytes(0, size)
72
+ end
73
+ end
74
+ end
75
+
76
+ result
77
+ end
78
+
79
+ def self.modp_b64_encode(text)
80
+ encoded = nil
81
+ text_len = text.bytesize
82
+ buff_len = modp_b64_encode_len(text_len)
83
+
84
+ create_string_and_buffer(text, buff_len) do |text_ptr, buff_ptr|
85
+ size = ::FFI::Hydrogen._modp_b64_encode(buff_ptr, text_ptr, text_len)
86
+ encoded = buff_ptr.get_bytes(0, size)
87
+ end
88
+
89
+ encoded
90
+ end
91
+
92
+ def self.modp_b64_decode(text)
93
+ decoded = nil
94
+ text_len = text.bytesize
95
+ buff_len = modp_b64_decode_len(text_len)
96
+
97
+ create_string_and_buffer(text, buff_len) do |text_ptr, buff_ptr|
98
+ size = ::FFI::Hydrogen._modp_b64_decode(buff_ptr, text_ptr, text_len)
99
+ decoded = buff_ptr.get_bytes(0, size)
100
+ end
101
+
102
+ decoded
103
+ end
104
+
105
+ def self.modp_b64_encode_len(len)
106
+ ((len + 2) / 3 * 4 + 1)
107
+ end
108
+
109
+ def self.modp_b64_decode_len(len)
110
+ (len / 4 * 3 + 2)
111
+ end
112
+
113
+ def self.hydro_secretbox_keygen
114
+ key = nil
115
+
116
+ ::FFI::MemoryPointer.new(:char, KEYBYTES) do |buff|
117
+ ::FFI::Hydrogen._hydro_secretbox_keygen(buff)
118
+ key = buff.get_bytes(0, KEYBYTES)
119
+ end
120
+
121
+ key
122
+ end
123
+
124
+ def self.hydro_secretbox_encrypt(text, context, key, message_id = 0)
125
+ encrypted = nil
126
+ cipher_len = HEADERBYTES + text.bytesize
127
+
128
+ ::FFI::MemoryPointer.new(:uint8, cipher_len) do |cipher_ptr|
129
+ ::FFI::MemoryPointer.new(:char, text.bytesize) do |text_ptr|
130
+ text_ptr.put_bytes(0, text)
131
+
132
+ create_context(context) do |context_ptr|
133
+ create_key(key) do |key_ptr|
134
+ ::FFI::Hydrogen._hydro_secretbox_encrypt(cipher_ptr, text_ptr, text.bytesize, message_id, context_ptr, key_ptr)
135
+ encrypted = cipher_ptr.get_bytes(0, cipher_len)
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ encrypted
142
+ end
143
+
144
+ def self.hydro_secretbox_decrypt(cipher_text, context, key, message_id = 0)
145
+ encrypted = nil
146
+ cipher_len = cipher_text.bytesize - HEADERBYTES
147
+
148
+ ::FFI::MemoryPointer.new(:char, cipher_len) do |text_ptr|
149
+ ::FFI::MemoryPointer.new(:uint8, cipher_text.bytesize) do |cipher_ptr|
150
+ cipher_ptr.put_bytes(0, cipher_text)
151
+
152
+ create_context(context) do |context_ptr|
153
+ create_key(key) do |key_ptr|
154
+ ::FFI::Hydrogen._hydro_secretbox_decrypt(text_ptr, cipher_ptr, cipher_text.bytesize, message_id, context_ptr, key_ptr)
155
+ encrypted = text_ptr.get_bytes(0, cipher_len)
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ encrypted
162
+ end
163
+
164
+ def self.create_context(context)
165
+ return yield(context) if context.is_a?(::FFI::MemoryPointer)
166
+
167
+ ::FFI::MemoryPointer.new(:char, context.bytesize) do |context_ptr|
168
+ context_ptr.put_bytes(0, context)
169
+ yield(context_ptr)
170
+ end
171
+ end
172
+
173
+ def self.create_key(key)
174
+ return yield(key) if key.is_a?(::FFI::MemoryPointer)
175
+
176
+ ::FFI::MemoryPointer.new(:uint8, key.bytesize) do |key_ptr|
177
+ key_ptr.put_bytes(0, key)
178
+ yield(key_ptr)
179
+ end
180
+ end
181
+
182
+ def self.create_string_and_buffer(text, buff_size)
183
+ ::FFI::MemoryPointer.new(:char, buff_size) do |buff_ptr|
184
+ ::FFI::MemoryPointer.new(:char, text.bytesize) do |text_ptr|
185
+ text_ptr.put_bytes(0, text)
186
+ yield(text_ptr, buff_ptr)
187
+ end
188
+ end
189
+ end
190
+
191
+ class Secretbox
192
+ def initialize(context, key)
193
+ @context_ptr = ::FFI::MemoryPointer.new(:char, context.bytesize)
194
+ @context_ptr.put_bytes(0, context)
195
+ @key_ptr = ::FFI::MemoryPointer.new(:uint8, key.bytesize)
196
+ @key_ptr.put_bytes(0, key)
197
+ end
198
+
199
+ def encrypt(text, message_id = 0)
200
+ ::FFI::Hydrogen.hydro_secretbox_encrypt(text, @context_ptr, @key_ptr, message_id)
201
+ end
202
+
203
+ def decrypt(text, message_id = 0)
204
+ ::FFI::Hydrogen.hydro_secretbox_decrypt(text, @context_ptr, @key_ptr, message_id)
205
+ end
206
+
207
+ def encrypt_encode(text, message_id = 0)
208
+ ::FFI::Hydrogen.encrypt_encode(text, @context_ptr, @key_ptr, message_id)
209
+ end
210
+
211
+ def decode_decrypt(text, message_id = 0)
212
+ ::FFI::Hydrogen.decode_decrypt(text, @context_ptr, @key_ptr, message_id)
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,2 @@
1
+ ReflowComments: false
2
+ BasedOnStyle: Google
data/vendor/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ main
2
+ main.o
3
+ main.dylib
data/vendor/README.md ADDED
@@ -0,0 +1,2 @@
1
+ - `libhydrogen` was downloaded from https://github.com/jedisct1/libhydrogen at this sha: 39eb529905.
2
+ - `stringencoders` was downloaded from https://github.com/client9/stringencoders at this sha: e1448a9415.
@@ -0,0 +1,95 @@
1
+ ---
2
+ Language: Cpp
3
+ AccessModifierOffset: -4
4
+ AlignAfterOpenBracket: Align
5
+ AlignConsecutiveAssignments: true
6
+ AlignConsecutiveDeclarations: true
7
+ AlignEscapedNewlinesLeft: true
8
+ AlignOperands: true
9
+ AlignTrailingComments: true
10
+ AllowAllParametersOfDeclarationOnNextLine: true
11
+ AllowShortBlocksOnASingleLine: false
12
+ AllowShortCaseLabelsOnASingleLine: false
13
+ AllowShortFunctionsOnASingleLine: Inline
14
+ AllowShortIfStatementsOnASingleLine: false
15
+ AllowShortLoopsOnASingleLine: false
16
+ AlwaysBreakAfterDefinitionReturnType: None
17
+ AlwaysBreakAfterReturnType: TopLevelDefinitions
18
+ AlwaysBreakBeforeMultilineStrings: true
19
+ AlwaysBreakTemplateDeclarations: true
20
+ BinPackArguments: true
21
+ BinPackParameters: true
22
+ BraceWrapping:
23
+ AfterClass: false
24
+ AfterControlStatement: false
25
+ AfterEnum: false
26
+ AfterFunction: true
27
+ AfterNamespace: false
28
+ AfterObjCDeclaration: false
29
+ AfterStruct: false
30
+ AfterUnion: false
31
+ BeforeCatch: false
32
+ BeforeElse: false
33
+ IndentBraces: false
34
+ BreakBeforeBinaryOperators: None
35
+ BreakBeforeBraces: WebKit
36
+ BreakBeforeTernaryOperators: true
37
+ BreakConstructorInitializersBeforeComma: true
38
+ BreakAfterJavaFieldAnnotations: false
39
+ BreakStringLiterals: true
40
+ ColumnLimit: 100
41
+ CommentPragmas: '^ IWYU pragma:'
42
+ ConstructorInitializerAllOnOneLineOrOnePerLine: false
43
+ ConstructorInitializerIndentWidth: 4
44
+ ContinuationIndentWidth: 4
45
+ Cpp11BracedListStyle: false
46
+ DerivePointerAlignment: true
47
+ DisableFormat: false
48
+ ExperimentalAutoDetectBinPacking: false
49
+ ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
50
+ IncludeCategories:
51
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
52
+ Priority: 2
53
+ - Regex: '^(<|"(gtest|isl|json)/)'
54
+ Priority: 3
55
+ - Regex: '.*'
56
+ Priority: 1
57
+ IncludeIsMainRegex: '$'
58
+ IndentCaseLabels: false
59
+ IndentWidth: 4
60
+ IndentWrappedFunctionNames: false
61
+ JavaScriptQuotes: Leave
62
+ JavaScriptWrapImports: true
63
+ KeepEmptyLinesAtTheStartOfBlocks: false
64
+ MacroBlockBegin: ''
65
+ MacroBlockEnd: ''
66
+ MaxEmptyLinesToKeep: 1
67
+ NamespaceIndentation: Inner
68
+ ObjCBlockIndentWidth: 4
69
+ ObjCSpaceAfterProperty: true
70
+ ObjCSpaceBeforeProtocolList: true
71
+ PenaltyBreakBeforeFirstCallParameter: 19
72
+ PenaltyBreakComment: 300
73
+ PenaltyBreakFirstLessLess: 120
74
+ PenaltyBreakString: 1000
75
+ PenaltyExcessCharacter: 1000000
76
+ PenaltyReturnTypeOnItsOwnLine: 60
77
+ PointerAlignment: Right
78
+ ReflowComments: true
79
+ SortIncludes: true
80
+ SpaceAfterCStyleCast: true
81
+ SpaceAfterTemplateKeyword: true
82
+ SpaceBeforeAssignmentOperators: true
83
+ SpaceBeforeParens: ControlStatements
84
+ SpaceInEmptyParentheses: false
85
+ SpacesBeforeTrailingComments: 1
86
+ SpacesInAngles: false
87
+ SpacesInContainerLiterals: true
88
+ SpacesInCStyleCastParentheses: false
89
+ SpacesInParentheses: false
90
+ SpacesInSquareBrackets: false
91
+ Standard: Cpp11
92
+ TabWidth: 8
93
+ UseTab: Never
94
+ ...
95
+
@@ -0,0 +1,32 @@
1
+ *.bc
2
+ *.cmake
3
+ *.dSYM
4
+ *.done
5
+ *.final
6
+ *.gcda
7
+ *.gcno
8
+ *.i
9
+ *.la
10
+ *.lo
11
+ *.log
12
+ *.mem
13
+ *.nexe
14
+ *.o
15
+ *.plist
16
+ *.scan
17
+ *.sdf
18
+ *.status
19
+ *.su
20
+ *.tar.*
21
+ *~
22
+ .DS_Store
23
+ .deps
24
+ .dirstamp
25
+ .done
26
+ .libs
27
+ build.options.json
28
+ coverage.info
29
+ depcomp
30
+ hydrogen-crypto.zip
31
+ libhydrogen.a
32
+ tests/tests
@@ -0,0 +1,22 @@
1
+ sudo: false
2
+
3
+ language: c
4
+
5
+ os:
6
+ - linux
7
+
8
+ compiler:
9
+ - clang
10
+ - gcc
11
+ - g++
12
+
13
+ addons:
14
+ apt:
15
+ packages:
16
+ - p7zip-full
17
+
18
+ script:
19
+ - make
20
+ - make test
21
+ - make clean
22
+ - make -f Makefile.arduino package
@@ -0,0 +1,18 @@
1
+ /*
2
+ * ISC License
3
+ *
4
+ * Copyright (c) 2017-2018
5
+ * Frank Denis <j at pureftpd dot org>
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
+ */
@@ -0,0 +1,61 @@
1
+ PREFIX ?= /usr/local
2
+ WFLAGS ?= -Wall -Wextra -Wmissing-prototypes -Wdiv-by-zero -Wbad-function-cast -Wcast-align -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wnested-externs -Wno-unknown-pragmas -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wno-type-limits
3
+ CFLAGS ?= -Os -march=native -fno-exceptions $(WFLAGS)
4
+ CFLAGS += -I.
5
+ OBJ = hydrogen.o
6
+ AR ?= ar
7
+ RANLIB ?= ranlib
8
+
9
+ SRC = \
10
+ hydrogen.c \
11
+ hydrogen.h \
12
+ impl/common.h \
13
+ impl/core.h \
14
+ impl/gimli-core.h \
15
+ impl/hash.h \
16
+ impl/hydrogen_p.h \
17
+ impl/kdf.h \
18
+ impl/kx.h \
19
+ impl/pwhash.h \
20
+ impl/random.h \
21
+ impl/secretbox.h \
22
+ impl/sign.h \
23
+ impl/x25519.h
24
+
25
+ all: lib test
26
+
27
+ lib: libhydrogen.a
28
+
29
+ install: lib
30
+ mkdir -p $(PREFIX)/lib
31
+ install -o 0 -g 0 -m 0755 libhydrogen.a $(PREFIX)/lib 2> /dev/null || install -m 0755 libhydrogen.a $(PREFIX)/lib
32
+ mkdir -p $(PREFIX)/include
33
+ install -o 0 -g 0 -m 0644 hydrogen.h $(PREFIX)/include 2> /dev/null || install -m 0644 hydrogen.h $(PREFIX)/include
34
+ ldconfig 2> /dev/null || true
35
+
36
+ uninstall:
37
+ rm -f $(PREFIX)/lib/libhydrogen.a
38
+ rm -f $(PREFIX)/include/hydrogen.h
39
+
40
+ test: tests/tests
41
+ rm -f tests/tests.done
42
+ tests/tests && touch tests/tests.done
43
+
44
+ tests/tests: $(SRC) tests/tests.c
45
+ $(CC) $(CFLAGS) -O3 -o tests/tests hydrogen.c tests/tests.c
46
+
47
+ $(OBJ): $(SRC)
48
+
49
+ libhydrogen.a: $(OBJ)
50
+ $(AR) -r $@ $^
51
+ $(RANLIB) $@
52
+
53
+ .PHONY: clean
54
+
55
+ clean:
56
+ rm -f libhydrogen.a $(OBJ)
57
+ rm -f tests/tests tests/*.done
58
+
59
+ check: test
60
+
61
+ distclean: clean
@@ -0,0 +1,51 @@
1
+ TARGET_DEVICE ?= atmega328p
2
+ HWTYPE ?= HYDRO_TARGET_DEVICE_ATMEGA328
3
+ ARDUINO_HOME ?= /Applications/Arduino.app/Contents/Java
4
+ ARDUINO_TOOLS ?= $(ARDUINO_HOME)/hardware/tools/avr/bin
5
+ AR = $(ARDUINO_TOOLS)/avr-gcc-ar
6
+ CC = $(ARDUINO_TOOLS)/avr-gcc
7
+ RANLIB = $(ARDUINO_TOOLS)/avr-gcc-ranlib
8
+ WFLAGS ?= -Wall -Wextra -Wmissing-prototypes -Wdiv-by-zero -Wbad-function-cast -Wcast-align -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wnested-externs -Wno-unknown-pragmas -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wno-type-limits
9
+ CFLAGS ?= -mmcu=$(TARGET_DEVICE) -Os -mcall-prologues -fno-exceptions -ffunction-sections -fdata-sections -flto $(WFLAGS)
10
+ CFLAGS += -I. -I$(ARDUINO_HOME)/hardware/arduino/avr/cores/arduino -I$(ARDUINO_HOME)/hardware/arduino/avr/variants/standard
11
+ CFLAGS += -DHYDRO_HWTYPE=$(HYDRO_HWTYPE)
12
+ OBJ = hydrogen.o
13
+ ARDUINO_PACKAGE ?= hydrogen-crypto.zip
14
+ SRC = \
15
+ hydrogen.c \
16
+ hydrogen.h \
17
+ impl/common.h \
18
+ impl/core.h \
19
+ impl/gimli-core.h \
20
+ impl/hash.h \
21
+ impl/hydrogen_p.h \
22
+ impl/kdf.h \
23
+ impl/kx.h \
24
+ impl/pwhash.h \
25
+ impl/random.h \
26
+ impl/secretbox.h \
27
+ impl/sign.h \
28
+ impl/x25519.h \
29
+ impl/gimli-core/portable.h
30
+
31
+ all: lib package
32
+
33
+ package: $(ARDUINO_PACKAGE)
34
+
35
+ $(ARDUINO_PACKAGE):
36
+ 7z a -tzip -mx=9 -r $(ARDUINO_PACKAGE) $(SRC) library.properties
37
+
38
+ lib: libhydrogen.a
39
+
40
+ $(OBJ): $(SRC)
41
+
42
+ libhydrogen.a: $(OBJ)
43
+ $(AR) -ar cr $@ $^
44
+ $(RANLIB) $@
45
+
46
+ .PHONY: clean
47
+
48
+ clean:
49
+ rm -f libhydrogen.a $(OBJ)
50
+ rm -f tests/tests
51
+ rm -f $(ARDUINO_PACKAGE)
@@ -0,0 +1,29 @@
1
+ [![Build Status](https://travis-ci.org/jedisct1/libhydrogen.svg?branch=master)](https://travis-ci.org/jedisct1/libhydrogen?branch=master)
2
+ [![Coverity Scan Build Status](https://scan.coverity.com/projects/13315/badge.svg)](https://scan.coverity.com/projects/13315)
3
+
4
+ ![libhydrogen](https://raw.github.com/jedisct1/libhydrogen/master/logo.png)
5
+ ==============
6
+
7
+ The Hydrogen library is a small, easy-to-use, hard-to-misuse cryptographic library.
8
+
9
+ Features:
10
+ - Consistent high-level API, inspired by libsodium. Instead of low-level primitives, it exposes simple functions to solve common problems that cryptography can solve.
11
+ - 100% built using just two cryptographic building blocks: the [Curve25519](https://cr.yp.to/ecdh.html) elliptic curve, and the [Gimli](https://gimli.cr.yp.to/) permutation.
12
+ - Small and easy to audit. Implemented as one tiny file for every set of operation, and adding a single `.c` file to your project is all it takes to use libhydrogen in your project.
13
+ - The whole code is released under a single, very liberal license (ISC).
14
+ - Zero dynamic memory allocations and low stack requirements (median: 32 bytes, max: 128 bytes). This makes it usable in constrained environments such as microcontrollers.
15
+ - Portable: written in standard C99. Supports Linux, *BSD, MacOS, Windows, and the Arduino IDE out of the box.
16
+ - Can generate cryptographically-secure random numbers, even on Arduino boards.
17
+ - Attempts to mitigate the implications of accidental misuse, even on systems with an unreliable PRG and/or no clock.
18
+
19
+ Non-goals:
20
+ - Having multiple primitives serving the same purpose, even to provide compatibility with other libraries.
21
+ - Networking -- but a simple key exchange API based on the Noise protocol is available, and a STROBE-based transport API will be implemented.
22
+ - Interoperability with other libraries.
23
+ - Replacing libsodium. Libhydrogen tries to keep the number of APIs and the code size down to a minimum.
24
+
25
+ # [Libhydrogen documentation](https://github.com/jedisct1/libhydrogen/wiki)
26
+
27
+ The documentation is maintained in the [libhydrogen wiki](https://github.com/jedisct1/libhydrogen/wiki).
28
+
29
+ The legacy libhydrogen code (leveraging XChaCha20, SipHashX, BLAKE2SX, Curve25519) remains available in the [v0 branch](https://github.com/jedisct1/libhydrogen/tree/v0).
@@ -0,0 +1,18 @@
1
+ #include "hydrogen.h"
2
+
3
+ #include "impl/common.h"
4
+ #include "impl/hydrogen_p.h"
5
+
6
+ #include "impl/core.h"
7
+ #include "impl/gimli-core.h"
8
+ #include "impl/random.h"
9
+
10
+ #include "impl/hash.h"
11
+ #include "impl/kdf.h"
12
+ #include "impl/secretbox.h"
13
+
14
+ #include "impl/x25519.h"
15
+
16
+ #include "impl/kx.h"
17
+ #include "impl/pwhash.h"
18
+ #include "impl/sign.h"