Commit Graph

126 Commits

Author SHA1 Message Date
Olivier Chéron
775855994c Use notElem 2020-03-15 15:44:35 +01:00
Olivier Chéron
096e2ec0bd Add XSalsa.derive and example
This function adds one more HSalsa key derivation to an XSalsa context
that has previously been initialized.  It allows multi-level cascades
like the 2-level done by NaCl crypto_box.
2019-09-09 19:32:24 +02:00
Olivier Chéron
3ae08ed509 Add API to generate a random nonce
This AEAD scheme is compatible with choosing the nonce randomly.
2019-08-25 16:38:08 +02:00
Olivier Chéron
908f979d44 Add AES-GCM-SIV 2019-08-25 16:38:01 +02:00
Olivier Chéron
0075b57f90 Add internal AES CTR variant with 32-bit counter
This variant of CTR mode is used by AES-GCM-SIV.  The counter is in
little-endian format and uses the first four bytes of the IV only.
2019-08-25 08:55:49 +02:00
Olivier Chéron
4df2a95276 AES GCM: use Shoup's method with 4-bit table 2019-06-06 06:48:16 +02:00
Olivier Chéron
76ba39fc95 Add benchmark with AES GCM and CCM 2019-05-19 11:16:34 +02:00
Lars Petersen
2a26202a32 Add implementation of bcrypt_pbkdf 2019-03-14 21:30:29 +01:00
Olivier Chéron
d67a21f95f Remove unnecessary imports and calls 2019-03-09 09:08:53 +01:00
Olivier Chéron
107317c84d Improve strictness in Blowfish rounds 2019-03-04 06:39:55 +01:00
Olivier Chéron
717de392cd Merge pull request #238 from lpeterse/master
Extend the internal interface of the Blowfish module.
2019-03-04 06:37:15 +01:00
Crockett
0fb8a73d3b Fixed compiler warnings 2019-02-03 16:06:05 -08:00
Lars Petersen
ff8a1c524d Extend the internal interface of the Blowfish module.
In preparation of an implementation of the bcrypt_pbkdf (a
variant of PBKDF2 used by OpenSSH) algorithm,
certain low-level operations of the Blowfish algorithm need to
be generalized and exposed.

The Blowfish.Primitive module has already been extended to
account for the requirements imposed by the BCrypt algorithm,
but the salt length was limited to 16 bytes and the BCrypt
specific key schedule setup has been hard-coded into the Blowfish
module.

This commit makes a clear distintion between the expandKey and
expandKeyWithSalt operation. Both take arbitrary sized salts
and keys now. The specialized operation for 16 byte salts as used
by BCrypt has been preserved and is selected automatically.
Also, the BCrypt specific parts have been move to the BCrypt
module with regard to separation of concern.

A benchmark for generating BCrypt hashes with cost 10 shows a
performance improvement from 158 to 141ms on average (Intel i5-6500)
after this refactoring.
Further experiments suggest that the specialized expandKeyWithSalt128
does not have any advantage over the generalized version
and might be removed in favour of less branches and exceptional
behaviour.
2018-05-08 22:08:20 +02:00
Olivier Chéron
325c87febf Use pattern matching 2018-02-04 14:35:43 +01:00
Olivier Chéron
4926cbb143 Improve types and indentation, fix typo 2018-02-03 19:05:20 +01:00
Baojun Wang
1e57f41e1d check AESCCM IV length in ccmInit instead of aeadInit 2018-02-03 09:34:57 +01:00
Baojun Wang
f6d9fb0cf1 aeadInit (ccm) returns CryptoError_IvSizeInvalid when iv size is wrong 2018-02-03 09:34:57 +01:00
Baojun Wang
48770bf79f fix aes ccm decryption cbcmac mis-match 2018-02-03 09:34:57 +01:00
Baojun Wang
1e04890d73 Add ccm decrypt 2018-02-03 09:34:57 +01:00
Baojun Wang
55bf620365 add aes ccm support 2018-02-03 09:31:36 +01:00
Chris Martin
f77994a729 Various documentation copy editing 2017-11-18 14:27:44 -05:00
Olivier Chéron
bb2363eea7 Add CAST5 aka CAST-128
Haskell translation of RFC 2144.
2017-09-17 11:28:56 +02:00
Vincent Hanquez
f559c7bd9d [ChaCha] only need ByteArrayAccess for initialization 2017-07-07 17:31:30 +01:00
Olivier Chéron
edd5d94bd4 Make ivAdd more constant-time
All IV bytes are processed even if accumulator is zero.
2017-05-31 23:31:29 +02:00
Olivier Chéron
07592ab237 Fix ivAdd overflow behaviour 2017-05-26 09:59:54 +02:00
Sam Protas
04b4c945c0 Add import to fix backwards compatibility 2017-04-10 00:57:49 -04:00
Sam Protas
762d818ec0 Twofish 192 and 256 bit key support 2017-04-10 00:33:54 -04:00
Sam Protas
b658c8a99b Cleanup and performance 2017-04-04 19:29:40 -04:00
Sam Protas
b1a9c7c047 Performance improvements 2017-04-02 19:36:58 -04:00
Sam Protas
7eedbaa112 Initial implementaiton with passing tests 2017-04-02 18:34:10 -04:00
Tim McIver
f5efdee75b Add key length validation to several AES Ciphers. 2016-12-06 22:06:57 -05:00
Brandon Hamilton
548cbb6f79 Implement the XSalsa20 stream cipher 2016-10-09 15:25:31 +02:00
Luke Taylor
fb66c35f46 Add a check for salt length in bcrypt function
Raises an error (as the original doc claimed) if the salt is not the
required length of 16 bytes.

validatePasswordEither doesn't require separate checking since the hash
length as a whole is checked, implicitly ensuring the salt is the right
length. Therefore it shouldn't be possible to trigger the error by
calling this function.

Fixes #93.
2016-07-27 17:45:33 +02:00
kinoru
5a2809a0f8 [ChaChaPoly1305] fix type error of example code
The example code had a type mismatch.

    Couldn't match expected type ‘State’
                with actual type ‘CryptoFailable State’
    In the second argument of ‘appendAAD’, namely ‘st1’
    In the second argument of ‘($)’, namely ‘appendAAD hdr st1’

This is due to the following part:

    let st1 = ChaChaPoly1305.initialize key nonce
        st2 = ChaChaPoly1305.finalizeAAD $ ChaChaPoly1305.appendAAD hdr st1

`initialize` returns `CryptoFailable State`, not `State`.

This commit fixes the type mismatch, changes the return type of the
example function to `CryptoFailable ByteString`, and makes the code
to be immediately copy-and-paste-able.
2015-12-03 18:05:04 +00:00
John Galt
53270f1ef6 Removed unused language extension 2015-11-16 13:13:18 -05:00
John Galt
320186cdd1 Fix endianness of incrementNonce function for ChaChaPoly1305 2015-11-16 12:59:01 -05:00
Vincent Hanquez
7bd3a8f892 [ChaChaPoly1305] Document everything 2015-11-04 15:17:32 +00:00
John Galt
55c6988a6e Added support for incrementing Nonces 2015-10-05 14:08:08 -04:00
Joachim Breitner
507a8f8cea Use mkLE, not LE
to make sure the conversion to little endian is actually happening. This
fixes a test failure in ChaChaPoly1305. Fixes #31.
2015-08-27 14:52:37 +02:00
Vincent Hanquez
ea8cb2d45a [blowfish] remove unnecessary list of word32 for the schedule
Just use the binary's array directly
2015-08-27 10:57:28 +01:00
Luke Taylor
2566e46185 Implement the eksBlowfish function
This modifies the standard blowfish key schedule function to accept an
optional salt and cost as used in bcrypt and modifies the algorithm
accordingly to implement the "expensive" version.

The standard blowfish version is just the same but with a salt value of
zero and a single call to the expandKey function. See the original
bcrypt paper for more details.
2015-08-26 10:33:35 +01:00
Luke Taylor
08ebde2f09 Modify creation of Blowfish key schedule
Changes to create it from an array of Word32, instead of using
mutableArray32FromAddrBE, which seems to reverse the words.
2015-08-26 10:33:35 +01:00
Vincent Hanquez
8a0bacfc6d [Poly1305] make initialize explicitely failable 2015-07-29 09:49:49 +01:00
Vincent Hanquez
e064af5cba [chachapoly1305] properly handle the decryption, and change combine to encrypt. 2015-07-29 07:24:46 +01:00
Vincent Hanquez
ce849fb0d2 [ChaChaPoly1305] add implementation and simple KAT test 2015-07-19 17:53:56 +01:00
Vincent Hanquez
ce043f49a1 [AES] fix wrongly indented comment 2015-07-19 17:51:00 +01:00
Luke Taylor
875b80107c Remove unused AES primitives functions and exports
The code for initializing different AEAD modes is now encapsulated in
the BlockCipher type and the individual mode encryption and decryption
functions have been replaced by generalized versions, so are no longer
used.
2015-06-09 11:45:39 +02:00
Luke Taylor
4e1437d4fd Minor haddock fixes
Fix some incorrect parameter descriptions and spelling/typos.
2015-06-07 13:26:26 +02:00
Vincent Hanquez
be75de64e1 [aes] fast track length == 0 with ECB encryption/decryption 2015-06-02 14:22:26 +01:00
Vincent Hanquez
8eaaa06e1e add optional support for deepseq 2015-05-22 18:35:46 +01:00