-
Notifications
You must be signed in to change notification settings - Fork 82
/
rbnacl.rb
106 lines (87 loc) · 3.32 KB
/
rbnacl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# encoding: binary
# frozen_string_literal: true
require "rbnacl/version"
require "rbnacl/sodium"
require "rbnacl/sodium/version"
require "rbnacl/serializable"
require "rbnacl/key_comparator"
require "rbnacl/auth"
require "rbnacl/util"
require "rbnacl/random"
require "rbnacl/simple_box"
require "rbnacl/test_vectors"
require "rbnacl/init"
require "rbnacl/aead/base"
# NaCl/libsodium for Ruby
module RbNaCl
# Oh no, something went wrong!
#
# This indicates a failure in the operation of a cryptographic primitive such
# as authentication failing on an attempt to decrypt a ciphertext. Classes
# in the library may define more specific subclasses.
class CryptoError < StandardError; end
# Something, probably a key, is the wrong length
#
# This indicates some argument with an expected length was not that length.
# Since this is probably a cryptographic key, you should check that!
class LengthError < ArgumentError; end
# An incorrect primitive has been passed to a method
#
# This indicates that an attempt has been made to use something (probably a key)
# with an incorrect primitive
class IncorrectPrimitiveError < ArgumentError; end
# The signature was forged or otherwise corrupt
class BadSignatureError < CryptoError; end
# The authenticator was forged or otherwise corrupt
class BadAuthenticatorError < CryptoError; end
# Public Key Encryption (Box): Curve25519XSalsa20Poly1305
require "rbnacl/boxes/curve25519xsalsa20poly1305"
require "rbnacl/boxes/curve25519xsalsa20poly1305/private_key"
require "rbnacl/boxes/curve25519xsalsa20poly1305/public_key"
# Sealed boxes
require "rbnacl/boxes/sealed"
# Secret Key Encryption (SecretBox): XSalsa20Poly1305
require "rbnacl/secret_boxes/xsalsa20poly1305"
# Digital Signatures: Ed25519
require "rbnacl/signatures/ed25519"
require "rbnacl/signatures/ed25519/signing_key"
require "rbnacl/signatures/ed25519/verify_key"
# Group Elements: Curve25519
require "rbnacl/group_elements/curve25519"
# One-time Authentication: Poly1305
require "rbnacl/one_time_auths/poly1305"
# Hash functions: SHA256/512 and Blake2b
require "rbnacl/hash"
require "rbnacl/hash/sha256"
require "rbnacl/hash/sha512"
require "rbnacl/hash/blake2b"
# Password hash functions
require "rbnacl/password_hash"
require "rbnacl/password_hash/scrypt"
if RbNaCl::Sodium::Version::ARGON2_SUPPORTED
require "rbnacl/password_hash/argon2"
end
# HMAC: SHA256/512 and SHA512256
require "rbnacl/hmac/sha256"
require "rbnacl/hmac/sha512256"
require "rbnacl/hmac/sha512"
# AEAD: ChaCha20-Poly1305
require "rbnacl/aead/chacha20poly1305_legacy"
require "rbnacl/aead/chacha20poly1305_ietf"
#
# Bind aliases used by the public API
#
Box = Boxes::Curve25519XSalsa20Poly1305
PrivateKey = Boxes::Curve25519XSalsa20Poly1305::PrivateKey
PublicKey = Boxes::Curve25519XSalsa20Poly1305::PublicKey
SealedBox = Boxes::Sealed
SecretBox = SecretBoxes::XSalsa20Poly1305
SigningKey = Signatures::Ed25519::SigningKey
VerifyKey = Signatures::Ed25519::VerifyKey
GroupElement = GroupElements::Curve25519
OneTimeAuth = OneTimeAuths::Poly1305
end
# Select platform-optimized versions of algorithms
RbNaCl::Init.sodium_init
# Perform self test on load
require "rbnacl/self_test" unless defined?($RBNACL_SELF_TEST) && $RBNACL_SELF_TEST == false