RubyDoc.info:

Module: RbNaCl::Hash

– Documentation for cryptosphere/rbnacl (main)

– RubyDoc.info (original) (raw)

Defined in:

lib/rbnacl/hash.rb,
lib/rbnacl/hash/sha256.rb,
lib/rbnacl/hash/sha512.rb,
lib/rbnacl/hash/blake2b.rb

Overview

Cryptographic hash functions

Cryptographic hash functions take a variable length message and compute a fixed length string, the message digest. Even a small change in the input data should produce a large change in the digest, and it is 'very difficult' to create two messages with the same digest.

A cryptographic hash can be used for checking the integrity of data, but there is no secret involved in the hashing, so anyone can create the hash of a given message.

RbNaCl provides the SHA-256,SHA-512 as well as the Blake2b hash functions.

Defined Under Namespace

Modules: SHA256, SHA512 Classes: Blake2b

Class Method Summarycollapse

Class Method Details

.blake2b(data, options = {}) ⇒ String

Returns the Blake2b hash of the given data

There's no streaming done, just pass in the data and be done with it. This method returns a 64-byte hash by default.

65 66 67 # File 'lib/rbnacl/hash.rb', line 65 def self.blake2b(data, options = {}) Blake2b.digest(data, options) end

.sha256(data) ⇒ String

Returns the SHA-256 hash of the given data

There's no streaming done, just pass in the data and be done with it.

| 27 28 29 30 31 32 | # File 'lib/rbnacl/hash.rb', line 27 def self.sha256(data) data = data.to_str digest = Util.zeros(SHA256::BYTES) SHA256.hash_sha256(digest, data, data.bytesize) || raise(CryptoError, "Hashing failed!") digest end | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

.sha512(data) ⇒ String

Returns the SHA-512 hash of the given data

There's no streaming done, just pass in the data and be done with it.

| 43 44 45 46 47 | # File 'lib/rbnacl/hash.rb', line 43 def self.sha512(data) digest = Util.zeros(SHA512::BYTES) SHA512.hash_sha512(digest, data, data.bytesize) || raise(CryptoError, "Hashing failed!") digest end | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |