Crypt API
The crypt library provides a minimal set of crypto for connected devices. It provides Base64 encode/decode, MD5, SHA256, Bcrypt crypto and password utilities.
Extensions
Crypt | Minimal Crypto Library. |
Functions
bool | cryptCheckPassword(cchar *plainTextPassword, cchar *passwordHash) |
Check a plain-text password against a password hash. | |
char* | cryptDecode64(cchar *str) |
Decode a block that has been base64 encoded. | |
char* | cryptDecode64Block(cchar *block, ssize *len, int flags) |
Decode a block that has been base64 encoded. | |
char* | cryptEncode64(cchar *str) |
Encode a string using base64 encoding. | |
char* | cryptEncode64Block(cchar *block, ssize len) |
Encode a block using base64 encoding. | |
char* | cryptGetFileMd5(cchar *path) |
Get an MD5 string hash for a file. | |
char* | cryptGetFileSha256(cchar *path) |
Get a SHA256 hash for the contents of a file. | |
char* | cryptGetMd5(uchar *block, ssize length) |
Get an MD5 hash for a block and return a string hash. | |
void | cryptGetMd5Block(uchar *block, ssize length, uchar hash[CRYPT_MD5_SIZE]) |
Get an MD5 hash for a block and return a binary hash. | |
char* | cryptGetPassword(cchar *prompt) |
Read a password from the console. | |
int | cryptGetRandomBytes(char *buf, ssize length, bool block) |
Get random data. | |
char* | cryptGetSha256(cuchar *block, ssize length) |
Get a SHA256 hash for a block and return a string hash. | |
void | cryptGetSha256Block(cuchar *block, ssize length, uchar hash[CRYPT_SHA256_SIZE]) |
Get a SHA256 hash for a block and return a binary hash. | |
char* | cryptMakePassword(cchar *password, int saltLength, int rounds) |
Make a password using the Blowfish cipher (Bcrypt). | |
void | cryptMd5Finalize(RMd5 *ctx, uchar digest[CRYPT_MD5_SIZE]),typedef,struct,RSha256 |
Low level MD5 hashing API to finalize an MD5 hash compuation and return a binary hash result. | |
char* | cryptMd5HashToString(uchar hash[CRYPT_MD5_SIZE]) |
Convert an MD5 hash to a hex string. | |
void | cryptMd5Init(RMd5 *ctx) |
Low level MD5 hashing API to initialize an MD5 hash computation. | |
void | cryptMd5Update(RMd5 *ctx, uchar *block, uint length) |
Low level MD5 hashing API to update an MD5 hash computation with a block of data. | |
void | cryptSha256Finalize(RSha256 *ctx, uchar hash[CRYPT_SHA256_SIZE]) |
Low level SHA256 hashing API to finalize a SHA256 hash compuation and return a binary result. | |
char* | cryptSha256HashToString(uchar hash[CRYPT_SHA256_SIZE]) |
Convert a SHA256 hash to a string. | |
void | cryptSha256Init(RSha256 *ctx) |
Low level SHA256 hashing API to initialize a SHA256 hash computation. | |
void | cryptSha256Start(RSha256 *ctx) |
Low level SHA256 hashing API to start a SHA256 hash computation. | |
void | cryptSha256Term(RSha256 *ctx) |
Low level SHA256 hashing API to terminate a SHA256 hash compuation. | |
void | cryptSha256Update(RSha256 *ctx, cuchar *block, int length) |
Low level SHA256 hashing API to update a SHA256 hash computation with input data. |
Typedefs
RMd5 | MD5 computation block. |
Defines
#define | CRYPT_BLOWFISH "BF1" |
Blowfish hash tag. | |
#define | CRYPT_BLOWFISH_ROUNDS 128 |
Number of computation rounds. | |
#define | CRYPT_BLOWFISH_SALT_LENGTH 16 |
Length of salt text. | |
#define | CRYPT_DECODE_TOKEQ 1 |
Decode base64 blocks up to a NULL or equals. |
Crypt
Minimal Crypto Library.
- Description:
- The crypt library provides a minimal set of crypto for connected devices. It provides Base64 encode/decode, MD5, SHA256, Bcrypt crypto and password utilities.
- API Stability:
- Evolving.
- API Stability:
- Evolving.
- Fields:
-
Check a plain-text password against a password hash.
- Parameters:
-
plainTextPassword Input plain-text password. passwordHash Hash previously computed via cryptMakePassword
- Returns:
- True if the password matches.
- API Stability:
- Evolving.
- See Also:
- cryptGetPassword, cryptMakePassword
Decode a block that has been base64 encoded.
- Parameters:
-
str Base64 encoded string.
- Returns:
- Null terminated decoded string. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptEncode64
Decode a block that has been base64 encoded.
- Parameters:
-
block Base64 encoded string. len Pointer to receive the length of the decoded block. flags Stop decoding at the end of the block or '=' if CRYPT_DECODE_TOKEQ is specified.
- Returns:
- Decoded block string. Caller must free. The length is described via *len.
- API Stability:
- Evolving.
- See Also:
- cryptDecode64, cryptEncode64, cryptEncode64Block
Encode a string using base64 encoding.
- Parameters:
-
str Null terminated string to encode.
- Returns:
- Base64 encoded string. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptEncode64Block
Encode a block using base64 encoding.
- Parameters:
-
block Block of data to encode. len Length of the block.
- Returns:
- Base64 encoded string. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptEncode64
Get an MD5 string hash for a file.
- Parameters:
-
path Filename for the file for which to compute the hash.
- Returns:
- A hex string representation of the hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptGetMd5, cryptGetMd5Block
Get a SHA256 hash for the contents of a file.
- Parameters:
-
path Filename of the file.
- Returns:
- A hex string representation of the hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptGetSha256, cryptGetSha256Block
Get an MD5 hash for a block and return a string hash.
- Parameters:
-
block Block of data for which to compute the hash. length Length of the block. If the length is -1, the block is assumed to be a string and its length is determined by strlen on the block.
- Returns:
- A hex string representation of the hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptGetMd5Block
Get an MD5 hash for a block and return a binary hash.
- Parameters:
-
block Block of data for which to compute the hash. length Length of the block. If the length is -1, the block is assumed to be a string and its length is determined by strlen on the block. hash Array to receive the hash.
- API Stability:
- Evolving.
- See Also:
- cryptGetMd5
Read a password from the console.
- Description:
- Used by utility programs to read passwords from the console.
- Parameters:
-
prompt Password user prompt.
- Returns:
- The input password. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptMakePassword
Get random data.
- Parameters:
-
buf Result buffer to hold the random data. length Size of the buffer. block Set to true to read from a blocking random generator that will guarantee the return of random data in the situation of insufficient entropy at the time the call was made.
- Returns:
- The input password. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptMakePassword
Get a SHA256 hash for a block and return a string hash.
- Parameters:
-
block Block of data for which to compute the hash. If set to -1, the block is assumed to be a null terminated string. length Length of the data block.
- Returns:
- A hex string representation of the hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
Get a SHA256 hash for a block and return a binary hash.
- Parameters:
-
block Block of data for which to compute the hash. length Length of the data block. If set to -1, the block is assumed to be a null terminated string. hash Array to receive the hash result.
- API Stability:
- Evolving.
- See Also:
- cryptGetFileSha256, cryptGetSha256
Make a password using the Blowfish cipher (Bcrypt).
- Parameters:
-
password Input plain-text password. saltLength Length of salt text to add. rounds Number of computation rounds. Default is 128. Longer is slower, but more secure.
- Returns:
- The computed password hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptCheckPassword, cryptGetPassword
Low level MD5 hashing API to finalize an MD5 hash compuation and return a binary hash result.
- Description:
- Finalize the hash computation.
- Parameters:
-
ctx MD5 context. digest MD5 array to receive the hash result.
- API Stability:
- Evolving.
- See Also:
- cryptMd5Init, cryptMd5Update
- API Stability:
- Internal.
Convert an MD5 hash to a hex string.
- Parameters:
-
hash Previously computed MD5 hash.
- Returns:
- A hex string representation of the hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptGetMd5, cryptGetMd5Block
Low level MD5 hashing API to initialize an MD5 hash computation.
- Description:
- Initialize the hash computation.
- Parameters:
-
ctx MD5 context.
- API Stability:
- Evolving.
- See Also:
- cryptMd5Finalize, cryptMd5Update
Low level MD5 hashing API to update an MD5 hash computation with a block of data.
- Description:
- Update the hash computation with input.
- Parameters:
-
ctx MD5 context. block Input block to add to the hash. length Length of the input block.
- API Stability:
- Evolving.
- See Also:
- cryptMd5Finalize, cryptMd5Init
Low level SHA256 hashing API to finalize a SHA256 hash compuation and return a binary result.
- Description:
- Finalize the hash computation and return a binary hash result.
- Parameters:
-
ctx SHA256 context. hash Array to receive the hash result.
- API Stability:
- Evolving.
- See Also:
- cryptSha256Init, cryptSha256Start, cryptSha256Term, cryptSha256Update
Convert a SHA256 hash to a string.
- Parameters:
-
hash Hash result from cryptGetSha256Block
- Returns:
- A hex string representation of the hash. Caller must free.
- API Stability:
- Evolving.
- See Also:
- cryptGetSha256, cryptGetSha256Block
Low level SHA256 hashing API to initialize a SHA256 hash computation.
- Description:
- Initialize the hash computation.
- Parameters:
-
ctx SHA256 context.
- API Stability:
- Evolving.
- See Also:
- cryptSha256Finalize, cryptSha256Start, cryptSha256Update
Low level SHA256 hashing API to start a SHA256 hash computation.
- Description:
- Start the hash computation.
- Parameters:
-
ctx SHA256 context.
- API Stability:
- Evolving.
Low level SHA256 hashing API to terminate a SHA256 hash compuation.
- Description:
- Terminate (conclude) the hash computation. This erases in-memory state and should be the final step in computing a hash.
- Parameters:
-
ctx SHA256 context.
- API Stability:
- Evolving.
Low level SHA256 hashing API to update a SHA256 hash computation with input data.
- Description:
- Update the hash computation with a block of data.
- Parameters:
-
ctx SHA256 context. block Block of data to hash. length Length of the input block.
- API Stability:
- Evolving.
Typedefs
MD5 computation block.
- API Stability:
- Internal.
- Fields:
-
uint state[4] MD5 hashing state.