forked from bytemaster/fc
-
Notifications
You must be signed in to change notification settings - Fork 53
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 #46 from pmconrad/blinding
Blinding a la Oleg Andreev
- Loading branch information
Showing
10 changed files
with
1,136 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
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,63 @@ | ||
/* | ||
* File: hmac.hpp | ||
* Author: Peter Conrad | ||
* | ||
* Created on 1. Juli 2015, 21:48 | ||
*/ | ||
|
||
#ifndef HMAC_HPP | ||
#define HMAC_HPP | ||
|
||
#include <fc/crypto/sha224.hpp> | ||
#include <fc/crypto/sha256.hpp> | ||
#include <fc/crypto/sha512.hpp> | ||
|
||
namespace fc { | ||
|
||
template<typename H> | ||
class hmac | ||
{ | ||
public: | ||
hmac() {} | ||
|
||
H digest( const char* c, uint32_t c_len, const char* d, uint32_t d_len ) | ||
{ | ||
encoder.reset(); | ||
add_key(c, c_len, 0x36); | ||
encoder.write( d, d_len ); | ||
H intermediate = encoder.result(); | ||
|
||
encoder.reset(); | ||
add_key(c, c_len, 0x5c); | ||
encoder.write( intermediate.data(), intermediate.data_size() ); | ||
return encoder.result(); | ||
} | ||
|
||
private: | ||
void add_key( const char* c, const uint32_t c_len, char pad ) | ||
{ | ||
if ( c_len > internal_block_size() ) | ||
{ | ||
H hash = H::hash( c, c_len ); | ||
add_key( hash.data(), hash.data_size(), pad ); | ||
} | ||
else | ||
for (unsigned int i = 0; i < internal_block_size(); i++ ) | ||
{ | ||
encoder.put( pad ^ ((i < c_len) ? *c++ : 0) ); | ||
} | ||
} | ||
|
||
unsigned int internal_block_size() const; | ||
|
||
H dummy; | ||
typename H::encoder encoder; | ||
}; | ||
|
||
typedef hmac<fc::sha224> hmac_sha224; | ||
typedef hmac<fc::sha256> hmac_sha256; | ||
typedef hmac<fc::sha512> hmac_sha512; | ||
} | ||
|
||
#endif /* HMAC_HPP */ | ||
|
Oops, something went wrong.