CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shash Namespace Reference

Classes

struct  HexPtr
 
struct  AsciiPtr
 
struct  Digest
 
struct  Md5
 
struct  Sha1
 
struct  Rmd160
 
struct  Shake128
 
struct  Any
 
class  ContextPtr
 

Typedefs

typedef char Suffix
 

Enumerations

enum  Algorithms {
  kMd5 = 0, kSha1, kRmd160, kShake128,
  kAny
}
 

Functions

Algorithms ParseHashAlgorithm (const string &algorithm_option)
 
Any MkFromHexPtr (const HexPtr hex, const char suffix)
 
Any MkFromSuffixedHexPtr (const HexPtr hex)
 
unsigned GetContextSize (const Algorithms algorithm)
 
void Init (ContextPtr context)
 
void Update (const unsigned char *buffer, const unsigned buffer_length, ContextPtr context)
 
void Final (ContextPtr context, Any *any_digest)
 
void HashMem (const unsigned char *buffer, const unsigned buffer_size, Any *any_digest)
 
void HashString (const std::string &content, Any *any_digest)
 
void Hmac (const string &key, const unsigned char *buffer, const unsigned buffer_size, Any *any_digest)
 
bool HashFd (int fd, Any *any_digest)
 
bool HashFile (const std::string &filename, Any *any_digest)
 
string Sha256File (const string &filename)
 
string Sha256Mem (const unsigned char *buffer, const unsigned buffer_size)
 
string Sha256String (const string &content)
 
std::string Hmac256 (const std::string &key, const std::string &content, bool raw_output)
 
void Hmac (const std::string &key, const unsigned char *buffer, const unsigned buffer_size, Any *any_digest)
 
void HmacString (const std::string &key, const std::string &content, Any *any_digest)
 
std::string Sha256File (const std::string &filename)
 
std::string Sha256String (const std::string &content)
 
Algorithms ParseHashAlgorithm (const std::string &algorithm_option)
 

Variables

const char * kAlgorithmIds []
 
const char kSuffixNone = 0
 
const char kSuffixCatalog = 'C'
 
const char kSuffixHistory = 'H'
 
const char kSuffixMicroCatalog = 'L'
 
const char kSuffixPartial = 'P'
 
const char kSuffixTemporary = 'T'
 
const char kSuffixCertificate = 'X'
 
const char kSuffixMetainfo = 'M'
 
const unsigned kDigestSizes []
 
const unsigned kMaxDigestSize = 20
 
const unsigned kMaxContextSize = 256
 
const unsigned kAlgorithmIdSizes []
 
const unsigned kMaxAlgorithmIdentifierSize = 9
 
const unsigned kBlockSizes []
 

Detailed Description

This file is part of the CernVM File System.

This file is part of the CernVM File System.

Provides a bit syntactic sugar around the hash algorithms. In particular, hashes can easily be created by constructors. Also, we have a little to-string-from-string conversion.

The complexity is due to the need to avoid dynamically allocated memory for the hashes. Almost everything happens on the stack.

Typedef Documentation

typedef char shash::Suffix

Definition at line 112 of file hash.h.

Enumeration Type Documentation

Don't change order! The integer value of the enum constants is used as file catalog flags and as flags in communication with the cache manager. If algorithms are added, the protocol definition for external cache managers needs to be updated, too.

Enumerator
kMd5 
kSha1 
kRmd160 
kShake128 
kAny 

Definition at line 39 of file hash.h.

Function Documentation

unsigned shash::GetContextSize ( const Algorithms  algorithm)

Allows the caller to create the context on the stack.

Actual operations on digests, like "hash a file", "hash a buffer", or iterative operations.

Definition at line 148 of file hash.cc.

Referenced by ChunkItem::ChunkItem(), and download::DownloadManager::Fetch().

Here is the caller graph for this function:

bool shash::HashFd ( int  fd,
Any *  any_digest 
)

Definition at line 321 of file hash.cc.

Referenced by HashFile(), and publish::CmdHash::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

bool shash::HashFile ( const std::string &  filename,
Any *  any_digest 
)

Definition at line 342 of file hash.cc.

Referenced by HasDirtabChanged(), manifest::Reflog::HashDatabase(), and MainCheck().

Here is the call graph for this function:

Here is the caller graph for this function:

void shash::HashMem ( const unsigned char *  buffer,
const unsigned  buffer_size,
Any *  any_digest 
)
void shash::HashString ( const std::string &  content,
Any *  any_digest 
)

Definition at line 268 of file hash.cc.

Referenced by ObjectPackConsumer::ConsumeNext(), whitelist::Whitelist::CreateString(), ObjectPackProducer::GetDigest(), and publish::CmdHash::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

void shash::Hmac ( const string &  key,
const unsigned char *  buffer,
const unsigned  buffer_size,
Any *  any_digest 
)

Definition at line 274 of file hash.cc.

Referenced by cipher::CipherAes256Cbc::GenerateIv(), HmacString(), and s3fanout::S3FanoutManager::MkV2Authz().

Here is the call graph for this function:

Here is the caller graph for this function:

void shash::Hmac ( const std::string &  key,
const unsigned char *  buffer,
const unsigned  buffer_size,
Any *  any_digest 
)
std::string shash::Hmac256 ( const std::string &  key,
const std::string &  content,
bool  raw_output = false 
)

Only used for AWS4 signature.

Adding SHA-256 to the standard hash infrastructure would generally bloat the digets size to 32 bytes and require client data structure transformation during hotpatch.

Definition at line 458 of file hash.cc.

Referenced by s3fanout::S3FanoutManager::GetAwsV4SigningKey(), s3fanout::S3FanoutManager::MkAzureAuthz(), and s3fanout::S3FanoutManager::MkV4Authz().

Here is the caller graph for this function:

void shash::HmacString ( const std::string &  key,
const std::string &  content,
Any *  any_digest 
)
inline

Definition at line 510 of file hash.h.

Referenced by upload::SessionContext::DoUpload(), MakeAcquireRequest(), anonymous_namespace{repository_session.cc}::MakeAcquireRequest(), anonymous_namespace{repository_session.cc}::MakeDropRequest(), and MakeEndRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

Any shash::MkFromHexPtr ( const HexPtr  hex,
const char  suffix 
)
Any shash::MkFromSuffixedHexPtr ( const HexPtr  hex)

Similar to MkFromHexPtr but the suffix is deducted from the HexPtr string.

Definition at line 105 of file hash.cc.

Referenced by swissknife::CommandScrub::FileCallback(), receiver::Reactor::HandleCommit(), swissknife::CommandScrub::OnFileHashed(), and ObjectPackConsumer::ParseItem().

Here is the caller graph for this function:

Algorithms shash::ParseHashAlgorithm ( const std::string &  algorithm_option)
string shash::Sha256File ( const string &  filename)

Definition at line 412 of file hash.cc.

std::string shash::Sha256File ( const std::string &  filename)
std::string shash::Sha256Mem ( const unsigned char *  buffer,
const unsigned  buffer_size 
)

Definition at line 442 of file hash.cc.

Referenced by s3fanout::S3FanoutManager::MkPayloadHash(), and Sha256String().

Here is the caller graph for this function:

string shash::Sha256String ( const string &  content)

Definition at line 452 of file hash.cc.

Referenced by s3fanout::S3FanoutManager::MkV4Authz().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string shash::Sha256String ( const std::string &  content)
void shash::Update ( const unsigned char *  buffer,
const unsigned  buffer_length,
ContextPtr  context 
)

Variable Documentation

const char * shash::kAlgorithmIds
Initial value:
=
{"", "", "-rmd160", "-shake128", ""}

Hex representations of hashes with the same length need a suffix to be distinguished from each other. They should all have one but for backwards compatibility MD5 and SHA-1 have none. Initialized in hash.cc like const char *kAlgorithmIds[] = {"", "", "-rmd160", ...

Definition at line 33 of file hash.cc.

Referenced by shash::Digest< digest_size_, algorithm_ >::Hex::GetAlgorithmIdentifierChar(), and shash::HexPtr::IsValid().

const unsigned shash::kAlgorithmIdSizes[]
Initial value:
=
{0, 0, 7, 9, 0}

Definition at line 84 of file hash.h.

const unsigned shash::kBlockSizes[]
Initial value:
=
{64, 64, 64, 168}

Corresponds to Algorithms. There is no block size for Any. Is an HMAC for SHAKE well-defined?

Definition at line 93 of file hash.h.

Referenced by Hmac().

const unsigned shash::kDigestSizes[]
Initial value:
=
{16, 20, 20, 20, 20}

Corresponds to Algorithms. "Any" is the maximum of all the other digest sizes. When the maximum digest size changes, the memory layout of DirectoryEntry and PosixQuotaManager::LruCommand changes, too!

Definition at line 67 of file hash.h.

Referenced by CacheTransport::FillMsgHash(), signature::SignatureManager::FingerprintCertificate(), FileChunkReflist::HashChunkList(), publish::CmdHash::Main(), PosixQuotaManager::MainCommandServer(), and CacheTransport::ParseMsgHash().

const unsigned shash::kMaxAlgorithmIdentifierSize = 9

Definition at line 87 of file hash.h.

const unsigned shash::kMaxContextSize = 256

The maximum of GetContextSize()

Definition at line 75 of file hash.h.

Referenced by upload::GatewayUploader::DoUpload().

const unsigned shash::kMaxDigestSize = 20
const char shash::kSuffixCatalog = 'C'

Definition at line 52 of file hash.h.

Referenced by manifest::Reflog::AddCatalog(), manifest::Breadcrumb::Breadcrumb(), swissknife::CommandScrub::CheckPathAndExtractHash(), manifest::Reflog::ContainsCatalog(), publish::CheckoutMarker::CreateFrom(), catalog::WritableCatalogManager::CreateRepository(), publish::SettingsBuilder::CreateSettingsPublisher(), publish::SettingsBuilder::CreateSettingsPublisherFromSession(), MountPoint::DetermineRootHash(), AbstractObjectFetcher< LocalObjectFetcher< CatalogT, HistoryT, ReflogT > >::FetchCatalog(), upload::LocalUploader::FinalizeStreamedUpload(), upload::S3Uploader::FinalizeStreamedUpload(), upload::GatewayUploader::FinalizeStreamedUpload(), swissknife::Assistant::GetCatalog(), swissknife::CommandTag::GetCatalog(), manifest::Reflog::GetCatalogTimestamp(), catalog::SqlNestedCatalogLookup::GetContentHash(), catalog::SqlNestedCatalogListing::GetContentHash(), catalog::SqlOwnNestedCatalogListing::GetContentHash(), catalog::Catalog::GetPreviousRevision(), anonymous_namespace{repository_diff.cc}::GetTag(), swissknife::CommandEditTag::GetTagRootHash(), swissknife::CommandTag::InitializeEnvironment(), manifest::Manifest::Load(), ExternalCacheManager::LoadBreadcrumb(), catalog::SimpleCatalogManager::LoadCatalog(), catalog::ClientCatalogManager::LoadCatalog(), catalog::ClientCatalogManager::LoadCatalogCas(), swissknife::CommandListCatalogs::Main(), swissknife::Ingest::Main(), swissknife::CommandFileStats::Main(), swissknife::CommandApplyDirtab::Main(), swissknife::CommandSync::Main(), swissknife::CommandMigrate::Main(), TalkManager::MainResponder(), swissknife::CommandPull::Pull(), manifest::Reflog::Remove(), GarbageCollector< CatalogTraversalT, HashFilterT >::RemoveCatalogFromReflog(), history::SqlGetHashes::RetrieveHash(), history::SqlRecycleBinList::RetrieveHash(), history::SqlRetrieveTag< SqlRollback< SqlHistory > >::RetrieveTag(), catalog::WritableCatalogManager::SnapshotCatalogsSerialized(), and SqlReflog::ToSuffix().

const char shash::kSuffixNone = 0

NOTE: when adding a suffix here, one must edit cvmfs_swissknife scrub accordingly, that checks for invalid hash suffixes

Definition at line 51 of file hash.h.

Referenced by AbstractObjectFetcher< LocalObjectFetcher< CatalogT, HistoryT, ReflogT > >::FetchReflog(), compat::shash_v1::MigrateAny(), history::SqlRecycleBinList::RetrieveHash(), and catalog::SqlAllChunks::SqlAllChunks().

const char shash::kSuffixTemporary = 'T'

Definition at line 56 of file hash.h.