Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in two new Digests 'whirlpool' and 'RIPEMD160'. #25

Merged
merged 2 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ Backward incompatible changes:

Date: 2015-01-18

* First version splitted from monolitic buddy package.
* First version splitted from monolitic buddy package.
14 changes: 8 additions & 6 deletions doc/content.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ All hash algorithms are located in the `buddy.core.hash` namespace.
| Tiger | 192
| Blake2b | 512
| Skein | 256, 512, 1024, arbitrary size
| Whirlpool | 512
| RIPEMD160 | 160
|===============================================


Expand Down Expand Up @@ -317,9 +319,9 @@ with some tradeoffs such as them provides additional security feature
explanation about the differences with MAC
link:http://crypto.stackexchange.com/a/5647[here].

*buddy-core* comes with support for:
*buddy-core* comes with support for:
link:https://en.wikipedia.org/wiki/PKCS_1[rsassa-pss],
link:https://en.wikipedia.org/wiki/PKCS_1[rsassa-pkcs] and
link:https://en.wikipedia.org/wiki/PKCS_1[rsassa-pkcs] and
link:https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm[ecdsa].

.Example signing string using rsassa-pss+sha256
Expand Down Expand Up @@ -476,8 +478,8 @@ Ciphers support in buddy is available on `buddy.core.crypto` namespace.

=== Block Ciphers

In cryptography, a block cipher is a deterministic algorithm operating on
fixed-length groups of bits, called blocks, with an unvarying transformation
In cryptography, a block cipher is a deterministic algorithm operating on
fixed-length groups of bits, called blocks, with an unvarying transformation
that is specified by a symmetric key.

.This is a list of currently supported block ciphers in buddy
Expand All @@ -489,7 +491,7 @@ that is specified by a symmetric key.
| Blowfish | `:blowfish`
|========================================

Additionally, for good security, is mandatory to combine a block cipher with
Additionally, for good security, is mandatory to combine a block cipher with
some cipher mode of operation.

.This is a list of currently supported of cipher mode of operation
Expand Down Expand Up @@ -561,7 +563,7 @@ engine requires 8 bytes iv.

NOTE: for decrypt, only change `:op` value to `:decrypt`

You can call `crypto/initialize!` any times as you want, it simply reinitializes
You can call `crypto/initialize!` any times as you want, it simply reinitializes
the engine.


Expand Down
16 changes: 14 additions & 2 deletions src/buddy/core/hash.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
org.bouncycastle.crypto.digests.SHA1Digest
org.bouncycastle.crypto.digests.TigerDigest
org.bouncycastle.crypto.digests.MD5Digest
org.bouncycastle.crypto.digests.RIPEMD160Digest
org.bouncycastle.crypto.digests.SHA3Digest
org.bouncycastle.crypto.digests.SHA256Digest
org.bouncycastle.crypto.digests.SHA384Digest
org.bouncycastle.crypto.digests.SHA512Digest
org.bouncycastle.crypto.digests.Blake2bDigest
org.bouncycastle.crypto.digests.SkeinDigest))
org.bouncycastle.crypto.digests.SkeinDigest
org.bouncycastle.crypto.digests.WhirlpoolDigest))

(def ^:no-doc ^:static
+digest-engines+
{:sha256 #(SHA256Digest.)
:sha384 #(SHA384Digest.)
:sha512 #(SHA512Digest.)
:sha1 #(SHA1Digest.)
:ripemd160 #(RIPEMD160Digest.)
:tiger #(TigerDigest.)
:md5 #(MD5Digest.)
:sha3-256 #(SHA3Digest. 256)
Expand All @@ -45,7 +48,8 @@
:blake2b-512 #(Blake2bDigest. nil 64 nil nil)
:skein-256 #(SkeinDigest. 256 256)
:skein-512 #(SkeinDigest. 512 512)
:skein-1024 #(SkeinDigest. 1024 1024)})
:skein-1024 #(SkeinDigest. 1024 1024)
:whirlpool #(WhirlpoolDigest.)})

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Protocol definitions (abstractions)
Expand Down Expand Up @@ -247,3 +251,11 @@
(defn md5
[input]
(digest input :md5))

(defn whirlpool
[input]
(digest input :whirlpool))

(defn ripemd160
[input]
(digest input :ripemd160))
10 changes: 10 additions & 0 deletions test/buddy/core/hash_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@
(is (= (bytes->hex hashed)
"da39a3ee5e6b4b0d3255bfef95601890afd80709"))))

(testing "whirlpool"
(let [hashed (hash/whirlpool "")]
(is (= (bytes->hex hashed)
"19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"))))

(testing "ripemd160"
(let [hashed (hash/ripemd160 "")]
(is (= (bytes->hex hashed)
"9c1185a5c5e9fc54612808977ee8f548b2258d31"))))

(testing "File hashing"
(let [path "test/_files/pubkey.ecdsa.pem"
stream (io/input-stream path)]
Expand Down