-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from mwpastore/hmac-sha512
Expose HMAC-SHA512 (with 64-byte keys)
- Loading branch information
Showing
6 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# encoding: binary | ||
module RbNaCl | ||
module HMAC | ||
# Computes an authenticator as HMAC-SHA-512 | ||
# | ||
# The authenticator can be used at a later time to verify the provenance of | ||
# the message by recomputing the HMAC over the message and then comparing it to | ||
# the provided authenticator. The class provides methods for generating | ||
# signatures and also has a constant-time implementation for checking them. | ||
# | ||
# This is a secret key authenticator, i.e. anyone who can verify signatures | ||
# can also create them. | ||
# | ||
# @see http://nacl.cr.yp.to/auth.html | ||
class SHA512 < Auth | ||
extend Sodium | ||
|
||
sodium_type :auth | ||
sodium_primitive :hmacsha512 | ||
sodium_constant :BYTES | ||
sodium_constant :KEYBYTES | ||
|
||
sodium_function :auth_hmacsha512, | ||
:crypto_auth_hmacsha512, | ||
[:pointer, :pointer, :ulong_long, :pointer] | ||
|
||
sodium_function :auth_hmacsha512_verify, | ||
:crypto_auth_hmacsha512_verify, | ||
[:pointer, :pointer, :ulong_long, :pointer] | ||
|
||
private | ||
|
||
def compute_authenticator(authenticator, message) | ||
self.class.auth_hmacsha512(authenticator, message, message.bytesize, key) | ||
end | ||
|
||
def verify_message(authenticator, message) | ||
self.class.auth_hmacsha512_verify(authenticator, message, message.bytesize, key) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# encoding: binary | ||
require "spec_helper" | ||
|
||
RSpec.describe RbNaCl::HMAC::SHA512 do | ||
let(:tag) { vector :auth_hmacsha512 } | ||
|
||
include_examples "authenticator" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters