x25519 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +3 -0
- data/CHANGES.md +3 -0
- data/Gemfile +3 -2
- data/README.md +205 -14
- data/Rakefile +9 -1
- data/ext/x25519/cputest.c +68 -0
- data/ext/x25519/extconf.rb +31 -0
- data/ext/x25519/ref10/api.h +2 -0
- data/ext/x25519/ref10/base.c +12 -0
- data/ext/x25519/ref10/fe.h +44 -0
- data/ext/x25519/ref10/fe_0.c +19 -0
- data/ext/x25519/ref10/fe_1.c +19 -0
- data/ext/x25519/ref10/fe_add.c +57 -0
- data/ext/x25519/ref10/fe_copy.c +29 -0
- data/ext/x25519/ref10/fe_cswap.c +73 -0
- data/ext/x25519/ref10/fe_frombytes.c +67 -0
- data/ext/x25519/ref10/fe_invert.c +14 -0
- data/ext/x25519/ref10/fe_mul.c +252 -0
- data/ext/x25519/ref10/fe_mul121666.c +69 -0
- data/ext/x25519/ref10/fe_sq.c +148 -0
- data/ext/x25519/ref10/fe_sub.c +57 -0
- data/ext/x25519/ref10/fe_tobytes.c +119 -0
- data/ext/x25519/ref10/montgomery.h +140 -0
- data/ext/x25519/ref10/pow225521.h +160 -0
- data/ext/x25519/ref10/scalarmult.c +46 -0
- data/ext/x25519/{fp25519_x64.c → rfc7748_precomputed/fp25519_x64.c} +14 -16
- data/ext/x25519/{fp25519_x64.h → rfc7748_precomputed/fp25519_x64.h} +6 -10
- data/ext/x25519/{bytes.h → rfc7748_precomputed/rfc7748_precomputed.h} +13 -5
- data/ext/x25519/{table_ladder_x25519.h → rfc7748_precomputed/table_ladder_x25519.h} +0 -0
- data/ext/x25519/{x25519_x64.c → rfc7748_precomputed/x25519_x64.c} +16 -29
- data/ext/x25519/x25519.c +325 -0
- data/ext/x25519/x25519.h +24 -0
- data/x25519.gemspec +3 -6
- metadata +32 -15
- data/ext/x25519/bytes.c +0 -42
- data/ext/x25519/random.c +0 -51
- data/ext/x25519/random.h +0 -24
- data/ext/x25519/rfc7748_precompted.h +0 -49
- data/ext/x25519/rfc7748_precomputed.c +0 -20
- data/lib/x25519.rb +0 -7
- data/lib/x25519/version.rb +0 -5
data/ext/x25519/x25519.h
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#include "rfc7748_precomputed.h"
|
2
|
+
|
3
|
+
/* Detect support for 4th gen (e.g. Haswell) or newer CPUs */
|
4
|
+
int check_4th_gen_intel_core_features();
|
5
|
+
|
6
|
+
/**********************************
|
7
|
+
* rfc7748_precomputed prototypes *
|
8
|
+
**********************************/
|
9
|
+
|
10
|
+
/* Fixed-base scalar multiplication */
|
11
|
+
void x25519_rfc7748_precomputed_scalarmult_base(uint8_t *session_key, uint8_t *private_key);
|
12
|
+
|
13
|
+
/* Variable-base scalar multiplication */
|
14
|
+
void x25519_rfc7748_precomputed_scalarmult(uint8_t *shared, uint8_t *private_key, uint8_t *session_key);
|
15
|
+
|
16
|
+
/********************
|
17
|
+
* ref10 prototypes *
|
18
|
+
********************/
|
19
|
+
|
20
|
+
/* Fixed-base scalar multiplication */
|
21
|
+
int x25519_ref10_scalarmult_base(uint8_t *q, const uint8_t *n);
|
22
|
+
|
23
|
+
/* Variable-base scalar multiplication */
|
24
|
+
int x25519_ref10_scalarmult(uint8_t *q, const uint8_t *n, const uint8_t *p);
|
data/x25519.gemspec
CHANGED
@@ -1,13 +1,8 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
lib = File.expand_path("../lib", __FILE__)
|
5
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require "x25519/version"
|
7
|
-
|
8
3
|
Gem::Specification.new do |spec|
|
9
4
|
spec.name = "x25519"
|
10
|
-
spec.version =
|
5
|
+
spec.version = "0.1.0"
|
11
6
|
spec.authors = ["Tony Arcieri"]
|
12
7
|
spec.email = ["bascule@gmail.com"]
|
13
8
|
spec.summary = "Public key cryptography library providing the X25519 D-H function"
|
@@ -22,6 +17,8 @@ Gem::Specification.new do |spec|
|
|
22
17
|
spec.bindir = "exe"
|
23
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
19
|
spec.require_paths = ["lib"]
|
20
|
+
spec.platform = Gem::Platform::RUBY
|
21
|
+
spec.extensions = "ext/x25519/extconf.rb"
|
25
22
|
|
26
23
|
spec.required_ruby_version = ">= 2.2.2"
|
27
24
|
spec.add_development_dependency "bundler", "~> 1.16"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: x25519
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,30 +30,47 @@ description: An efficient public key cryptography library for Ruby providing key
|
|
30
30
|
email:
|
31
31
|
- bascule@gmail.com
|
32
32
|
executables: []
|
33
|
-
extensions:
|
33
|
+
extensions:
|
34
|
+
- ext/x25519/extconf.rb
|
34
35
|
extra_rdoc_files: []
|
35
36
|
files:
|
36
37
|
- ".gitignore"
|
37
38
|
- ".rspec"
|
38
39
|
- ".rubocop.yml"
|
39
40
|
- ".travis.yml"
|
41
|
+
- CHANGES.md
|
40
42
|
- CODE_OF_CONDUCT.md
|
41
43
|
- Gemfile
|
42
44
|
- LICENSE
|
43
45
|
- README.md
|
44
46
|
- Rakefile
|
45
|
-
- ext/x25519/
|
46
|
-
- ext/x25519/
|
47
|
-
- ext/x25519/
|
48
|
-
- ext/x25519/
|
49
|
-
- ext/x25519/
|
50
|
-
- ext/x25519/
|
51
|
-
- ext/x25519/
|
52
|
-
- ext/x25519/
|
53
|
-
- ext/x25519/
|
54
|
-
- ext/x25519/
|
55
|
-
-
|
56
|
-
-
|
47
|
+
- ext/x25519/cputest.c
|
48
|
+
- ext/x25519/extconf.rb
|
49
|
+
- ext/x25519/ref10/api.h
|
50
|
+
- ext/x25519/ref10/base.c
|
51
|
+
- ext/x25519/ref10/fe.h
|
52
|
+
- ext/x25519/ref10/fe_0.c
|
53
|
+
- ext/x25519/ref10/fe_1.c
|
54
|
+
- ext/x25519/ref10/fe_add.c
|
55
|
+
- ext/x25519/ref10/fe_copy.c
|
56
|
+
- ext/x25519/ref10/fe_cswap.c
|
57
|
+
- ext/x25519/ref10/fe_frombytes.c
|
58
|
+
- ext/x25519/ref10/fe_invert.c
|
59
|
+
- ext/x25519/ref10/fe_mul.c
|
60
|
+
- ext/x25519/ref10/fe_mul121666.c
|
61
|
+
- ext/x25519/ref10/fe_sq.c
|
62
|
+
- ext/x25519/ref10/fe_sub.c
|
63
|
+
- ext/x25519/ref10/fe_tobytes.c
|
64
|
+
- ext/x25519/ref10/montgomery.h
|
65
|
+
- ext/x25519/ref10/pow225521.h
|
66
|
+
- ext/x25519/ref10/scalarmult.c
|
67
|
+
- ext/x25519/rfc7748_precomputed/fp25519_x64.c
|
68
|
+
- ext/x25519/rfc7748_precomputed/fp25519_x64.h
|
69
|
+
- ext/x25519/rfc7748_precomputed/rfc7748_precomputed.h
|
70
|
+
- ext/x25519/rfc7748_precomputed/table_ladder_x25519.h
|
71
|
+
- ext/x25519/rfc7748_precomputed/x25519_x64.c
|
72
|
+
- ext/x25519/x25519.c
|
73
|
+
- ext/x25519/x25519.h
|
57
74
|
- x25519.gemspec
|
58
75
|
homepage: https://github.com/cryptosphere/x25519
|
59
76
|
licenses:
|
data/ext/x25519/bytes.c
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2017 Armando Faz <armfazh@ic.unicamp.br>.
|
3
|
-
* Institute of Computing.
|
4
|
-
* University of Campinas, Brazil.
|
5
|
-
*
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU Lesser General Public License as
|
8
|
-
* published by the Free Software Foundation, version 3.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful, but
|
11
|
-
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
16
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
*/
|
18
|
-
#include <stdio.h>
|
19
|
-
#include "bytes.h"
|
20
|
-
|
21
|
-
void print_bytes(uint8_t * A, int num_bytes)
|
22
|
-
{
|
23
|
-
int i;
|
24
|
-
|
25
|
-
printf("0x");
|
26
|
-
for(i=num_bytes-1;i>=0;i--)
|
27
|
-
{
|
28
|
-
printf("%02x", A[i]);
|
29
|
-
}
|
30
|
-
printf("\n");
|
31
|
-
}
|
32
|
-
|
33
|
-
int compare_bytes(uint8_t* A, uint8_t* B,unsigned int num_bytes)
|
34
|
-
{
|
35
|
-
unsigned int i=0;
|
36
|
-
uint8_t ret=0;
|
37
|
-
for(i=0;i<num_bytes;i++)
|
38
|
-
{
|
39
|
-
ret += A[i]^B[i];
|
40
|
-
}
|
41
|
-
return ret;
|
42
|
-
}
|
data/ext/x25519/random.c
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2017 Armando Faz <armfazh@ic.unicamp.br>.
|
3
|
-
* Institute of Computing.
|
4
|
-
* University of Campinas, Brazil.
|
5
|
-
*
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU Lesser General Public License as
|
8
|
-
* published by the Free Software Foundation, version 3.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful, but
|
11
|
-
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
16
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
*/
|
18
|
-
#include <stdlib.h>
|
19
|
-
#include <stdint.h>
|
20
|
-
#include <stdio.h>
|
21
|
-
|
22
|
-
/** Random number Generator:
|
23
|
-
* Taken from: https://github.com/relic-toolkit/relic/src/rand/relic_rand_call.c
|
24
|
-
*
|
25
|
-
* @warning Provide a secure random number generator.
|
26
|
-
* @param buffer
|
27
|
-
* @param num_bytes
|
28
|
-
*/
|
29
|
-
#include <unistd.h>
|
30
|
-
#include <fcntl.h>
|
31
|
-
void random_bytes(uint8_t *buffer, int num_bytes)
|
32
|
-
{
|
33
|
-
int c, l, fd = open("/dev/urandom", O_RDONLY);
|
34
|
-
|
35
|
-
if (fd == -1)
|
36
|
-
{
|
37
|
-
printf("Error opening /dev/urandom\n");
|
38
|
-
}
|
39
|
-
|
40
|
-
l = 0;
|
41
|
-
do {
|
42
|
-
c = read(fd, buffer + l, num_bytes - l);
|
43
|
-
l += c;
|
44
|
-
if (c == -1)
|
45
|
-
{
|
46
|
-
printf("Error reading /dev/urandom\n");
|
47
|
-
}
|
48
|
-
} while (l < num_bytes);
|
49
|
-
|
50
|
-
close(fd);
|
51
|
-
}
|
data/ext/x25519/random.h
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2017 Armando Faz <armfazh@ic.unicamp.br>.
|
3
|
-
* Institute of Computing.
|
4
|
-
* University of Campinas, Brazil.
|
5
|
-
*
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU Lesser General Public License as
|
8
|
-
* published by the Free Software Foundation, version 3.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful, but
|
11
|
-
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
16
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
*/
|
18
|
-
#ifndef RANDOM_H
|
19
|
-
#define RANDOM_H
|
20
|
-
|
21
|
-
#include <stdint.h>
|
22
|
-
void random_bytes(uint8_t *A, int length);
|
23
|
-
|
24
|
-
#endif /* RANDOM_H */
|
@@ -1,49 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2017 Armando Faz <armfazh@ic.unicamp.br>.
|
3
|
-
* Institute of Computing.
|
4
|
-
* University of Campinas, Brazil.
|
5
|
-
*
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU Lesser General Public License as
|
8
|
-
* published by the Free Software Foundation, version 3.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful, but
|
11
|
-
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
16
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
*/
|
18
|
-
#ifndef RFC7748_PRECOMPUTED_H
|
19
|
-
#define RFC7748_PRECOMPUTED_H
|
20
|
-
|
21
|
-
#include <stdint.h>
|
22
|
-
|
23
|
-
#define ALIGN_BYTES 32
|
24
|
-
#ifdef __INTEL_COMPILER
|
25
|
-
#define ALIGN __declspec(align(ALIGN_BYTES))
|
26
|
-
#else
|
27
|
-
#define ALIGN __attribute__ ((aligned (ALIGN_BYTES)))
|
28
|
-
#endif
|
29
|
-
|
30
|
-
#define X25519_KEYSIZE_BYTES 32
|
31
|
-
typedef ALIGN uint8_t X25519_KEY[X25519_KEYSIZE_BYTES];
|
32
|
-
#define X448_KEYSIZE_BYTES 56
|
33
|
-
typedef ALIGN uint8_t X448_KEY[X448_KEYSIZE_BYTES];
|
34
|
-
|
35
|
-
typedef uint8_t * argKey;
|
36
|
-
typedef void (*KeyGen)(argKey session_key, argKey private_key);
|
37
|
-
typedef void (*Shared)(argKey shared, argKey session_key, argKey private_key);
|
38
|
-
|
39
|
-
void print_X25519_key(argKey key);
|
40
|
-
void print_X448_key(argKey key);
|
41
|
-
void random_X25519_key(argKey key);
|
42
|
-
void random_X448_key(argKey key);
|
43
|
-
|
44
|
-
extern const KeyGen X25519_KeyGen_x64;
|
45
|
-
extern const Shared X25519_Shared_x64;
|
46
|
-
extern const KeyGen X448_KeyGen_x64;
|
47
|
-
extern const Shared X448_Shared_x64;
|
48
|
-
|
49
|
-
#endif /* RFC7748_PRECOMPUTED_H */
|
@@ -1,20 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2017 Armando Faz <armfazh@ic.unicamp.br>.
|
3
|
-
* Institute of Computing.
|
4
|
-
* University of Campinas, Brazil.
|
5
|
-
*
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU Lesser General Public License as
|
8
|
-
* published by the Free Software Foundation, version 3.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful, but
|
11
|
-
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public License
|
16
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
*/
|
18
|
-
#include "rfc7748_precompted.h"
|
19
|
-
|
20
|
-
|
data/lib/x25519.rb
DELETED