SHMEM_MAGIC
0x2288882222888822
A 64bit arbitrary number which is gauranteed to be the same on high and low endian computers.
See
shmap_value_t
structshmap__value__t
compound
shencode()
group__libshare__memcrypt_1gac27f839caed815456e890576bdb71011
member
SHMEM32_MAGIC
((SHMEM_MAGIC >> 32) & 0xFFFFFFFF)
A 32bit arbitrary number which is gauranteed to be the same on high and low endian computers.
See
shmap_value_t
structshmap__value__t
compound
shencode()
group__libshare__memcrypt_1gac27f839caed815456e890576bdb71011
member
SHMEM16_MAGIC
((SHMEM_MAGIC >> 24) & 0xFFFF)
A 16bit arbitrary number which is gauranteed to be the same on high and low endian computers.
SHMEM8_MAGIC
((SHMEM_MAGIC >> 16) & 0xFF)
A single arbitrary byte (8 bits).
SHMEM_ENDIAN_MAGIC
0x12345678
A arbitrary 32bit number which is gauranteed to different on both and low endian computers.
Note
Specifies a hard-coded value that identifies a data segment.
shmap_value_t
structshmap__value__t
compound
SHMEM16_ENDIAN_MAGIC
((SHMEM_ENDIAN_MAGIC >> 16) & 0xFFFF)
A arbitrary 16bit number which is gauranteed to different on both and low endian computers.
Note
Specifies a hard-coded value that identifies a data segment.
shmap_value_t
structshmap__value__t
compound
SHMEM_PAD_SIZE
32
The byte padding size when allocating a stored value.
See
shencode()
group__libshare__memcrypt_1gac27f839caed815456e890576bdb71011
member
shmap_set()
group__libshare__memmap_1ga66656d4db4b5580fe5f26c4c5dfea490
member
SHKEY_WORDS
7
The maximum word size of the share key.
SHR224_BLOCK_SIZE
(SHR224_BLOCKS * sizeof(uint64_t))
SHR224_IPAD_MAGIC
(uint8_t)SHMEM8_MAGIC
SHR224_OPAD_MAGIC
(uint8_t)~SHMEM8_MAGIC
ashkey_blank
(( *)&_shkey_blank)structshkey__tcompoundshkey_t
Generates a blank key token.
shkey_t
structshkey__t
compound
Return Value
A statically allocated blank key token.
Note
Do not free the returned value.
shkey_is_blank
(0 == memcmp((_key), &_shkey_blank, sizeof()))structshkey__tcompoundshkey_t
Determines whether a has been initialized.
shkey_t
structshkey__t
compound
Return Value
FALSE is key is not blank, and TRUE is the key is blank.
Note
It is possible to generate keys which equal a blank key, for example a key generated from a zero-length data segment. This macro should be utilitized only when it is known that the key being compared against has a unique value.
SHMPI_MAX_SIZE
1024
Maximum number of bytes for usable MPIs.
SHMPI_MAX_BITS
( 8 * SHMPI_MAX_SIZE )
Maximum number of bits for usable MPIs.
SHMPI_ERR_FILE_IO_ERROR
-0x0002
An error occurred while reading from or writing to a file.
SHMPI_ERR_BAD_INPUT_DATA
-0x0004
Bad input parameters to function.
SHMPI_ERR_INVALID_CHARACTER
-0x0006
There is an invalid character in the digit string.
SHMPI_ERR_BUFFER_TOO_SMALL
-0x0008
The buffer is too small to write to.
SHMPI_ERR_NEGATIVE_VALUE
-0x000A
The input arguments are negative or result in illegal output.
SHMPI_ERR_DIVISION_BY_ZERO
-0x000C
The input argument for division is zero, which is not allowed.
SHMPI_ERR_NOT_ACCEPTABLE
-0x000E
The input arguments are not acceptable.
SHMPI_ERR_MALLOC_FAILED
-0x0010
Memory allocation failed.
SHALG_128BIT
(1 << 0)
A 16-byte hash.
SHALG_160BIT
(1 << 1)
A 20-byte hash.
SHALG_224BIT
(1 << 2)
A 28-byte hash.
SHALG_256BIT
(1 << 3)
A 32-byte hash.
SHALG_384BIT
(1 << 4)
A 48-byte hash.
SHALG_512BIT
(1 << 5)
A 64-byte hash.
SHALG_SHR
(1 << 8)
Share Library Algorythm.
SHALG_SHA
(1 << 9)
Secure Hash Algorythm.
SHALG_RSA
(1 << 10)
Pubkey Encryption Algorythm (circa 1977).
SHALG_ECDSA
(1 << 11)
Elliptic Curve Algorythm.
SHALG_VR
(1 << 15)
Indicates that the algorythm is 'verifiably random'.
SHALG_SHR160
(SHALG_SHR | SHALG_160BIT)
The libshare 160-bit hash algorithm.
SHALG_SHR224
(SHALG_SHR | SHALG_224BIT)
The libshare 224-bit hash algorithm.
SHALG_SHCR224
(SHALG_CRYPT | SHALG_SHR | SHALG_224BIT)
The libshare 224-bit "crypt" hash algorithm designed towards password authentication purposes.
SHALG_SHA1
(SHALG_SHA | SHALG_128BIT)
SHALG_SHA224
(SHALG_SHA | SHALG_224BIT)
SHALG_SHA256
(SHALG_SHA | SHALG_256BIT)
SHALG_SHA384
(SHALG_SHA | SHALG_384BIT)
SHALG_SHA512
(SHALG_SHA | SHALG_512BIT)
SHALG_ECDSA128R
(SHALG_ECDSA | SHALG_128BIT | SHALG_VR)
SHALG_ECDSA160R
(SHALG_ECDSA | SHALG_160BIT | SHALG_VR)
SHALG_ECDSA160K
(SHALG_ECDSA | SHALG_160BIT)
SHALG_ECDSA224R
(SHALG_ECDSA | SHALG_224BIT | SHALG_VR)
SHALG_ECDSA224K
(SHALG_ECDSA | SHALG_224BIT)
SHALG_ECDSA256R
(SHALG_ECDSA | SHALG_256BIT | SHALG_VR)
SHALG_ECDSA256K
(SHALG_ECDSA | SHALG_256BIT)
SHALG_ECDSA384R
(SHALG_ECDSA | SHALG_384BIT | SHALG_VR)
SHALG_ECDSA512R
(SHALG_ECDSA | SHALG_512BIT | SHALG_VR)
SHALG_RSA128
(SHALG_RSA | SHALG_128BIT)
SHALG_CRYPT256
(SHALG_CRYPT | SHALG_256BIT)
SHALG_CRYPT512
(SHALG_CRYPT | SHALG_512BIT)
SHALG_DEFAULT
0
An indicator to use the default available algorythm.
SHALG_SHKEY
0
A generic 224-bit key generated by the shkey() function set.
SHALG_RIPEMD160
SHALG_SHR160
A convience macro for referencing the RIPEMD160 algorythm.
SHALG
((_alg) == (_flag))
Return Value
TRUE if the alg matches the given flags
MAX_ALG_SIZE
((MAX_ALG_WORD_SIZE - 1) * sizeof(uint32_t))
shalg_size
((_a)[MAX_ALG_WORD_SIZE - 1])
SHCR224_DEFAULT_ROUNDS
SHCR224_MIN_ROUNDS
INITIAL_MAX
15
The initial number of hashmap indexes to create.
SHMETA_BIG_ENDIAN
0
Specifies that a machine has a big endian architecture.
See
SHMETA_VALUE_ENDIAN
group__libshare__memmap_1gabbd81e29e6bbee43df50a9fda916caf5
member
SHMETA_SMALL_ENDIAN
1
Specifies that a machine has a small endian architecture.
See
SHMETA_VALUE_ENDIAN
group__libshare__memmap_1gabbd81e29e6bbee43df50a9fda916caf5
member
SHMETA_VALUE_ENDIAN
(_val->magic == SHMEM_ENDIAN_MAGIC ? \
SHMETA_BIG_ENDIAN : SHMETA_SMALL_ENDIAN)
Determines whether the meta value originated from a big or small endian architecture.
Return Value
SHMETA_BIG_ENDIAN or SHMETA_SMALL_ENDIAN based on the meta value.
SHMAP_ALLOC
(1 << 0)
Indicates the underlying map value has been allocated.
SHMAP_STRING
(1 << 10)
A null-terminated string value.
SHMAP_NUMBER
(1 << 11)
A numeric value with decimal precision.
SHMAP_BINARY
(1 << 13)
A non-specific binary memory segment.
SHLOCK_SYSTEM
-9999
A lock used by the share library in order to ensure no two threads perform a system call at the same instance.
SHLK_READ_ONLY
O_RDONLY
A flag which indicates the lock applies to only 'Read' I/O access.
SHLK_WRITE_ONLY
O_WRONLY
A flag which indicates the lock applies to only 'Write' I/O access.
SHLK_IO
O_RDWR
A flag which indicates the lock applies to all I/O access.
SHLK_PRIVATE
O_EXCL
In memory this Prevents the mutex from allowing the same thread to access the lock.
For a file indicates only the originating process may remove lock.
Note
Similar to a semaphore as the lock is not based on thread conditions.
SHLK_OVERRIDE
O_TRUNC
A flag which indicates the previous lock should be over-written.
SHLK_NOWAIT
O_NONBLOCK
A flag which indicates to not wait for a lock to become available.
shlock_open_num
shlock_open(ashkey_num(_num), (_flags))
Opens a lock based on a number.
See
shlock_open()
group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49
member
shlock_open_str
shlock_open(ashkey_str(_str), (_flags))
Opens a lock based on a string.
See
shlock_open()
group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49
member
shlock_tryopen_num
shlock_tryopen(ashkey_num(_num), (_flags), (_keyp))
Opens a lock based on a number.
See
shlock_tryopen()
group__libshare__memlock_1gaeb92477a7ff8dead2095664ab39a0578
member
shlock_tryopen_str
shlock_tryopen(ashkey_str(_str), (_flags), (_keyp))
Opens a lock based on a string.
See
shlock_tryopen()
group__libshare__memlock_1gaeb92477a7ff8dead2095664ab39a0578
member
shlock_close_num
shlock_close(ashkey_num(_num), (_flags))
Closes a lock based on a number.
See
shlock_close()
group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4
member
shlock_close_str
shlock_close(ashkey_str(_str))
Closes a lock based on a string.
See
shlock_close()
group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4
member
bswap_16
((((value) & 0xff) << 8) | ((value) >> 8))
bswap_32
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
bswap_64
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
flip32
(swap32yes(dest_p, src_p, 32 / 4))
SHTREE_PERM
(1 << 10)
Do not allow nodes to be removed.
SHTREE_RECYCLE
(1 << 11)
Re-use old intermediate branch nodes that are deleted.
SHTREE_DEALLOC
(1 << 12)
De-allocate the data segments provided.
SHZ_PAGE_SIZE
1024
The size of each page.
SHZ_ALLOC_SIZE
65536
The maximum size to allocate at once for the archive.
SHZ_PAGE_INDEX
10011
A block containing hash references to archived data content.
SHZ_PAGE_ZLIB_DATA
10021
A block containing a segment of raw zlib compressed data.
SHZ_PAGE_BASE
23123
A base page which initializes the archive state.
See
shz_base_t
structshz__base__t
compound
SHZ_MAX_INDEX_SIZE
((SHZ_PAGE_SIZE - sizeof()) / sizeof(shz_idx))structshz__data__tcompoundshz_index_t
SHZ_WRITE_F
(()(_f))group__libshare__memzlib_1ga04147c4a8cbc72bbb94d3088e7872f92membershz_write_f
SHZ_READ_F
(()(_f))group__libshare__memzlib_1gac4bc78a08b4951b293b3692b1161edd5membershz_read_f
SHZ_FAST
(1 << 1)
whether to reduce the encode (compress) window in order to increase speed
SHZ_NOATTR
(1 << 2)
Flag to denote file attributes should not be applied from archive.
SHZ_TRUNC
(1 << 3)
Truncate the archive upon initialization.
SHZ_RAW
(1 << 4)
Do not encode (compress) the stored data.
SHZ_VERBOSE
(1 << 5)
Log information about individual archive operations.
SHZ_IGNORE
(1 << 6)
Skip data integrity errors.
SHZ_ALLOC
(1 << 20)
Whether the buffer is internally allocated by the shz functionality.
SHZ_FRESH
(1 << 21)
Whether to start with an empty archive.
SHZ_VERIFY
(1 << 22)
Flag to denote that a base CRC needs verified.
@0
group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba394854ff4f1518f8a047ea885d7d4f60publicSHA1_Message_Block_Size 64group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55bafb2361a9dd54ccd78a2727ca4c47f792publicSHA224_Message_Block_Size 64group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55baf163926be4ff6a506a77f737295b6884publicSHA256_Message_Block_Size 64group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba4c82bc2f6b15a4717d5cd8125ca31e03publicSHA384_Message_Block_Size 128group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55babba971af4f20bede9e0e62472e03e755publicSHA512_Message_Block_Size 128group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba082a5cabbe9ad6382a0606cd0a9c9c47publicUSHA_Max_Message_Block_Size SHA512_Message_Block_Sizegroup__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55bae6b440886f3edd40e1854e8bb5406835publicSHA1HashSize 20group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba8f590c65273a356a4703c90cc1f1584fpublicSHA224HashSize 28group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba3a8b66cf5d0bd8cc0e375a86a754ab28publicSHA256HashSize 32group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba1f2e28eb98ef458a8c54e32e9cbe3322publicSHA384HashSize 48group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba9c2b656e2a8c7b981612de8ddaf2f7bepublicSHA512HashSize 64group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55bab3907d0aaeac7086349a0c920c301145publicUSHAMaxHashSize SHA512HashSizegroup__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba3cee11b61cecb950ddad59399caab2e3publicSHA1HashSizeBits 160group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba1d000b90626950f5ceae6353d4648e59publicSHA224HashSizeBits 224group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55baf8b7a9e3bd026320a4b418bc35ba21a7publicSHA256HashSizeBits 256group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba2bf86ed4893af8bff6df06951fcd65dfpublicSHA384HashSizeBits 384group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55ba44595cd183133d2dca15294777f6b6ebpublicSHA512HashSizeBits 512group__libshare__memalg_1gga06fc87d81c62e9abb8790b6e5713c55baeb9a635b6c798bf545965b19aef992fdpublicUSHAMaxHashSizeBits SHA512HashSizeBits
typedef struct shbuf_t shbuf_t
typedef struct shkey_t shkey_t
typedef uint32_t sh160_t[5]
A 160-bit key.
typedef uint32_t shalg_t[78]
A key or signature.
typedef unsigned char shcr224_t[96]
typedef struct shpool_t shpool_t
A memory pool.
typedef struct shmap_t shmap_t
A hashmap table.
typedef struct shmap_index_t shmap_index_t
A hashmap index.
typedef unsigned int(* shmapfunc_t)(const char *key, ssize_t *klen)
Callback functions for calculating hash values.
Param
key
The key.
klen
The length of the key.
typedef struct shmap_entry_t shmap_entry_t
A hashmap entry.
typedef struct shmap_value_t shmap_value_t
Specifies a reference to the current version of a shmap hashmap entry value.
typedef shesig_t shenc_hdr_t
typedef struct shlock_t shlock_t
The share library lock structure is used primarily in order to prevent multiple threads from performing system calls at the same instance.
The lock includes both re-entrant and private access styles. The functionality can be extended in order to provide custom locks.
See
shlock_open()
group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49
member
shlock_close()
group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4
member
typedef void(* shtree_f)(shtree_t *)
typedef struct shz_map_t shz_map_t
typedef struct shz_mod_t shz_mod_t
typedef struct shz_data_t shz_data_t
typedef struct shz_t shz_t
typedef struct shz_tree_t shz_tree_t
typedef struct shz_data_t shz_index_t
typedef ssize_t(* shz_write_f)(shz_t *, shz_idx *, unsigned char *, size_t)
The bulk write function template for a module.
typedef int(* shz_read_f)(shz_t *, shz_idx, shbuf_t *)
The bulk read function template for a module.
typedef int(* shz_list_f)(shz_t *, shz_idx, char *f_path, shbuf_t *, void *p)
int shbuf_cmp
(shbuf_t *buff, shbuf_t *cmp_buff)
Return Value
TRUE or FALSE whether buffers contain identical data.
shbuf_t* shbuf_init
(void)
Initialize a memory buffer for use.
Note
A memory buffer handles automatic allocation of memory.
shbuf_t
structshbuf__t
compound
void shbuf_catstr
(shbuf_t *buf, char *data)
Inserts a string into a memory pool.
shbuf_t
structshbuf__t
compound
void shbuf_cat
(shbuf_t *buf, void *data, size_t data_len)
Inserts a binary data segment into a memory pool.
shbuf_t
structshbuf__t
compound
void shbuf_memcpy
(shbuf_t *buf, void *data, size_t data_len)
size_t shbuf_size
(shbuf_t *buf)
The current size of the data segement stored in the memory buffer.
unsigned char* shbuf_data
(shbuf_t *buf)
void shbuf_clear
(shbuf_t *buf)
Clear the contents of a libshare memory buffer.
shbuf_t
structshbuf__t
compound
void shbuf_trim
(shbuf_t *buf, size_t len)
Reduce the data size of a memory buffer.
Param
buf
The memory buffer.
len
The size of bytes to reduce by.
Note
This removes data from the beginning of the data segment.
void shbuf_truncate
(shbuf_t *buf, size_t len)
void shbuf_dealloc
(shbuf_t *buf)
void shbuf_free
(shbuf_t **buf_p)
Frees the resources utilizited by the memory buffer.
int shbuf_grow
(shbuf_t *buf, size_t data_len)
Grow the memory buffer to atleast the size specified.
Param
buf
The memory buffer.
shbuf_t
structshbuf__t
compound
data_len
The minimum byte size the memory buffer should be allocated.
shbuf_t* shbuf_file
(char *path)
Map a file into a memory buffer.
int shbuf_growmap
(shbuf_t *buf, size_t data_len)
shbuf_t* shbuf_map
(unsigned char *data, size_t data_len)
shbuf_t* ashbuf_map
(unsigned char *data, size_t data_len)
unsigned char* shbuf_unmap
(shbuf_t *buf)
size_t shbuf_pos
(shbuf_t *buff)
void shbuf_pos_set
(shbuf_t *buff, size_t pos)
void shbuf_pos_incr
(shbuf_t *buff, size_t pos)
size_t shbuf_idx
(shbuf_t *buf, unsigned char ch)
void shbuf_padd
(shbuf_t *buff, size_t len)
shkey_t* shkey_bin
(char *data, size_t data_len)
Generates a unique 192-bit key from a segment of data.
Note
Algorythm is a combination of adler32 and sha256.
shkey_t* ashkey_bin
(char *data, size_t data_len)
shkey_t* shkey_str
(char *kvalue)
Create a hashmap key reference from The string to generate into a .
shkey_t
structshkey__t
compound
kvalue
shkey_t
structshkey__t
compound
kvalue
Return Value
A referencing a kvalue
shkey_t
structshkey__t
compound
shkey_t* shkey_num
(long kvalue)
Create a hashmap key reference from a 32bit number.
shkey_t
structshkey__t
compound
The number to generate into a
kvalue
shkey_t
structshkey__t
compound
Return Value
A statically allocated version of
shkey_t* shkey_num64
(uint64_t kvalue)
Create a hashmap key reference from a 64bit number.
shkey_t
structshkey__t
compound
The number to generate into a
kvalue
shkey_t
structshkey__t
compound
Return Value
A statically allocated version of
shkey_t* shkey_uniq
(void)
Create a unique hashmap key reference.
shkey_t
structshkey__t
compound
Return Value
A containing a unique key value.
shkey_t
structshkey__t
compound
shkey_t* ashkey_uniq
(void)
uint64_t shkey_crc
(shkey_t *key)
A 64-bit numeric representation of a .
shkey_t
structshkey__t
compound
void shkey_free
(shkey_t **key_p)
shkey_t* shkey_xor
(shkey_t *key1, shkey_t *key2)
shkey_t* ashkey_xor
(shkey_t *key1, shkey_t *key2)
shkey_t* shkey_dup
(shkey_t *key)
const char* shkey_print
(shkey_t *key)
A ascii string representation of a libshare key.
Note
The string returned will be 36 characters long in a format similar to base64.
shkey_t* ashkey_str
(char *name)
Generates a from a string that does not need to be freed.
shkey_t
structshkey__t
compound
Bug
psuedo thread-safe
bug_1_bug000001
shkey_t* ashkey_num
(long num)
Generates a from a number that does not need to be freed.
shkey_t
structshkey__t
compound
Bug
psuedo thread-safe
bug_1_bug000002
int shkey_cmp
(shkey_t *key_1, shkey_t *key_2)
Compare two shkek_t key tokens.
Return Value
TRUE is keys are ientical and FALSE if not.
shkey_t* shkey_clone
(shkey_t *key)
shkey_t* shkey_cert
(shkey_t *key, uint64_t crc, shtime_t stamp)
Creates a certificate's signature key based off content attributes.
int shkey_verify
(shkey_t *sig, uint64_t crc, shkey_t *key, shtime_t stamp)
Verifies whether content attributes match a generated certificate signature key.
shkey_t* shkey_gen
(char *hex_str)
Converts a hex string into a binary key.
const char* shkey_hex
(shkey_t *key)
A string hexadecimal representation of a libshare key.
Note
The string returned will be 48 characters long.
shkey_t* shkey_hexgen
(char *hex_str)
Generate a libshare key from a 48-character long hexadecimal string.
shkey_t* shkey_shr160
(sh160_t raw)
Generate a allocated share-key from a 160bit binary segment.
shkey_t* ashkey_shr160
(sh160_t raw)
Generate a share-key on the stack from a 160bit binary segment.
Note
Do not free the return value.
void sh160_key
(shkey_t *in_key, sh160_t u160)
Obtain a 160bit binary segment from a pre-set 160-bit share-key.
void shkey_shr160_hash
(shkey_t *ret_key, unsigned char *data, size_t data_len)
Generate a SHA256+RIPEMD160 20-byte hash in the form of a share-key.
shkey_t* shkey_shr160_gen
(char *key_str)
Generate a 'u160' key from a printed key string.
char* shkey_shr160_print
(shkey_t *key)
int shkey_shr160_ver
(shkey_t *key)
int shr224
(unsigned char *data, size_t data_len, unsigned char *ret_digest)
int shr224_init
(shr224_t *ctx)
int shr224_write
(shr224_t *ctx, unsigned char *data, size_t data_len)
int shr224_result
(shr224_t *ctx, unsigned char *ret_digest)
int shr224_hmac
(unsigned char *key, size_t key_len, unsigned char *data, size_t data_len, unsigned char *ret_digest)
int shr224_hmac_init
(shr224_t *ctx, unsigned char *key, size_t key_len)
int shr224_hmac_write
(shr224_t *ctx, unsigned char *data, size_t data_len)
int shr224_hmac_result
(shr224_t *ctx, unsigned char *ret_digest)
int shr224_expand
(unsigned char *digest, unsigned char *data, size_t data_len)
int shr224_shrink
(uint64_t crc, unsigned char *data, size_t data_len, unsigned char *ret_digest)
uint64_t shr224_crc
(shr224_t *ctx)
shkey_t* ashkey_shr224
(void *data, size_t data_len)
shkey_t* shkey_shr224
(void *data, size_t data_len)
int shkey_shr224_ver
(shkey_t *key, unsigned char *data, size_t data_len)
int shr224_result_key
(shr224_t *ctx, shkey_t *key)
uint64_t shr224_result_crc
(shr224_t *ctx, shkey_t *key)
void* memxor
(void *dest, const void *src, size_t n)
int shkey_alg
(shkey_t *key)
void shkey_alg_set
(shkey_t *key, int alg)
void shmpi_init
(shmpi *X)
Initialize one MPI (make internal references valid) This just makes it ready to be set or freed, but does not define a value for the MPI.
Param
X
One MPI to initialize.
void shmpi_free
(shmpi *X)
Unallocate one MPI.
Param
X
One MPI to unallocate.
int shmpi_grow
(shmpi *X, size_t nblimbs)
Enlarge to the specified number of limbs.
Param
X
MPI to grow
nblimbs
The target number of limbs
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_shrink
(shmpi *X, size_t nblimbs)
Resize down, keeping at least the specified number of limbs.
Param
X
MPI to shrink
nblimbs
The minimum number of limbs to keep
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_copy
(shmpi *X, const shmpi *Y)
Copy the contents of Y into X.
Param
X
Destination MPI
Y
Source MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
void shmpi_swap
(shmpi *X, shmpi *Y)
Swap the contents of X and Y.
Param
X
First MPI value
Y
Second MPI value
int shmpi_safe_cond_assign
(shmpi *X, const shmpi *Y, unsigned char assign)
Safe conditional assignement X = Y if assign is 1.
Param
X
MPI to conditionally assign to
Y
Value to be assigned
assign
1: perform the assignment, 0: keep X's original value
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed,
Note
This function is equivalent to if( assign ) shmpi_copy( X, Y ); except that it avoids leaking any information about whether the assignment was done or not (the above code may leak information through branch prediction and/or memory access patterns analysis).
int shmpi_safe_cond_swap
(shmpi *X, shmpi *Y, unsigned char assign)
Safe conditional swap X <-> Y if swap is 1.
Param
X
First value
shmpi
structshmpi
compound
Y
Second value
shmpi
structshmpi
compound
assign
1: perform the swap, 0: keep X and Y's original values
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed,
Note
This function is equivalent to if( assign ) shmpi_swap( X, Y ); except that it avoids leaking any information about whether the assignment was done or not (the above code may leak information through branch prediction and/or memory access patterns analysis).
int shmpi_lset
(shmpi *X, t_sint z)
Set value from integer.
Param
X
MPI to set
z
Value to use
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_get_bit
(const shmpi *X, size_t pos)
Get a specific bit from X.
Param
X
MPI to use
pos
Zero-based index of the bit in X
Return Value
Either a 0 or a 1
int shmpi_set_bit
(shmpi *X, size_t pos, unsigned char val)
Set a bit of X to a specific value of 0 or 1.
Note
Will grow X if necessary to set a bit to 1 in a not yet existing limb. Will not grow if bit should be set to 0
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1
Param
X
MPI to use
pos
Zero-based index of the bit in X
val
The value to set the bit to (0 or 1)
size_t shmpi_lsb
(const shmpi *X)
Return the number of zero-bits before the least significant '1' bit.
Note: Thus also the zero-based index of the least significant '1' bit
size_t shmpi_msb
(const shmpi *X)
Return the number of bits up to and including the most significant '1' bit'.
Note: Thus also the one-based index of the most significant '1' bit
size_t shmpi_size
(const shmpi *X)
Return the total size in bytes.
int shmpi_read_string
(shmpi *X, int radix, const char *s)
Import from an ASCII string.
Param
X
Destination MPI
radix
Input numeric base
s
Null-terminated string buffer
Return Value
0 if successful, or a MPI_ERR_MPI_XXX error code
int shmpi_write_string
(const shmpi *X, int radix, char *s, size_t *slen)
Export into an ASCII string.
Param
X
Source MPI
radix
Output numeric base
s
String buffer
slen
String buffer size
Return Value
0 if successful, or a MPI_ERR_MPI_XXX error code. *slen is always updated to reflect the amount of data that has (or would have) been written.
Note
Call this function with *slen = 0 to obtain the minimum required buffer size in *slen.
int shmpi_read_binary
(shmpi *X, const unsigned char *buf, size_t buflen)
Import X from unsigned binary data, big endian.
Param
X
Destination MPI
buf
Input buffer
buflen
Input buffer size
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_write_binary
(const shmpi *X, unsigned char *buf, size_t buflen)
Export X into unsigned binary data, big endian.
Always fills the whole buffer, which will start with zeros if the number is smaller.
Param
X
Source MPI
buf
Output buffer
buflen
Output buffer size
Return Value
0 if successful, MPI_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough
int shmpi_shift_l
(shmpi *X, size_t count)
Left-shift: X <<= count.
Param
X
MPI to shift
count
Amount to shift
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_shift_r
(shmpi *X, size_t count)
Right-shift: X >>= count.
Param
X
MPI to shift
count
Amount to shift
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_cmp_abs
(const shmpi *X, const shmpi *Y)
Compare unsigned values.
Param
X
Left-hand MPI
Y
Right-hand MPI
Return Value
1 if |X| is greater than |Y|, -1 if |X| is lesser than |Y| or 0 if |X| is equal to |Y|
int shmpi_cmp_mpi
(const shmpi *X, const shmpi *Y)
Compare signed values.
Param
X
Left-hand MPI
Y
Right-hand MPI
Return Value
1 if X is greater than Y, -1 if X is lesser than Y or 0 if X is equal to Y
int shmpi_cmp_int
(const shmpi *X, t_sint z)
Compare signed values.
Param
X
Left-hand MPI
z
The integer value to compare to
Return Value
1 if X is greater than z, -1 if X is lesser than z or 0 if X is equal to z
int shmpi_add_abs
(shmpi *X, const shmpi *A, const shmpi *B)
Unsigned addition: X = |A| + |B|.
Param
X
Destination MPI
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_sub_abs
(shmpi *X, const shmpi *A, const shmpi *B)
Unsigned subtraction: X = |A| - |B|.
Param
X
Destination MPI
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_NEGATIVE_VALUE if B is greater than A
int shmpi_add_mpi
(shmpi *X, const shmpi *A, const shmpi *B)
Signed addition: X = A + B.
Param
X
Destination MPI
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_sub_mpi
(shmpi *X, const shmpi *A, const shmpi *B)
Signed subtraction: X = A - B.
Param
X
Destination MPI
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_add_int
(shmpi *X, const shmpi *A, t_sint b)
Signed addition: X = A + b.
Param
X
Destination MPI
A
Left-hand MPI
b
The integer value to add
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_sub_int
(shmpi *X, const shmpi *A, t_sint b)
Signed subtraction: X = A - b.
Param
X
Destination MPI
A
Left-hand MPI
b
The integer value to subtract
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_mul_mpi
(shmpi *X, const shmpi *A, const shmpi *B)
Baseline multiplication: X = A * B.
Param
X
Destination MPI
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_mul_int
(shmpi *X, const shmpi *A, t_sint b)
Baseline multiplication: X = A * b Note: despite the functon signature, b is treated as a t_uint.
Negative values of b are treated as large positive values.
Param
X
Destination MPI
A
Left-hand MPI
b
The integer value to multiply with
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_div_mpi
(shmpi *Q, shmpi *R, const shmpi *A, const shmpi *B)
Division by : A = Q * B + R.
shmpi
structshmpi
compound
Param
Q
Destination MPI for the quotient
R
Destination MPI for the rest value
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_DIVISION_BY_ZERO if B == 0
Note
Either Q or R can be NULL.
int shmpi_div_int
(shmpi *Q, shmpi *R, const shmpi *A, t_sint b)
Division by int: A = Q * b + R.
Param
Q
Destination MPI for the quotient
R
Destination MPI for the rest value
A
Left-hand MPI
b
Integer to divide by
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_DIVISION_BY_ZERO if b == 0
Note
Either Q or R can be NULL.
int shmpi_mod_mpi
(shmpi *R, const shmpi *A, const shmpi *B)
Modulo: R = A mod B.
Param
R
Destination MPI for the rest value
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_DIVISION_BY_ZERO if B == 0, MPI_ERR_MPI_NEGATIVE_VALUE if B < 0
int shmpi_mod_int
(t_uint *r, const shmpi *A, t_sint b)
Modulo: r = A mod b.
Param
r
Destination t_uint
A
Left-hand MPI
b
Integer to divide by
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_DIVISION_BY_ZERO if b == 0, MPI_ERR_MPI_NEGATIVE_VALUE if b < 0
int shmpi_exp_mod
(shmpi *X, const shmpi *A, const shmpi *E, const shmpi *N, shmpi *_RR)
Sliding-window exponentiation: X = A^E mod N.
Param
X
Destination MPI
A
Left-hand MPI
E
Exponent MPI
N
Modular MPI
_RR
Speed-up MPI used for recalculations
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_BAD_INPUT_DATA if N is negative or even or if E is negative
Note
_RR is used to avoid re-computing R*R mod N across multiple calls, which speeds up things a bit. It can be set to NULL if the extra performance is unneeded.
int shmpi_fill_random
(shmpi *X, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Fill an MPI X with size bytes of random.
Param
X
Destination MPI
size
Size in bytes
f_rng
RNG function
p_rng
RNG parameter
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_gcd
(shmpi *G, const shmpi *A, const shmpi *B)
Greatest common divisor: G = gcd(A, B).
Param
G
Destination MPI
A
Left-hand MPI
B
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed
int shmpi_inv_mod
(shmpi *X, const shmpi *A, const shmpi *N)
Modular inverse: X = A^-1 mod N.
Param
X
Destination MPI
A
Left-hand MPI
N
Right-hand MPI
Return Value
0 if successful, MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_BAD_INPUT_DATA if N is negative or nil MPI_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N
int shmpi_is_prime
(shmpi *X, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Miller-Rabin primality test.
Param
X
MPI to check
f_rng
RNG function
p_rng
RNG parameter
Return Value
0 if successful (probably prime), MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_NOT_ACCEPTABLE if X is not prime
int shmpi_gen_prime
(shmpi *X, size_t nbits, int dh_flag, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Prime number generation.
Param
X
Destination MPI
nbits
Required size of X in bits ( 3 <= nbits <= MPI_MPI_MAX_BITS )
dh_flag
If 1, then (X-1)/2 will be prime too
f_rng
RNG function
p_rng
RNG parameter
Return Value
0 if successful (probably prime), MPI_ERR_MPI_MALLOC_FAILED if memory allocation failed, MPI_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
size_t shmpi_bitlen
(const shmpi *X)
Return Value
The the number of bits.
char* shhex_str
(unsigned char *data, size_t data_len)
void shhex_bin
(char *hex_str, unsigned char *data, size_t data_max)
const char* shalg_str
(int alg)
Print the algorythm parameters.
int shalg_fmt
(char *label)
char* shalg_fmt_str
(int fmt)
char* shalg_encode
(int fmt, unsigned char *data, size_t data_len)
Print a binary segment in the format specified.
int shalg_decode
(int fmt, char *in_data, unsigned char *data, size_t *data_len_p)
int shalg_priv_rand
(int alg, shalg_t ret_key)
Generate a random 512-bit private signature.
int shalg_priv
(int alg, shalg_t ret_key, unsigned char *data, size_t data_len)
Generate a private signature from a 'secret' binary segment.
char* shalg_print
(int fmt, shalg_t key)
Print a key or signature in the format specified.
int shalg_gen
(int fmt, char *in_data, shalg_t ret_key)
int shalg_pub
(int alg, shalg_t priv_key, shalg_t ret_key)
Generate a public key from a private key.
int shalg_sign
(int alg, shalg_t priv_key, shalg_t ret_sig, unsigned char *data, size_t data_len)
int shalg_ver
(int alg, shalg_t pub_key, shalg_t sig_key, unsigned char *data, size_t data_len)
int shalg_mode_str
(char *mode_str)
int shalg_cmp
(shalg_t alg_a, shalg_t alg_b)
int shsha_hex
(int alg, unsigned char *ret_digest, unsigned char *data, size_t data_len)
Digest a single message into hexadecimal format.
int shsha
(int alg, unsigned char *ret_bin, unsigned char *data, size_t data_len)
Digest a single message into binary format.
size_t shsha_size
(int alg)
The byte size of the resulting SHA digest hash.
int shsha_init
(sh_sha_t *ctx, int alg)
int shsha_write
(sh_sha_t *ctx, unsigned char *data, size_t data_len)
int shsha_result
(sh_sha_t *ctx, unsigned char *ret_bin)
int shhmac
(int alg, unsigned char *key, size_t key_len, const unsigned char *message_array, int length, unsigned char *digest)
This function will compute an HMAC message digest.
Param
alg
One of SHALG_SHA1, SHALG_SHA224, SHALG_SHA256, SHALG_SHA384, or SHALG_SHA512.
message_array
An array of octets representing the message.
length
The length of the message in message_array.
key
The secret shared key.
key_len
The length of the secret shared key.
digest
Where the digest is to be returned.
Return Value
A libshare error code.
Note
The length of the digest is determined by the value of whichSha.
int shhmac_init
(sh_hmac_t *context, int alg, unsigned char *key, int key_len)
This function will initialize the hmacContext in preparation for computing a new HMAC message digest.
Param
context
The context to reset.
alg
One of SHALG_SHA1, SHALG_SHA224, SHALG_SHA256, SHALG_SHA384, or SHALG_SHA512.
key
The secret shared key.
key_len
The length of the secret shared key.
Return Value
A libshare error code.
int shhmac_write
(sh_hmac_t *context, const unsigned char *text, int text_len)
Accepts an array of octets as the next portion of the message.
Param
context
The HMAC context to update.
text
An array of octets representing the next portion of the message.
text_len
The length of the message in text.
Return Value
A libshare error code.
Note
This function may be called multiple times.
int shhmac_result
(sh_hmac_t *context, uint8_t *digest)
This function will return the N-byte message digest into the Message_Digest array provided by the caller.
Param
context
The context to use to calculate the HMAC hash.
digest
Where the digest is returned.
Return Value
A libshare error code.
Note
The length of the hash is determined by the value of alg that was passed to hmacReset().
int shhkdf
(int alg, unsigned char *salt, int salt_len, unsigned char *ikm, int ikm_len, unsigned char *info, int info_len, uint8_t *okm, int okm_len)
The HKDF algorithm (HMAC-based Extract-and-Expand Key Derivation Function, RFC 5869), expressed in terms of the various SHA algorithms.
Param
alg
One of SHA1, SHA224, SHA256, SHA384, SHA512
salt
The optional salt value (a non-secret random value); if not provided (salt == NULL), it is set internally to a string of HashLen(whichSha) zeros.
salt_len
The length of the salt value. (Ignored if salt == NULL.)
ikm
Input keying material.
ikm_len
The length of the input keying material.
info
The optional context and application specific information. If info == NULL or a zero-length string, it is ignored.
info_len
The length of the optional context and application specific information. (Ignored if info == NULL.)
okm
Where the HKDF is to be stored.
okm_len
The length of the buffer to hold okm. okm_len must be <= 255 * shsha_size(alg) * 2
Return Value
A libshare error code.
int shhkdf_extract
(int alg, unsigned char *salt, int salt_len, unsigned char *ikm, int ikm_len, uint8_t *prk)
This function will perform HKDF extraction.
Param
alg
One of SHALG_SHA1, SHALG_SHA224, SHALG_SHA256, SHALG_SHA384, SHALG_SHA512
salt
The optional salt value (a non-secret random value); if not provided (salt == NULL), it is set internally to a string of HashLen(whichSha) zeros.
salt_len
The length of the salt value. (Ignored if salt == NULL.)
ikm[
] Input keying material.
ikm_len
The length of the input keying material.
prk
Array where the HKDF extraction is to be stored. Must be larger than shsha_size(alg)
Return Value
A libshare error code.
int shhkdf_expand
(int alg, uint8_t *prk, int prk_len, unsigned char *info, int info_len, uint8_t *okm, int okm_len)
This function will perform HKDF expansion.
Param
whichSha
One of SHA1, SHA224, SHA256, SHA384, SHA512
prk
The pseudo-random key to be expanded; either obtained directly from a cryptographically strong, uniformly distributed pseudo-random number generator, or as the output from hkdfExtract().
prk_len
The length of the pseudo-random key in prk; should at least be equal to shsha_size(alg).
info
The optional context and application specific information. If info == NULL or a zero-length string, it is ignored.
info_len
The length of the optional context and application specific information. (Ignored if info == NULL.)
okm
Where the HKDF is to be stored.
okm_len
The length of the buffer to hold okm. The okm_len must be <= 255 * shsha_size(alg) * 2.
Return Value
A libshare error code.
int shhkdf_init
(sh_hkdf_t *context, int alg, unsigned char *salt, int salt_len)
This function will initialize the hkdfContext in preparation for key derivation using the modular HKDF interface for arbitrary length inputs.
Param
context
The context to reset.
alg
One of SHALG_SHA1, SHALG_SHA224, SHALG_SHA256, SHALG_SHA384, or SHALG_SHA512.
salt
The optional salt value (a non-secret random value); if not provided (salt == NULL), it is set internally to a string of HashLen(whichSha) zeros.
salt_len
The length of the salt value. (Ignored if salt == NULL.)
Return Value
A libshare error code.
int shhkdf_write
(sh_hkdf_t *context, unsigned char *ikm, int ikm_len)
This function accepts an array of octets as the next portion of the input keying material.
Param
context
The HKDF context to update.
ikm
An array of octets representing the next portion of the input keying material.
ikm_len
The length of ikm.
Return Value
A libshare error code.
Note
This function may be called multiple times.
int shhkdf_result
(sh_hkdf_t *context, uint8_t *prk, unsigned char *info, int info_len, uint8_t *okm, int okm_len)
This function will finish the HKDF extraction and perform the final HKDF expansion.
Param
context
The HKDF context to use to calculate the HKDF hash.
prk
NULL or a location to store the HKDF extraction. The buffer must be larger than shsha_size(whichSha).
info
NULL or context and application specific information.
info_len
The length of the optional context and application specific
okm
Where the HKDF is to be stored.
okm_len
The length of the buffer to hold okm. The okm_len must be <= 255 * shsha_size(whichSha) * 2
Return Value
A libshare error code.
int sh_sha1_init
(sh_sha_t *sha)
This function will initialize the in preparation for computing a new SHA1 message digest.
sh_sha1_t
structsh__sha1__t
compound
Param
context
The context to reset [in/out]
Return Value
A share error code.
int sh_sha1_write
(sh_sha_t *sha, const uint8_t *message_array, unsigned length)
This function accepts an array of octets as the next portion of the message.
Param
context
The SHA context to update. [in/out]
message_array
An array of octets representing the next portion of the message.
length
The length of the message in message_array. [in]
Return Value
A libshare error code.
int sh_sha1_result
(sh_sha_t *sha, uint8_t *Message_Digest)
This function will return the 160-bit message digest into the Message_Digest array provided by the caller.
Param
context
The context to use to calculate the SHA-1 hash.
Message_Digest
Where the digest is returned.
Return Value
A libshare error code.
Note
The first octet of hash is stored in the element with index 0, the last octet of hash in the element with index 19.
void sh_sha224
(const unsigned char *message, unsigned int len, unsigned char *digest)
int sh_sha256_init
(sh_sha_t *sha)
This function will initialize the in preparation for computing a new SHA256 message digest.
sh_sha256_t
structsh__sha256__t
compound
Param
context
The context to reset.
Return Value
A libshare error code.
int sh_sha256_write
(sh_sha_t *sha, const uint8_t *message_array, unsigned int length)
This function accepts an array of octets as the next portion of the message.
Param
context
The SHA context to update.
message_array
An array of octets representing the next portion of the message.
length
The length of the message in message_array.
Return Value
A libshare error code.
int sh_sha256_result
(sh_sha_t *sha, uint8_t *Message_Digest)
This function will return the 256-bit message digest into the Message_Digest array provided by the caller.
Param
context
The context to use to calculate the SHA hash.
Message_Digest
Where the digest is returned.
Return Value
A libshare error code.
Note
The first octet of hash is stored in the element with index 0. The last octet of hash in the element with index 31.
void sh_sha256
(const unsigned char *message, unsigned int len, unsigned char *digest)
int sh_sha512_init
(sh_sha_t *sha)
This function will initialize the in preparation for computing a new SHA512 message digest.
sh_sha512_t
structsh__sha512__t
compound
Param
context
The context to reset.
Return Value
A libshare error code.
int sh_sha512_write
(sh_sha_t *sha, const uint8_t *message_array, unsigned int length)
This function accepts an array of octets as the next portion of the message.
Param
context
The SHA context to update.
message_array
An array of octets representing the next portion of the message.
length
The length of the message in message_array.
Return Value
A libshare error code.
int sh_sha512_result
(sh_sha_t *sha, uint8_t *Message_Digest)
This function will return the 512-bit message digest into the Message_Digest array provided by the caller.
Param
context
The context to use to calculate the SHA hash.
Message_Digest
Where the digest is returned.
Return Value
A libshare error code.
Note
The first octet of hash is stored in the element with index 0, * the last octet of hash in the element with index 63.
void sh_sha512
(const unsigned char *message, unsigned int len, unsigned char *digest)
char* shdigest
(void *data, int32_t len)
void sh_ripemd160
(unsigned char *data, size_t data_len, sh160_t digest)
Generate a RIPEMD160 20-byte hash from a binary segment.
uint32_t shsha_2fa
(char *secret_str)
Param
secret_str
A 16 character "base 32" string.
Return Value
A pin that will invalidate after aproximately one minute.
int shsha_2fa_verify
(char *secret_str, uint32_t pin)
Param
secret_str
A 16 character "base 32" string.
Return Value
0 on success and SHERR_ACCESS when pin is invalid.
char* shsha_2fa_secret
(void)
Generate a random secret key usable for 2fa purposes.
Return Value
A 16-character string in base-32 format.
uint32_t shsha_2fa_bin
(int alg, unsigned char *secret, size_t secret_len, int freq)
int shsha_2fa_bin_verify
(int alg, unsigned char *secret, size_t secret_len, int freq, uint32_t pin)
void shsha_2fa_secret_bin
(unsigned char *secret, size_t secret_len)
char* shcrypt
(const char *passwd, const char *salt)
char* shcrypt_sha256
(const char *key, const char *salt)
char* shcrypt_sha512
(const char *key, const char *salt)
void shcrypt_b64_encode
(char *ret_str, unsigned char *data, size_t data_len)
void shcrypt_b64_decode
(char *str, unsigned char *data, size_t *data_len_p)
shkey_t* shecdsa_key
(char *hex_str)
shkey_t* shecdsa_key_priv
(char *hex_seed)
shkey_t* shecdsa_key_pub
(shkey_t *priv_key)
const char* shecdsa_pub
(const char *hex_str)
int shecdsa_sign
(shkey_t *priv_key, char *sig_r, char *sig_s, unsigned char *data, size_t data_len)
int shecdsa_verify
(shkey_t *pub_key, char *str_r, char *str_s, unsigned char *data, size_t data_len)
char* shecdsa_hd_seed
(char *seed_hex, char *chain)
Generate a private key from the given seed context.
Param
seed_hex
A seed for the private key in hexadecimal format.
Return Value
A private key (32 bytes) in hexadecimal string.
char* shecdsa_hd_pubkey
(char *pubkey, char *chain, uint32_t idx)
Param
pubkey
The parent pubkey (65 bytes) in hexadecimal format.
chain
The parent chain (32 bytes) in hexadecimal format. This value is over-written with the new chain sequence.
idx
The sequence number in the derived set.
Return Value
A hexadecimal public key (65 bytes) in hexadecimal format.
char* shecdsa_hd_privkey
(char *secret, char *chain, uint32_t idx)
Param
pubkey
The parent pubkey (65 bytes) in hexadecimal format.
chain
The parent chain (32 bytes) in hexadecimal format. This value is over-written with the new chain sequence.
seed
The parent's secret key (32 bytes) in hexadecimal format.
idx
The sequence number in the derived set.
Return Value
A hexadecimal private key (32 bytes) in hexadecimal format.
char* shecdsa_hd_par_pub
(char *p_secret, char *p_chain, uint32_t idx)
char* shecdsa_hd_recover_pub
(char *secret)
int shecdsa_hd_sign
(char *privkey_hex, char *sig_r, char *sig_s, char *hash_hex)
int shecdsa_hd_verify
(char *pubkey_hex, char *str_r, char *str_s, char *hash_hex)
shec_t* shec_init
(int alg)
void shec_free
(shec_t **ec_p)
char* shec_priv
(shec_t *ec)
char* shec_priv_gen
(shec_t *ec, unsigned char *data, size_t data_len)
void shec_priv_set
(shec_t *ec, char *hex_priv)
char* shec_priv_rand
(shec_t *ec)
char* shec_pub
(shec_t *ec)
char* shec_pub_gen
(shec_t *ec)
int shec_sign
(shec_t *ec, unsigned char *data, size_t data_len)
int shec_signstr
(shec_t *ec, char *data)
int shec_signnull
(shec_t *ec)
int shec_ver
(shec_t *ec, unsigned char *data, size_t data_len)
int shec_verstr
(shec_t *ec, char *data)
int shec_vernull
(shec_t *ec)
shkey_t* shec_priv_key
(shec_t *ec)
int shec_priv_key_set
(shec_t *ec, shkey_t *key)
shkey_t* shec_pub_key
(shec_t *ec)
int shec_pub_key_set
(shec_t *ec, shkey_t *key)
int shec_pub_set
(shec_t *ec, char *hex_pub)
int shec_sig_set
(shec_t *ec, char *hex_sig)
int shcr224_verify
(char *salt, char *sig, char *data)
int shcr224_bin_verify
(unsigned char salt_key[28], shcr224_t sig, unsigned int rounds, unsigned char *data, size_t data_len)
int shcr224
(char *salt, char *data, char *ret_str)
int shcr224_bin
(unsigned char salt_key[28], shcr224_t ret_key, unsigned int rounds, unsigned char *data, size_t data_len)
Generate a signature, from the salt provided, that can be used in order to authenticate a password.
char* shcr224_salt
(unsigned int rounds)
int shcr224_salt_bin
(unsigned char ret_key[28])
Generate a random salt.
char* shcr224_salt_gen
(unsigned int rounds, unsigned char *data, size_t data_len)
int shcr224_salt_bin_gen
(unsigned char ret_key[28], unsigned char *data, size_t data_len)
uint32_t shcsum_crc32
(uint32_t crc, unsigned char *buf, size_t len)
uint32_t shcsum_crc32_combine
(uint32_t crc1, uint32_t crc2, size_t len2)
uint32_t shcsum_adler32
(uint32_t adler, unsigned char *buf, size_t len)
uint32_t shcsum_adler32_combine
(uint32_t adler1, uint32_t adler2, size_t len2)
shpool_t* shpool_init
(void)
Initializes a new memory pool instance.
Return Value
A memory pool of memory buffers.
shpool_t
structshpool__t
compound
shbuf_t
structshbuf__t
compound
size_t shpool_size
(shpool_t *pool)
Calculates the number of avaiable memory buffer contained in the memory pool.
shbuf_t
structshbuf__t
compound
shpool_t
structshpool__t
compound
See
shpool_get_index()
group__libshare__mempool_1ga5e0a3279f39237d245ac888ab7af2be4
member
void shpool_grow
(shpool_t *pool)
Increases the size of the memory pool.
Bug
smaller incremental reallocs have been known to fail in glibc
bug_1_bug000003
shbuf_t* shpool_get
(shpool_t *pool, unsigned int *idx_p)
Get's the next available memory buffer from a pool.
Param
idx_p
A reference that is filled with the retained pool index of the buffer.
shbuf_t* shpool_get_index
(shpool_t *pool, int index)
Get's a specific memory buffer by index number.
shbuf_t
structshbuf__t
compound
Param
index
The index number of the memory buffer.
Return Value
The memory buffer associated with the index or NULL if none exist.
shbuf_t
structshbuf__t
compound
void shpool_put
(shpool_t *pool, shbuf_t *buff)
Put's a memory buffer into a pool.
void shpool_free
(shpool_t **pool_p)
Free's the resources associated with a memory pool.
Param
pool_p
A reference to an allocated pool_t memory pool.
shmap_t* shmap_init
(void)
Create an instance of a meta definition hashmap.
Return Value
A meta definition hashmap.
shmap_t
structshmap__t
compound
void shmap_free
(shmap_t **meta_p)
Free an instance of a meta definition hashmap.
Param
meta_p
A reference to the meta definition hashmap to be free'd.
void shmap_set
(shmap_t *ht, shkey_t *key, const void *val)
Set a key to a particular allocated value in a map.
Param
ht
The meta definition hashmap to retrieve from.
sh_k
The key of the meta definition value.
val
The allocated value.
Note
Do not free the value passed in.
void shmap_set_str
(shmap_t *h, shkey_t *key, char *value)
Set a meta definition to a string value.
Param
h
The meta definition hash map.
name
A string name identifying the meta definition.
value
A string value to be assigned.
Note
An allocated copy of the string value is stored.
void shmap_set_astr
(shmap_t *h, shkey_t *key, char *value)
Set a map key to an allocated copy of a string value.
void shmap_unset_str
(shmap_t *h, shkey_t *name)
Unset a string value from a meta definition.
void shmap_set_void
(shmap_t *ht, shkey_t *key, void *data, size_t data_len)
Set an object value in a meta definition hash map.
Param
h
The meta definition hash map.
name
The name of the meta definition.
data
The binary data to assign.
data_len
The size of the bindary data.
char* shmap_get_str
(shmap_t *h, shkey_t *key)
Get a string meta from a meta definition.
Return Value
A string reference to the hashmap value.
void* shmap_get_void
(shmap_t *h, shkey_t *key)
Obtain a non-specific binary data segment from a meta definition hash map.
Param
h
The meta definition hash map.
name
The name of the meta definition.
void* shmap_get
(shmap_t *ht, shkey_t *key)
Get a meta definition value.
Param
ht
The meta definition hashmap to retrieve from.
sh_k
The key of the meta definition value.
Return Value
A containing the hashmap value.
shmap_value_t
structshmap__value__t
compound
void shmap_print
(shmap_t *h, shbuf_t *ret_buff)
Prints out a JSON representation of a meta definition hashmap.
Note
The text buffer must be allocated by first.
shbuf_init()
group__libshare__membuf_1gafac914ba170c0f2a9bc8c2add3a63a41
member
Param
h
The meta map to print.
ret_buff
The text buffer to return the JSON string representation.
void shmap_load
(shmap_t *ht, shbuf_t *buff)
Loads data dumped by .
shmap_print()
group__libshare__memmap_1ga99be5185d0537a6c2f9fbcb0ca9cc83c
member
unsigned int shmap_count
(shmap_t *ht)
void shmap_set_ptr
(shmap_t *ht, shkey_t *key, void *ptr)
void* shmap_get_ptr
(shmap_t *h, shkey_t *key)
void** shmap_get_ptr_list
(shmap_t *h)
void shmap_set_abin
(shmap_t *ht, shkey_t *key, void *data, size_t data_len)
void shmap_set_bin
(shmap_t *ht, shkey_t *key, void *data, size_t data_len)
void shmap_unset
(shmap_t *h, shkey_t *name)
void shmap_self
(shmap_index_t *hi, shkey_t **key_p, void **val_p, ssize_t *len_p, int *flag_p)
int shmap_set_ent
(shmap_t *ht, shkey_t *key, int map_flag, void *val, ssize_t val_size)
void shbuf_append
(shbuf_t *from_buff, shbuf_t *to_buff)
shbuf_t* shbuf_clone
(shbuf_t *buff)
int shbuf_sprintf
(shbuf_t *buff, char *fmt,...)
Return Value
the number of characters appended to the memory buffer.
Note
passes arguments through vsnprintf().
int ashencode
(char *data, size_t *data_len_p, shkey_t *key)
Encrypt a data segment without allocating additional memory.
Param
data
- A segment of data. - The length of the data segment.
key
- Pointer to a libshare token key.
shkey_t
structshkey__t
compound
Return Value
A zero on success and negative one (-1) when the string is already encrypted with the same key.
Note
Fills with encrypted data and with the size of the new data array
data
len
data size must be equal to or larger than ((len + 7) / 8) * 8 + 8 + 4 TEA encrypts in 8 byte blocks, so it must include enough space to hold the entire data to pad out to an 8 byte boundary, plus another 8 bytes at the end to give the length to the decrypt algorithm, plus another 4 bytes to signify that it has been encrypted.
You must use the same key passed into this function in order to decrypt the segment.
Bug
The data segment must be allocated 20 bytes larger than data_len. If possible this should return the same data length even if up to 16 bytes of the segment suffix is not encrypted.
Both parameters will be modified.
Specifying a different key will not prevent the data segment from being re-encrypted. The magic number should be used instead.
SHMEM_MAGIC
group__libshare__mem_1gafab60f793071e84e749e90828483f44c
member
bug_1_bug000004
int shencode
(char *data, size_t data_len, unsigned char **data_p, size_t *data_len_p, shkey_t *key)
Encrypts byte array data of length len with key key using TEA.
Param
data
- A segment of data. - The length of the data segment.
key
- Pointer to a libshare token key.
shkey_t
structshkey__t
compound
Return Value
A zero on success and negative one (-1) when the string is already encrypted with the same key.
Note
Fills with encrypted data and with the size of the new data array
data
len
data size must be equal to or larger than ((len + 7) / 8) * 8 + 8 + 4 TEA encrypts in 8 byte blocks, so it must include enough space to hold the entire data to pad out to an 8 byte boundary, plus another 8 bytes at the end to give the length to the decrypt algorithm, plus another 4 bytes to signify that it has been encrypted.
Bug
The data segment must be allocated 20 bytes larger than data_len. If possible this should return the same data length even if up to 16 bytes of the segment suffix is not encrypted.
Both parameters will be modified.
Specifying a different key will not prevent the data segment from being re-encrypted. The magic number should be used instead.
SHMEM_MAGIC
group__libshare__mem_1gafab60f793071e84e749e90828483f44c
member
bug_1_bug000005
shkey_t* shencode_str
(char *data)
See
shdecode_str()
group__libshare__memcrypt_1ga1e3e85d775242a8f25ff07ee451ec69a
member
int ashdecode
(uint8_t *data, size_t *data_len_p, shkey_t *key)
Decrypt a data segment without allocating additional memory.
Param
data
- pointer to 8 bit data array to be decrypted - SEE NOTES
len
- length of array
key
- Pointer to four integer array (16 bytes) holding TEA key
Return Value
A zero on success and negative one (-1) when the string is not encrypted.
Note
Modifies data and len
Fills data with decrypted data and len with the size of the new data
Bug
Using magic numbers in encrypt and decrypt routines - use defines instead - Kyle
If the 64 bit encoding functions aren't used outside this module, their prototypes should be in the code, not header - Simon
Add sanity checking to input - Rob
Require that input len is a multiple of 8 bytes - making a requirement we can't enforce or check is a recipe for corruption - Rob
bug_1_bug000006
int shdecode
(uint8_t *data, uint32_t data_len, char **data_p, size_t *data_len_p, shkey_t *key)
Decrypts byte array data of length len with a key token.
Param
data
pointer to 8 bit data array to be decrypted
len
length of array
data_p
A reference to the decrypted data segment.
data_len_p
The length of the decrypted data segment.
key
- Pointer to four integer array (16 bytes).
Return Value
A zero on success and negative one (-1) when the string is not encrypted.
Note
Modifies data and len
Bug
Using magic numbers in encrypt and decrypt routines - use defines instead - Kyle
If the 64 bit encoding functions aren't used outside this module, their prototypes should be in the code, not header - Simon
Add sanity checking to input - Rob
Require that input len is a multiple of 8 bytes - making a requirement we can't enforce or check is a recipe for corruption - Rob
bug_1_bug000007
int shdecode_str
(char *data, shkey_t *key)
Decrypt a string into it's original format using an assigned key.
Param
key
The key returned by
shencode_str()
group__libshare__memcrypt_1ga43c66c37375ea22cdd2352ef3a87365d
member
Return Value
A zero on success and negative one (-1) when the string is not encrypted.
int shencode_b64
(unsigned char *data, size_t data_len, char **out_p, shkey_t *key)
int shdecode_b64
(char *in_data, unsigned char **data_p, size_t *data_len_p, shkey_t *key)
int shencrypt
(int alg, shbuf_t *out_buff, unsigned char *data, size_t data_len, unsigned char *key, size_t key_len)
int shdecrypt
(shbuf_t *out_buff, unsigned char *data, size_t data_len, unsigned char *key, size_t key_len)
int shdecrypt_verify
(unsigned char *data, size_t data_len)
int shencrypt_derive
(shesig_t *cert, shalg_t pub, shbuf_t *buff, unsigned char *key_data, size_t key_len)
int shdecrypt_derive_verify
(shesig_t *cert, shalg_t pub)
shlock_t* shlock_open
(shkey_t *key, int flags)
Create a new lock on a mutex waiting if needed.
Param
num
A positive number identifying the lock.
flags
A set of modifiers to configure the lock. (SHLK_XXX)
Note
The libshare uses negative numbers for internal locks.
See
SHLOCK_SYSTEM
group__libshare__memlock_1gaf99dc958d5d8980511586e0c5a41c56e
member
SHLK_PRIVATE
group__libshare__memlock_1ga1115629744ded6de6f3c5d2c51650b7a
member
Bug
flags should be stored in instead of a paramter
shkey_t
structshkey__t
compound
bug_1_bug000008
int shlock_tryopen
(shkey_t *key, int flags, shlock_t **lock_p)
Create a new lock on a mutex unless one has already been created.
Param
num
A positive number identifying the lock.
flags
A set of modifiers to configure the lock. (SHLK_XXX)
Note
The libshare uses negative numbers for internal locks.
Return Value
A 0 on success, a 1 when the mutex is already locked, and a -1 on error.
See
SHLOCK_SYSTEM
group__libshare__memlock_1gaf99dc958d5d8980511586e0c5a41c56e
member
SHLK_PRIVATE
group__libshare__memlock_1ga1115629744ded6de6f3c5d2c51650b7a
member
int shlock_close
(shkey_t *key)
Unlock a mutex.
(static)
(inline)
static uint32_t swab32
(uint32_t v)
(static)
(inline)
static void swap32yes
(void *out, const void *in, size_t sz)
void shscrypt_peer
(scrypt_peer *peer, char *nonce1, double diff)
int shscrypt
(scrypt_work *work, int step)
int shscrypt_verify
(scrypt_work *work)
void shscrypt_peer_gen
(scrypt_peer *peer, double diff)
double shscrypt_hash_diff
(scrypt_work *work)
void shscrypt_work
(scrypt_peer *peer, scrypt_work *work, char **merkle_list, char *prev_hash, char *coinbase1, char *coinbase2, char *nbit, char *ntime)
void shscrypt_swap256
(void *dest_p, const void *src_p)
void sh_calc_midstate
(struct scrypt_work *work)
void shtree_data_set
(shtree_t *node, void *data)
Set a data segment for a tree node.
void* shtree_data_get
(shtree_t *node)
Get a data segment from a tree node.
shtree_t* shtree_new
(shtree_t *tree, void *data)
shtree_t* shtree_init
(int flags)
void shtree_free_node
(shtree_t *node)
void shtree_remove_branch
(shtree_t *node)
shtree_t* shtree_left_new
(shtree_t *tree, void *data)
shtree_t* shtree_right_new
(shtree_t *tree, void *data)
shtree_t* shtree_right
(shtree_t *tree)
shtree_t* shtree_left
(shtree_t *tree)
int shtree_leaf
(shtree_t *tree)
shtree_t* shtree_root
(shtree_t *node)
shtree_t* shtree_parent
(shtree_t *node)
int shtree_flags
(shtree_t *node)
int shtree_root_flags
(shtree_t *node)
void shtree_traverse_pre
(shtree_t *node, shtree_f proc)
void shtree_traverse_in
(shtree_t *node, shtree_f proc)
void shtree_traverse_post
(shtree_t *node, shtree_f proc)
void shtree_traverse
(shtree_t *node, int order, shtree_f proc)
void shtree_free
(shtree_t **tree_p)
int shzenc
(shbuf_t *buff, void *data, size_t data_len)
Compress data into a data buffer.
Param
buff
The data buffer to store the compressed data.
data
The data segment to compress.
int shzdec
(shbuf_t *buff, unsigned char *data, size_t data_len)
Decompress a data segment into a data buffer.
Param
buff
The data buffer to store the decompressed data.
data
The data segment to decompress.
shz_t* shz_init
(shbuf_t *buff, int flags)
void shz_free
(shz_t **z_p)
shz_t* shz_fopen
(const char *path, int flags)
int shz_extract
(shz_t *z, char *fspec)
Extract files from the an archive to the current working directory.
Param
z
The SHZ archive.
fspec
NULL to omit filter or a wild-card filename specification.
Note
Specify a literal filename in the fspec to extract a single file.
int shz_list
(shz_t *z, char *rel_path, char *fspec, shz_list_f op, void *p)
Iterate through all files, filtering by file-spec, to call a supplied procedure.
Param
z
The SHZ archive.
rel_path
An absolute path to extract file(s) to.
fspec
NULL to omit filter or a wild-card filename specification.
op
The procedure to call for each file listed.
Note
Specify a literal filename in the fspec to extract a single file.
int shz_file_add
(shz_t *z, const char *filename)
Add (or over-write) a file in the archive based on a relative path.
int shz_file_append
(shz_t *z, const char *filename, shbuf_t *buff)
Add to the contents of a file in the archive.
int shz_file_write
(shz_t *z, const char *filename, shbuf_t *buff)
Write the contents of a file to the archive.
int shz_file_read
(shz_t *z, const char *filename, shbuf_t *buff)
Read the contents of a file in the archive.
const char* shz_type_label
(int type)
Obtain the print label for a SHZ page type.
int shz_arch_init
(shz_t *z, shbuf_t *buff, int flags)
int shz_arch_fopen
(shz_t *z, const char *path, int flags)
void shz_arch_free
(shz_t *z)
shz_hdr_t* shz_page_new
(shz_t *z, int type, shz_idx *bnum_p)
Allocate a new block page for the archive.
shz_hdr_t* shz_page
(shz_t *z, int bnum)
Obtain a block page from the archive.
int shz_file_extract
(shz_t *z, char *rel_path, char *fspec)
Extracts all files contained in an archive, relative to , that match the filter.
Param
z
The SHZ archive.
rel_path
An absolute path to extract file(s) to.
fspec
NULL for no filter, or a wildcard filename specification.
Note
All paths refernce the local file system.
int shz_list_write
(shz_t *z, shz_idx f_idx, char *f_path, shbuf_t *buff, void *p)
ssize_t shz_raw_write
(shz_t *z, shz_idx *ret_idx_p, unsigned char *data, size_t data_len)
int shz_raw_read
(shz_t *z, shz_idx bnum, shbuf_t *buff)
int shz_index_add
(shz_t *z, shz_write_f f, shbuf_t *buff, shz_idx *ret_idx_p)
int shz_index_write
(shz_t *z, shz_write_f f, shbuf_t *buff, shz_idx *ret_idx_p)
int shz_index_read
(shz_t *z, shz_read_f f, shbuf_t *buff, shz_idx bnum)
ssize_t shz_zlib_write
(shz_t *z, shz_idx *z_bnum_p, unsigned char *data, size_t data_len)
int shz_zlib_read
(shz_t *z, int page_bnum, shbuf_t *dec_buff)
int shz_mod_write
(shz_t *z, shz_idx mod_bnum, shbuf_t *buff)
int shz_mod_read
(shz_t *z, shz_mod_t *mod, shbuf_t *buff)
time_t shz_mod_ctime
(shz_t *z, shz_idx bnum)
time_t shz_mod_mtime
(shz_t *z, shz_idx bnum)
const char* shz_mod_label
(shz_t *z, shz_idx bnum)
shtime_t shz_ctime
(shz_t *z)
The time that the archive was created.
shtime_t shz_mtime
(shz_t *z)
The last time the archive was updated.
time_t shz_uctime
(shz_t *z)
The time the archive was created in unix-time.
time_t shz_umtime
(shz_t *z)
The last modification time in unix-time format.
int shdiff
(shbuf_t *buff, char *str_1, char *str_2)
int shdelta
(shbuf_t *src_buff, shbuf_t *in_buff, shbuf_t *out_buff)
int shpatch
(shbuf_t *src_buff, shbuf_t *in_buff, shbuf_t *out_buff)
int shbase58_decode
(unsigned char *data, size_t *data_len, char *b58)
int shbase58_encode
(char *b58, size_t *b58sz, unsigned char *data, size_t data_len)
int shbase58_encode_check
(const uint8_t *data, int datalen, char *str, int strsize)
int shbase58_decode_check
(const char *str, uint8_t *data, int datalen)
int shbase58_decode_size
(char *b58, size_t max_size)
int shbase64_decode
(char *enc_data, unsigned char **data_p, size_t *data_len_p)
int shbase64_encode
(unsigned char *data, size_t data_len, char **enc_data_p)
int shbase32_adecode
(char *in, size_t in_len, unsigned char *out, size_t *out_len_p)
int shbase32_decode
(char *in, size_t in_len, unsigned char *out, size_t *out_len_p)
void shbase32_encode
(const char *in, size_t inlen, char *out, size_t outlen)
size_t shbase32_encode_alloc
(const char *in, size_t inlen, char **out)
int shsig_shr_gen
(shsig_t *pub_sig, unsigned char data, size_t data_len)
Generate a public key using random or user-supplied content.
Param
data
The user-supplied content or NULL for random key.
int shsig_shr_sign
(shsig_t *priv_sig, shsig_t *pub_sig, unsigned char *data, size_t data_len)
Generate a private signature from data content and sign it with a public key.
Param
data
The user-supplied message to sign.
int shsig_shr_verify
(shsig_t *priv_sig, shsig_t *pub_sig, unsigned char *data, size_t data_len)
Verify that a private key is valid based on user-supplied content and a public signature.
char* shjson_print
(shjson_t *json)
A JSON text-format of the specified hierarchy.
Return Value
An allocated string in JSON format.
char* shjson_Print
(shjson_t *item)
A human-readable JSON text-format of the specified hierarchy.
Return Value
An allocated string in JSON format.
char* shjson_str
(shjson_t *json, char *name, char *def_str)
Obtain an allocated string value from a JSON object.
Param
tree
The JSON object containing the string value.
name
The name of the string JSON node.
def_str
The default string value if the JSON node does not exist.
Return Value
The string value contained in the JSON node.
char* shjson_astr
(shjson_t *json, char *name, char *def_str)
Obtain an un-allocated string value from a JSON object.
Param
tree
The JSON object containing the string value.
name
The name of the string JSON node.
def_str
The default string value if the JSON node does not exist.
Return Value
The string value contained in the JSON node.
shjson_t* shjson_str_add
(shjson_t *tree, char *name, char *val)
Add a string value to a JSON object or array.
Param
tree
The JSON object containing the string value.
name
The name of the string JSON node.
val
The string value to store in the new JSON node.
Return Value
The new JSON node containing the string value.
void shjson_free
(shjson_t **tree_p)
De-allocates memory associated with a JSON hiearchy.
Param
tree_p
A reference to the JSON hierarchy.
See
shjson_init()
group__libshare__memjson_1ga6a003b3ec511a1f68258088cad1d70ea
member
double shjson_num
(shjson_t *json, char *name, double def_d)
Obtain a number value from a JSON object.
Param
tree
The JSON object containing the number value.
name
The name of the number JSON node.
def_d
The default number value if the JSON node does not exist.
Return Value
The number value contained in the JSON node.
shjson_t* shjson_num_add
(shjson_t *tree, char *name, double num)
Add a number value to a JSON object or array.
Param
tree
The JSON object or array to add the number value.
name
The name of the number JSON node or NULL if is an array.
tree
idx
The number value to store in the new JSON node.
Return Value
The new JSON node containing the number value.
shjson_t* shjson_init
(char *json_str)
Create a new JSON tree hierarchy.
Param
json_str
A JSON formatted text string or NULL.
Return Value
A new JSON object if is null or a full JSON node hierarchy otherwise.
json_str
See
shjson_print
group__libshare__memjson_1ga4c996046c84e6237ba31f7e8242556c1
member
shjson_free
group__libshare__memjson_1gae9a7788305c14ad5cfb2b08c8d1a1fb4
member
shjson_t* shjson_array_add
(shjson_t *tree, char *name)
Create a new JSON node at the end of an array.
Param
json
The JSON object containing the array.
name
The name of the array in the JSON object.
Return Value
A new JSON node attachd to the array.
int shjson_array_count
(shjson_t *json, char *name)
shjson_t* shjson_obj_add
(shjson_t *tree, char *name)
Create a new object JSON node.
Param
name
The name of the object or NULL if appending to an array.
char* shjson_array_str
(shjson_t *json, char *name, int idx)
Obtain an allocated string value from an array.
Param
json
The JSON object containing the array.
name
The name of the array in the JSON object.
idx
The index number of the JSON node in the array.
Return Value
The string value contained in the array's node index.
Note
The string pointer returned must be de-allocated.
char* shjson_array_astr
(shjson_t *json, char *name, int idx)
Obtain an un-allocated string value from an array.
Param
json
The JSON object containing the array.
name
The name of the array in the JSON object.
idx
The index number of the JSON node in the array.
Return Value
The string value contained in the array's node index.
Note
Do not free the string pointer returned.
double shjson_array_num
(shjson_t *json, char *name, int idx)
Obtain a number value from an array.
Param
json
The JSON object containing the array.
name
The name of the array in the JSON object.
idx
The index number of the JSON node in the array.
Return Value
The numeric value contained in the array's node index.
shjson_t* shjson_obj
(shjson_t *json, char *name)
Return Value
A JSON object contained inside another object.
size_t shjson_strlen
(shjson_t *json, char *name)
Return Value
The string length of a JSON object node.