Permalink
Browse files

Test vectors for SHA hashes

  • Loading branch information...
1 parent 9da8952 commit 1a9030247457914c409a4a7864b767f00f5a97c7 @stouset committed Mar 20, 2013
Showing with 67 additions and 0 deletions.
  1. +32 −0 test/sodium/hash/sha256_test.rb
  2. +35 −0 test/sodium/hash/sha512_test.rb
View
32 test/sodium/hash/sha256_test.rb
@@ -0,0 +1,32 @@
+require 'test_helper'
+
+describe Sodium::Hash::SHA256 do
+ let (:klass) { Sodium::Hash::SHA256 }
+ let (:primitive) { :sha256 }
+
+ let :constants do
+ { :BYTES => 32 }
+ end
+
+ let :hash do
+ Base64.decode64 'q1MKE+RZFJgrefm34/uplM/R8/si9xzqGvvwK0YMbR0='
+ end
+
+ let(:plaintext) { 'message' }
+
+ it '::primitive must be correct' do
+ self.klass.primitive.must_equal self.primitive
+ end
+
+ it 'must have correct values for its constants' do
+ self.constants.each_pair do |name, value|
+ self.klass[name].must_equal value
+ end
+ end
+
+ it 'must generate hashes' do
+ self.klass.hash(
+ self.plaintext
+ ).must_equal self.hash
+ end
+end
View
35 test/sodium/hash/sha512_test.rb
@@ -0,0 +1,35 @@
+require 'test_helper'
+
+describe Sodium::Hash::SHA512 do
+ let (:klass) { Sodium::Hash::SHA512 }
+ let (:primitive) { :sha512 }
+
+ let :constants do
+ { :BYTES => 64 }
+ end
+
+ let :hash do
+ Base64.decode64 %{
+ +Nr1ejNHzE1rnVdbMf5gd+LLSH9gqWIzwIy0edvzFTjMkV7G1IvbqpbdwaFt
+ tPT5bzcnbPyzUQuCRiQXcNWVLA==
+ }
+ end
+
+ let(:plaintext) { 'message' }
+
+ it '::primitive must be correct' do
+ self.klass.primitive.must_equal self.primitive
+ end
+
+ it 'must have correct values for its constants' do
+ self.constants.each_pair do |name, value|
+ self.klass[name].must_equal value
+ end
+ end
+
+ it 'must generate hashes' do
+ self.klass.hash(
+ self.plaintext
+ ).must_equal self.hash
+ end
+end

0 comments on commit 1a90302

Please sign in to comment.