예제 #1
0
StatusWith<SHA1Block> SHA1Block::fromBuffer(const uint8_t* input, size_t inputLen) {
    if (inputLen != kHashLength) {
        return {ErrorCodes::InvalidLength,
                str::stream() << "Unsupported SHA1Hash hash length: " << inputLen};
    }

    HashType newHash;
    memcpy(newHash.data(), input, inputLen);
    return SHA1Block(newHash);
}
예제 #2
0
파일: hmac.c 프로젝트: Noltari/PSGrade
// Calculates the MAC, hmacdigest will contain the result
// Assumes that the last call to HMACBlock was done with len<64
void HMACDone(void) {
  uint8_t i;
  unsigned char temp[SHA1_DIGESTSIZE];
  
  // terminate inner digest and store it
  SHA1Done();
  memcpy(temp, shadigest, SHA1_DIGESTSIZE);
  
  // prepare key for outer digest
  // buffer will contain the original key xor 0x5c
  for (i=0;i<SHA1_BLOCKSIZE;i++) {
    hmackey[i] ^= 0x6a;
  }
  
  // initialize SHA1 and hash key
  SHA1Init();
  SHA1Block(hmackey, SHA1_BLOCKSIZE);
  // hash inner digest and terminate hash
  SHA1Block(temp, SHA1_DIGESTSIZE);
  SHA1Done();
}
예제 #3
0
StatusWith<SHA1Block> SHA1Block::fromBinData(const BSONBinData& binData) {
    if (binData.type != BinDataGeneral) {
        return {ErrorCodes::UnsupportedFormat, "SHA1Block only accepts BinDataGeneral type"};
    }

    if (binData.length != kHashLength) {
        return {ErrorCodes::UnsupportedFormat,
                str::stream() << "Unsupported SHA1Block hash length: " << binData.length};
    }

    HashType newHash;
    memcpy(newHash.data(), binData.data, binData.length);
    return SHA1Block(newHash);
}
예제 #4
0
파일: hmac.c 프로젝트: Noltari/PSGrade
// Initializes HMAC algorithm with given key
// key must be smaller than 64 bytes
void HMACInit(const unsigned char* key, const uint8_t len) {
  uint8_t i;
  
  // copy key, XOR it for the inner digest, pad it to block size
  for (i=0;i<len;i++) {
    hmackey[i] = key[i] ^ 0x36;
  }
  for (i=len;i<SHA1_BLOCKSIZE;i++) {
    hmackey[i] = 0x36;
  }
  
  // initialize SHA1 and hash key
  SHA1Init();
  SHA1Block(hmackey, SHA1_BLOCKSIZE);
}
예제 #5
0
파일: hmac.c 프로젝트: Noltari/PSGrade
// Authenticates blocks of 64 bytes of data.
// Only the last block *must* be smaller than 64 bytes.
void HMACBlock(const unsigned char* data, const uint8_t len) {
  SHA1Block(data, len);
}
예제 #6
0
SHA1Block SHA1Block::fromBinData(std::vector<unsigned char> bytes) {
    HashType newHash;
    invariant(bytes.size() == kHashLength);
    memcpy(newHash.data(), bytes.data(), bytes.size());
    return SHA1Block(newHash);
}