tor  master
Functions
crypto_format.c File Reference

Formatting and parsing code for crypto-related data structures. More...

#include "orconfig.h"
#include "container.h"
#include "crypto_curve25519.h"
#include "crypto_digest.h"
#include "crypto_ed25519.h"
#include "crypto_format.h"
#include "crypto_util.h"
#include "util.h"
#include "util_format.h"
#include "torlog.h"
Include dependency graph for crypto_format.c:

Functions

int crypto_write_tagged_contents_to_file (const char *fname, const char *typestring, const char *tag, const uint8_t *data, size_t datalen)
 
ssize_t crypto_read_tagged_contents_from_file (const char *fname, const char *typestring, char **tag_out, uint8_t *data_out, ssize_t data_out_len)
 
int curve25519_public_to_base64 (char *output, const curve25519_public_key_t *pkey)
 
int curve25519_public_from_base64 (curve25519_public_key_t *pkey, const char *input)
 
const char * ed25519_fmt (const ed25519_public_key_t *pkey)
 
int ed25519_public_from_base64 (ed25519_public_key_t *pkey, const char *input)
 
int ed25519_public_to_base64 (char *output, const ed25519_public_key_t *pkey)
 
int ed25519_signature_to_base64 (char *output, const ed25519_signature_t *sig)
 
int ed25519_signature_from_base64 (ed25519_signature_t *sig, const char *input)
 
int digest_to_base64 (char *d64, const char *digest)
 
int digest_from_base64 (char *digest, const char *d64)
 
int digest256_to_base64 (char *d64, const char *digest)
 
int digest256_from_base64 (char *digest, const char *d64)
 

Detailed Description

Formatting and parsing code for crypto-related data structures.

Function Documentation

◆ crypto_read_tagged_contents_from_file()

ssize_t crypto_read_tagged_contents_from_file ( const char *  fname,
const char *  typestring,
char **  tag_out,
uint8_t *  data_out,
ssize_t  data_out_len 
)

Read a tagged-data file from fname into the data_out_len-byte buffer in data_out. Check that the typestring matches typestring; store the tag into a newly allocated string in tag_out. Return -1 on failure, and the number of bytes of data on success. Preserves the errno from reading the file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ crypto_write_tagged_contents_to_file()

int crypto_write_tagged_contents_to_file ( const char *  fname,
const char *  typestring,
const char *  tag,
const uint8_t *  data,
size_t  datalen 
)

Write the datalen bytes from data to the file named fname in the tagged-data format. This format contains a 32-byte header, followed by the data itself. The header is the NUL-padded string "== <b>typestring</b>: <b>tag</b> ==". The length of typestring and tag must therefore be no more than 24.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ curve25519_public_from_base64()

int curve25519_public_from_base64 ( curve25519_public_key_t pkey,
const char *  input 
)

Try to decode a base64-encoded curve25519 public key from input into the object at pkey. Return 0 on success, -1 on failure. Accepts keys with or without a trailing "=".

Here is the call graph for this function:

◆ curve25519_public_to_base64()

int curve25519_public_to_base64 ( char *  output,
const curve25519_public_key_t pkey 
)

Encode pkey as a base64-encoded string, without trailing "=" characters, in the buffer output, which must have at least CURVE25519_BASE64_PADDED_LEN+1 bytes available. Return 0 on success, -1 on failure.

Here is the call graph for this function:

◆ digest256_from_base64()

int digest256_from_base64 ( char *  digest,
const char *  d64 
)

Given a base64 encoded, nul-terminated digest in d64 (without trailing newline or = characters), decode it and store the result in the first DIGEST256_LEN bytes at digest.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ digest256_to_base64()

int digest256_to_base64 ( char *  d64,
const char *  digest 
)

Base64 encode DIGEST256_LINE bytes from digest, remove the trailing = characters, and store the nul-terminated result in the first BASE64_DIGEST256_LEN+1 bytes of d64.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ digest_from_base64()

int digest_from_base64 ( char *  digest,
const char *  d64 
)

Given a base64 encoded, nul-terminated digest in d64 (without trailing newline or = characters), decode it and store the result in the first DIGEST_LEN bytes at digest.

Here is the call graph for this function:

◆ digest_to_base64()

int digest_to_base64 ( char *  d64,
const char *  digest 
)

Base64 encode DIGEST_LINE bytes from digest, remove the trailing = characters, and store the nul-terminated result in the first BASE64_DIGEST_LEN+1 bytes of d64.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ed25519_fmt()

const char* ed25519_fmt ( const ed25519_public_key_t pkey)

For logging convenience: Convert pkey to a statically allocated base64 string and return it. Not threadsafe. Format not meant to be computer-readable; it may change in the future. Subsequent calls invalidate previous returns.

Here is the call graph for this function:

◆ ed25519_public_from_base64()

int ed25519_public_from_base64 ( ed25519_public_key_t pkey,
const char *  input 
)

Try to decode the string input into an ed25519 public key. On success, store the value in pkey and return 0. Otherwise return -1.

Here is the call graph for this function:

◆ ed25519_public_to_base64()

int ed25519_public_to_base64 ( char *  output,
const ed25519_public_key_t pkey 
)

Encode the public key pkey into the buffer at output, which must have space for ED25519_BASE64_LEN bytes of encoded key, plus one byte for a terminating NUL. Return 0 on success, -1 on failure.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ed25519_signature_from_base64()

int ed25519_signature_from_base64 ( ed25519_signature_t sig,
const char *  input 
)

Try to decode the string input into an ed25519 signature. On success, store the value in sig and return 0. Otherwise return -1.

Here is the call graph for this function:

◆ ed25519_signature_to_base64()

int ed25519_signature_to_base64 ( char *  output,
const ed25519_signature_t sig 
)

Encode the signature sig into the buffer at output, which must have space for ED25519_SIG_BASE64_LEN bytes of encoded signature, plus one byte for a terminating NUL. Return 0 on success, -1 on failure.

Here is the call graph for this function: