file
shmem_8h
[ ]
define
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
define
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
define
SHMEM16_MAGIC
((SHMEM_MAGIC >> 24) & 0xFFFF)
A 16bit arbitrary number which is gauranteed to be the same on high and low endian computers.
define
SHMEM8_MAGIC
((SHMEM_MAGIC >> 16) & 0xFF)
A single arbitrary byte (8 bits).
define
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
define
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
define
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
define
SHBUF_PREALLOC
(1 << 0)
define
SHBUF_FMAP
(1 << 1)
define
SHKEY_WORDS
7
The maximum word size of the share key.
define
SHR224_SIZE
28
define
SHR224_BLOCKS
12
define
SHR224_BLOCK_SIZE
(SHR224_BLOCKS * sizeof(uint64_t))
define
SHR224_IPAD_MAGIC
(uint8_t)SHMEM8_MAGIC
define
SHR224_OPAD_MAGIC
(uint8_t)~SHMEM8_MAGIC
define
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.
define
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.
define
SHMPI_MAX_SIZE
1024
Maximum number of bytes for usable MPIs.
define
SHMPI_MAX_BITS
( 8 * SHMPI_MAX_SIZE )
Maximum number of bits for usable MPIs.
define
SHMPI_ERR_FILE_IO_ERROR
-0x0002
An error occurred while reading from or writing to a file.
define
SHMPI_ERR_BAD_INPUT_DATA
-0x0004
Bad input parameters to function.
define
SHMPI_ERR_INVALID_CHARACTER
-0x0006
There is an invalid character in the digit string.
define
SHMPI_ERR_BUFFER_TOO_SMALL
-0x0008
The buffer is too small to write to.
define
SHMPI_ERR_NEGATIVE_VALUE
-0x000A
The input arguments are negative or result in illegal output.
define
SHMPI_ERR_DIVISION_BY_ZERO
-0x000C
The input argument for division is zero, which is not allowed.
define
SHMPI_ERR_NOT_ACCEPTABLE
-0x000E
The input arguments are not acceptable.
define
SHMPI_ERR_MALLOC_FAILED
-0x0010
Memory allocation failed.
define
MPI_HAVE_INT32
define
SHMEM_ALG_GENPRIME
define
SHFMT_HEX
0
define
SHFMT_BASE32
1
define
SHFMT_BASE58
2
define
SHFMT_BASE64
3
define
SHFMT_SHR56
4
define
MAX_SHFMT
5
define
SHALG_128BIT
(1 << 0)
A 16-byte hash.
define
SHALG_160BIT
(1 << 1)
A 20-byte hash.
define
SHALG_224BIT
(1 << 2)
A 28-byte hash.
define
SHALG_256BIT
(1 << 3)
A 32-byte hash.
define
SHALG_384BIT
(1 << 4)
A 48-byte hash.
define
SHALG_512BIT
(1 << 5)
A 64-byte hash.
define
SHALG_SHR
(1 << 8)
Share Library Algorythm.
define
SHALG_SHA
(1 << 9)
Secure Hash Algorythm.
define
SHALG_RSA
(1 << 10)
Pubkey Encryption Algorythm (circa 1977).
define
SHALG_ECDSA
(1 << 11)
Elliptic Curve Algorythm.
define
SHALG_CRYPT
(1 << 12)
define
SHALG_VR
(1 << 15)
Indicates that the algorythm is 'verifiably random'.
define
SHALG_SHR160
(SHALG_SHR | SHALG_160BIT)
The libshare 160-bit hash algorithm.
define
SHALG_SHR224
(SHALG_SHR | SHALG_224BIT)
The libshare 224-bit hash algorithm.
define
SHALG_SHCR224
(SHALG_CRYPT | SHALG_SHR | SHALG_224BIT)
The libshare 224-bit "crypt" hash algorithm designed towards password authentication purposes.
define
SHALG_SHA1
(SHALG_SHA | SHALG_128BIT)
define
SHALG_SHA224
(SHALG_SHA | SHALG_224BIT)
define
SHALG_SHA256
(SHALG_SHA | SHALG_256BIT)
define
SHALG_SHA384
(SHALG_SHA | SHALG_384BIT)
define
SHALG_SHA512
(SHALG_SHA | SHALG_512BIT)
define
SHALG_ECDSA128R
(SHALG_ECDSA | SHALG_128BIT | SHALG_VR)
define
SHALG_ECDSA160R
(SHALG_ECDSA | SHALG_160BIT | SHALG_VR)
define
SHALG_ECDSA160K
(SHALG_ECDSA | SHALG_160BIT)
define
SHALG_ECDSA224R
(SHALG_ECDSA | SHALG_224BIT | SHALG_VR)
define
SHALG_ECDSA224K
(SHALG_ECDSA | SHALG_224BIT)
define
SHALG_ECDSA256R
(SHALG_ECDSA | SHALG_256BIT | SHALG_VR)
define
SHALG_ECDSA256K
(SHALG_ECDSA | SHALG_256BIT)
define
SHALG_ECDSA384R
(SHALG_ECDSA | SHALG_384BIT | SHALG_VR)
define
SHALG_ECDSA512R
(SHALG_ECDSA | SHALG_512BIT | SHALG_VR)
define
SHALG_RSA128
(SHALG_RSA | SHALG_128BIT)
define
SHALG_CRYPT256
(SHALG_CRYPT | SHALG_256BIT)
define
SHALG_CRYPT512
(SHALG_CRYPT | SHALG_512BIT)
define
SHALG_DEFAULT
0
An indicator to use the default available algorythm.
define
SHALG_SHKEY
0
A generic 224-bit key generated by the shkey() function set.
define
SHALG_RIPEMD160
SHALG_SHR160
A convience macro for referencing the RIPEMD160 algorythm.
define
SHALG
((_alg) == (_flag))
Return Value
TRUE if the alg matches the given flags
define
MAX_ALG_SIZE
((MAX_ALG_WORD_SIZE - 1) * sizeof(uint32_t))
define
shalg_size
((_a)[MAX_ALG_WORD_SIZE - 1])
define
MAX_ALG_WORD_SIZE
78
define
SHCR224_SIZE
96
define
SHCR224_SALT_SIZE
28
define
SHCR224_MIN_ROUNDS
1000
define
SHCR224_DEFAULT_ROUNDS
SHCR224_MIN_ROUNDS
define
INITIAL_MAX
15
The initial number of hashmap indexes to create.
define
SHMETA_BIG_ENDIAN
0
Specifies that a machine has a big endian architecture.
See
SHMETA_VALUE_ENDIAN group__libshare__memmap_1gabbd81e29e6bbee43df50a9fda916caf5 member
define
SHMETA_SMALL_ENDIAN
1
Specifies that a machine has a small endian architecture.
See
SHMETA_VALUE_ENDIAN group__libshare__memmap_1gabbd81e29e6bbee43df50a9fda916caf5 member
define
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.
define
SHMAP_ALLOC
(1 << 0)
Indicates the underlying map value has been allocated.
define
SHMAP_STRING
(1 << 10)
A null-terminated string value.
define
SHMAP_NUMBER
(1 << 11)
A numeric value with decimal precision.
define
SHMAP_BINARY
(1 << 13)
A non-specific binary memory segment.
define
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.
define
SHLK_READ_ONLY
O_RDONLY
A flag which indicates the lock applies to only 'Read' I/O access.
define
SHLK_WRITE_ONLY
O_WRONLY
A flag which indicates the lock applies to only 'Write' I/O access.
define
SHLK_IO
O_RDWR
A flag which indicates the lock applies to all I/O access.
define
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.
define
SHLK_OVERRIDE
O_TRUNC
A flag which indicates the previous lock should be over-written.
define
SHLK_NOWAIT
O_NONBLOCK
A flag which indicates to not wait for a lock to become available.
define
shlock_open_num
shlock_open(ashkey_num(_num), (_flags))
Opens a lock based on a number.
See
shlock_open() group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49 member
define
shlock_open_str
shlock_open(ashkey_str(_str), (_flags))
Opens a lock based on a string.
See
shlock_open() group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49 member
define
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
define
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
define
shlock_close_num
shlock_close(ashkey_num(_num), (_flags))
Closes a lock based on a number.
See
shlock_close() group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4 member
define
shlock_close_str
shlock_close(ashkey_str(_str))
Closes a lock based on a string.
See
shlock_close() group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4 member
define
bswap_16
((((value) & 0xff) << 8) | ((value) >> 8))
define
bswap_32
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \ (uint32_t)bswap_16((uint16_t)((value) >> 16)))
define
bswap_64
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \ << 32) | \ (uint64_t)bswap_32((uint32_t)((value) >> 32)))
define
flip32
(swap32yes(dest_p, src_p, 32 / 4))
define
SHTREE_ORDER_PRE
1
define
SHTREE_ORDER_IN
2
define
SHTREE_ORDER_POST
3
define
SHTREE_PERM
(1 << 10)
Do not allow nodes to be removed.
define
SHTREE_RECYCLE
(1 << 11)
Re-use old intermediate branch nodes that are deleted.
define
SHTREE_DEALLOC
(1 << 12)
De-allocate the data segments provided.
define
SHZ_PAGE_SIZE
1024
The size of each page.
define
SHZ_ALLOC_SIZE
65536
The maximum size to allocate at once for the archive.
define
SHZ_PAGE_NONE
0
define
SHZ_PAGE_ROOT
1001
define
SHZ_PAGE_BRANCH
1002
define
SHZ_PAGE_DATA
1004
define
SHZ_PAGE_RAW
1006
define
SHZ_PAGE_INDEX
10011
A block containing hash references to archived data content.
define
SHZ_PAGE_ZLIB_DATA
10021
A block containing a segment of raw zlib compressed data.
define
SHZ_PAGE_ZLIB
10022
define
SHZ_PAGE_DIR
10102
define
SHZ_PAGE_FILE
10104
define
SHZ_PAGE_BASE
23123
A base page which initializes the archive state.
See
shz_base_t structshz__base__t compound
define
MAX_SHZ_PAGE_MODES
24000
define
SHZ_DICT_MASK
0xFF
define
SHZ_HASH_MASK
0xF0
define
SHZ_MAX_INDEX_SIZE
((SHZ_PAGE_SIZE - sizeof()) / sizeof(shz_idx))structshz__data__tcompoundshz_index_t
define
SHZ_WRITE_F
(()(_f))group__libshare__memzlib_1ga04147c4a8cbc72bbb94d3088e7872f92membershz_write_f
define
SHZ_READ_F
(()(_f))group__libshare__memzlib_1gac4bc78a08b4951b293b3692b1161edd5membershz_read_f
define
SHZ_CREATE
(1 << 0)
define
SHZ_FAST
(1 << 1)
whether to reduce the encode (compress) window in order to increase speed
define
SHZ_NOATTR
(1 << 2)
Flag to denote file attributes should not be applied from archive.
define
SHZ_TRUNC
(1 << 3)
Truncate the archive upon initialization.
define
SHZ_RAW
(1 << 4)
Do not encode (compress) the stored data.
define
SHZ_VERBOSE
(1 << 5)
Log information about individual archive operations.
define
SHZ_IGNORE
(1 << 6)
Skip data integrity errors.
define
SHZ_QUIET
(1 << 7)
define
SHZ_ABSOLUTE
(1 << 8)
define
SHZ_ALLOC
(1 << 20)
Whether the buffer is internally allocated by the shz functionality.
define
SHZ_FRESH
(1 << 21)
Whether to start with an empty archive.
define
SHZ_VERIFY
(1 << 22)
Flag to denote that a base CRC needs verified.
define
shjson_False
0
define
shjson_True
1
define
shjson_NULL
2
define
shjson_Number
3
define
shjson_String
4
define
shjson_Array
5
define
shjson_Object
6
define
shjson_IsReference
256
enum
@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
typedef struct shbuf_t shbuf_t
typedef
typedef struct shkey_t shkey_t
typedef
typedef uint32_t sh160_t[5]
A 160-bit key.
typedef
typedef int32_t t_sint
typedef
typedef uint32_t t_uint
typedef
typedef uint32_t shalg_t[78]
A key or signature.
typedef
typedef unsigned char shcr224_t[96]
typedef
typedef struct shpool_t shpool_t
A memory pool.
typedef
typedef struct shmap_t shmap_t
A hashmap table.
typedef
typedef struct shmap_index_t shmap_index_t
A hashmap index.
typedef
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
typedef struct shmap_entry_t shmap_entry_t
A hashmap entry.
typedef
typedef struct shmap_value_t shmap_value_t
Specifies a reference to the current version of a shmap hashmap entry value.
typedef
typedef shesig_t shenc_hdr_t
typedef
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
typedef void(* shtree_f)(shtree_t *)
typedef
typedef uint32_t shz_idx
typedef
typedef struct shz_map_t shz_map_t
typedef
typedef struct shz_mod_t shz_mod_t
typedef
typedef struct shz_data_t shz_data_t
typedef
typedef struct shz_t shz_t
typedef
typedef struct shz_tree_t shz_tree_t
typedef
typedef struct shz_data_t shz_index_t
typedef
typedef ssize_t(* shz_write_f)(shz_t *, shz_idx *, unsigned char *, size_t)
The bulk write function template for a module.
typedef
typedef int(* shz_read_f)(shz_t *, shz_idx, shbuf_t *)
The bulk read function template for a module.
typedef
typedef int(* shz_list_f)(shz_t *, shz_idx, char *f_path, shbuf_t *, void *p)
variable
shkey_t _shkey_blank
function
int shbuf_cmp
(shbuf_t *buff, shbuf_t *cmp_buff)
Return Value
TRUE or FALSE whether buffers contain identical data.
function
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
function
void shbuf_catstr
(shbuf_t *buf, char *data)
Inserts a string into a memory pool.
shbuf_t structshbuf__t compound
function
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
function
void shbuf_memcpy
(shbuf_t *buf, void *data, size_t data_len)
function
size_t shbuf_size
(shbuf_t *buf)
The current size of the data segement stored in the memory buffer.
function
unsigned char* shbuf_data
(shbuf_t *buf)
function
void shbuf_clear
(shbuf_t *buf)
Clear the contents of a libshare memory buffer.
shbuf_t structshbuf__t compound
function
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.
function
void shbuf_truncate
(shbuf_t *buf, size_t len)
function
void shbuf_dealloc
(shbuf_t *buf)
function
void shbuf_free
(shbuf_t **buf_p)
Frees the resources utilizited by the memory buffer.
function
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.
function
shbuf_t* shbuf_file
(char *path)
Map a file into a memory buffer.
function
int shbuf_growmap
(shbuf_t *buf, size_t data_len)
function
shbuf_t* shbuf_map
(unsigned char *data, size_t data_len)
function
shbuf_t* ashbuf_map
(unsigned char *data, size_t data_len)
function
unsigned char* shbuf_unmap
(shbuf_t *buf)
function
size_t shbuf_pos
(shbuf_t *buff)
function
void shbuf_pos_set
(shbuf_t *buff, size_t pos)
function
void shbuf_pos_incr
(shbuf_t *buff, size_t pos)
function
size_t shbuf_idx
(shbuf_t *buf, unsigned char ch)
function
void shbuf_padd
(shbuf_t *buff, size_t len)
function
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.
function
shkey_t* ashkey_bin
(char *data, size_t data_len)
function
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
function
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
function
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
function
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
function
shkey_t* ashkey_uniq
(void)
function
uint64_t shkey_crc
(shkey_t *key)
A 64-bit numeric representation of a . shkey_t structshkey__t compound
function
void shkey_free
(shkey_t **key_p)
function
uint64_t shrand
(void)
function
shkey_t* shkey_xor
(shkey_t *key1, shkey_t *key2)
function
shkey_t* ashkey_xor
(shkey_t *key1, shkey_t *key2)
function
shkey_t* shkey_dup
(shkey_t *key)
function
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.
function
shkey_t* ashkey_str
(char *name)
Generates a from a string that does not need to be freed. shkey_t structshkey__t compound
See
shkey_free()
Bug psuedo thread-safe bug_1_bug000001
function
shkey_t* ashkey_num
(long num)
Generates a from a number that does not need to be freed. shkey_t structshkey__t compound
See
shkey_free()
Bug psuedo thread-safe bug_1_bug000002
function
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.
function
shkey_t* shkey_clone
(shkey_t *key)
function
shkey_t* shkey_cert
(shkey_t *key, uint64_t crc, shtime_t stamp)
Creates a certificate's signature key based off content attributes.
function
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.
function
shkey_t* shkey_gen
(char *hex_str)
Converts a hex string into a binary key.
function
const char* shkey_hex
(shkey_t *key)
A string hexadecimal representation of a libshare key.
Note
The string returned will be 48 characters long.
function
shkey_t* shkey_hexgen
(char *hex_str)
Generate a libshare key from a 48-character long hexadecimal string.
function
shkey_t* shkey_shr160
(sh160_t raw)
Generate a allocated share-key from a 160bit binary segment.
function
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.
function
void sh160_key
(shkey_t *in_key, sh160_t u160)
Obtain a 160bit binary segment from a pre-set 160-bit share-key.
function
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.
function
shkey_t* shkey_shr160_gen
(char *key_str)
Generate a 'u160' key from a printed key string.
function
char* shkey_shr160_print
(shkey_t *key)
function
int shkey_shr160_ver
(shkey_t *key)
function
int shr224
(unsigned char *data, size_t data_len, unsigned char *ret_digest)
function
int shr224_init
(shr224_t *ctx)
function
int shr224_write
(shr224_t *ctx, unsigned char *data, size_t data_len)
function
int shr224_result
(shr224_t *ctx, unsigned char *ret_digest)
function
int shr224_hmac
(unsigned char *key, size_t key_len, unsigned char *data, size_t data_len, unsigned char *ret_digest)
function
int shr224_hmac_init
(shr224_t *ctx, unsigned char *key, size_t key_len)
function
int shr224_hmac_write
(shr224_t *ctx, unsigned char *data, size_t data_len)
function
int shr224_hmac_result
(shr224_t *ctx, unsigned char *ret_digest)
function
int shr224_expand
(unsigned char *digest, unsigned char *data, size_t data_len)
function
int shr224_shrink
(uint64_t crc, unsigned char *data, size_t data_len, unsigned char *ret_digest)
function
uint64_t shr224_crc
(shr224_t *ctx)
function
shkey_t* ashkey_shr224
(void *data, size_t data_len)
function
shkey_t* shkey_shr224
(void *data, size_t data_len)
function
int shkey_shr224_ver
(shkey_t *key, unsigned char *data, size_t data_len)
function
int shr224_result_key
(shr224_t *ctx, shkey_t *key)
function
uint64_t shr224_result_crc
(shr224_t *ctx, shkey_t *key)
function
void* memxor
(void *dest, const void *src, size_t n)
function
int shkey_alg
(shkey_t *key)
function
void shkey_alg_set
(shkey_t *key, int alg)
function
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.
function
void shmpi_free
(shmpi *X)
Unallocate one MPI.
Param
X
One MPI to unallocate.
function
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
function
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
function
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
function
void shmpi_swap
(shmpi *X, shmpi *Y)
Swap the contents of X and Y.
Param
X
First MPI value
Y
Second MPI value
function
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).
function
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).
function
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
function
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
function
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)
function
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
Param
X
MPI to use
function
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
Param
X
MPI to use
function
size_t shmpi_size
(const shmpi *X)
Return the total size in bytes.
Param
X
MPI to use
function
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
function
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.
function
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
function
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
function
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
function
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
function
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|
function
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
function
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
function
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
function
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
function
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
function
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
function
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
function
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
function
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
function
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
function
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.
function
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.
function
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
function
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
function
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.
function
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
function
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
function
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
function
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
function
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
function
size_t shmpi_bitlen
(const shmpi *X)
Return Value
The the number of bits.
function
char* shhex_str
(unsigned char *data, size_t data_len)
function
void shhex_bin
(char *hex_str, unsigned char *data, size_t data_max)
function
const char* shalg_str
(int alg)
Print the algorythm parameters.
function
int shalg_fmt
(char *label)
function
char* shalg_fmt_str
(int fmt)
function
char* shalg_encode
(int fmt, unsigned char *data, size_t data_len)
Print a binary segment in the format specified.
function
int shalg_decode
(int fmt, char *in_data, unsigned char *data, size_t *data_len_p)
function
int shalg_priv_rand
(int alg, shalg_t ret_key)
Generate a random 512-bit private signature.
function
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.
function
char* shalg_print
(int fmt, shalg_t key)
Print a key or signature in the format specified.
function
int shalg_gen
(int fmt, char *in_data, shalg_t ret_key)
function
int shalg_pub
(int alg, shalg_t priv_key, shalg_t ret_key)
Generate a public key from a private key.
function
int shalg_sign
(int alg, shalg_t priv_key, shalg_t ret_sig, unsigned char *data, size_t data_len)
function
int shalg_ver
(int alg, shalg_t pub_key, shalg_t sig_key, unsigned char *data, size_t data_len)
function
int shalg_mode_str
(char *mode_str)
function
int shalg_cmp
(shalg_t alg_a, shalg_t alg_b)
function
int shsha_hex
(int alg, unsigned char *ret_digest, unsigned char *data, size_t data_len)
Digest a single message into hexadecimal format.
function
int shsha
(int alg, unsigned char *ret_bin, unsigned char *data, size_t data_len)
Digest a single message into binary format.
function
size_t shsha_size
(int alg)
The byte size of the resulting SHA digest hash.
function
int shsha_init
(sh_sha_t *ctx, int alg)
function
int shsha_write
(sh_sha_t *ctx, unsigned char *data, size_t data_len)
function
int shsha_result
(sh_sha_t *ctx, unsigned char *ret_bin)
function
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.
function
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.
function
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.
function
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().
function
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.
function
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.
function
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.
function
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.
function
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.
function
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.
function
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.
function
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.
function
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.
function
void sh_sha224
(const unsigned char *message, unsigned int len, unsigned char *digest)
function
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.
function
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.
function
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.
function
void sh_sha256
(const unsigned char *message, unsigned int len, unsigned char *digest)
function
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.
function
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.
function
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.
function
void sh_sha512
(const unsigned char *message, unsigned int len, unsigned char *digest)
function
char* shdigest
(void *data, int32_t len)
function
void sh_ripemd160
(unsigned char *data, size_t data_len, sh160_t digest)
Generate a RIPEMD160 20-byte hash from a binary segment.
function
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.
function
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.
function
char* shsha_2fa_secret
(void)
Generate a random secret key usable for 2fa purposes.
Return Value
A 16-character string in base-32 format.
function
uint32_t shsha_2fa_bin
(int alg, unsigned char *secret, size_t secret_len, int freq)
function
int shsha_2fa_bin_verify
(int alg, unsigned char *secret, size_t secret_len, int freq, uint32_t pin)
function
void shsha_2fa_secret_bin
(unsigned char *secret, size_t secret_len)
function
char* shcrypt
(const char *passwd, const char *salt)
function
char* shcrypt_sha256
(const char *key, const char *salt)
function
char* shcrypt_sha512
(const char *key, const char *salt)
function
void shcrypt_b64_encode
(char *ret_str, unsigned char *data, size_t data_len)
function
void shcrypt_b64_decode
(char *str, unsigned char *data, size_t *data_len_p)
function
shkey_t* shecdsa_key
(char *hex_str)
function
shkey_t* shecdsa_key_priv
(char *hex_seed)
function
shkey_t* shecdsa_key_pub
(shkey_t *priv_key)
function
const char* shecdsa_pub
(const char *hex_str)
function
int shecdsa_sign
(shkey_t *priv_key, char *sig_r, char *sig_s, unsigned char *data, size_t data_len)
function
int shecdsa_verify
(shkey_t *pub_key, char *str_r, char *str_s, unsigned char *data, size_t data_len)
function
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.
function
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.
function
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.
function
char* shecdsa_hd_par_pub
(char *p_secret, char *p_chain, uint32_t idx)
function
char* shecdsa_hd_recover_pub
(char *secret)
function
int shecdsa_hd_sign
(char *privkey_hex, char *sig_r, char *sig_s, char *hash_hex)
function
int shecdsa_hd_verify
(char *pubkey_hex, char *str_r, char *str_s, char *hash_hex)
function
shec_t* shec_init
(int alg)
function
void shec_free
(shec_t **ec_p)
function
char* shec_priv
(shec_t *ec)
function
char* shec_priv_gen
(shec_t *ec, unsigned char *data, size_t data_len)
function
void shec_priv_set
(shec_t *ec, char *hex_priv)
function
char* shec_priv_rand
(shec_t *ec)
function
char* shec_pub
(shec_t *ec)
function
char* shec_pub_gen
(shec_t *ec)
function
int shec_sign
(shec_t *ec, unsigned char *data, size_t data_len)
function
int shec_signstr
(shec_t *ec, char *data)
function
int shec_signnull
(shec_t *ec)
function
int shec_ver
(shec_t *ec, unsigned char *data, size_t data_len)
function
int shec_verstr
(shec_t *ec, char *data)
function
int shec_vernull
(shec_t *ec)
function
shkey_t* shec_priv_key
(shec_t *ec)
function
int shec_priv_key_set
(shec_t *ec, shkey_t *key)
function
shkey_t* shec_pub_key
(shec_t *ec)
function
int shec_pub_key_set
(shec_t *ec, shkey_t *key)
function
int shec_pub_set
(shec_t *ec, char *hex_pub)
function
int shec_sig_set
(shec_t *ec, char *hex_sig)
function
int shcr224_verify
(char *salt, char *sig, char *data)
function
int shcr224_bin_verify
(unsigned char salt_key[28], shcr224_t sig, unsigned int rounds, unsigned char *data, size_t data_len)
function
int shcr224
(char *salt, char *data, char *ret_str)
function
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.
function
char* shcr224_salt
(unsigned int rounds)
function
int shcr224_salt_bin
(unsigned char ret_key[28])
Generate a random salt.
function
char* shcr224_salt_gen
(unsigned int rounds, unsigned char *data, size_t data_len)
function
int shcr224_salt_bin_gen
(unsigned char ret_key[28], unsigned char *data, size_t data_len)
function
uint32_t shcsum_crc32
(uint32_t crc, unsigned char *buf, size_t len)
function
uint32_t shcsum_crc32_combine
(uint32_t crc1, uint32_t crc2, size_t len2)
function
uint32_t shcsum_adler32
(uint32_t adler, unsigned char *buf, size_t len)
function
uint32_t shcsum_adler32_combine
(uint32_t adler1, uint32_t adler2, size_t len2)
function
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
function
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
function
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
function
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.
function
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
function
void shpool_put
(shpool_t *pool, shbuf_t *buff)
Put's a memory buffer into a pool.
function
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.
function
shmap_t* shmap_init
(void)
Create an instance of a meta definition hashmap.
Return Value
A meta definition hashmap.
shmap_t structshmap__t compound
function
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.
function
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.
function
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.
function
void shmap_set_astr
(shmap_t *h, shkey_t *key, char *value)
Set a map key to an allocated copy of a string value.
function
void shmap_unset_str
(shmap_t *h, shkey_t *name)
Unset a string value from a meta definition.
function
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.
function
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.
function
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.
function
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
function
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.
function
void shmap_load
(shmap_t *ht, shbuf_t *buff)
Loads data dumped by . shmap_print() group__libshare__memmap_1ga99be5185d0537a6c2f9fbcb0ca9cc83c member
function
unsigned int shmap_count
(shmap_t *ht)
function
void shmap_set_ptr
(shmap_t *ht, shkey_t *key, void *ptr)
function
void* shmap_get_ptr
(shmap_t *h, shkey_t *key)
function
void** shmap_get_ptr_list
(shmap_t *h)
function
void shmap_set_abin
(shmap_t *ht, shkey_t *key, void *data, size_t data_len)
function
void shmap_set_bin
(shmap_t *ht, shkey_t *key, void *data, size_t data_len)
function
void shmap_unset
(shmap_t *h, shkey_t *name)
function
void shmap_self
(shmap_index_t *hi, shkey_t **key_p, void **val_p, ssize_t *len_p, int *flag_p)
function
int shmap_set_ent
(shmap_t *ht, shkey_t *key, int map_flag, void *val, ssize_t val_size)
function
void shbuf_append
(shbuf_t *from_buff, shbuf_t *to_buff)
function
shbuf_t* shbuf_clone
(shbuf_t *buff)
function
int shbuf_sprintf
(shbuf_t *buff, char *fmt,...)
Return Value
the number of characters appended to the memory buffer.
Note
passes arguments through vsnprintf().
function
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
function
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
function
shkey_t* shencode_str
(char *data)
See
shdecode_str() group__libshare__memcrypt_1ga1e3e85d775242a8f25ff07ee451ec69a member
function
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
function
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
function
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.
function
int shencode_b64
(unsigned char *data, size_t data_len, char **out_p, shkey_t *key)
function
int shdecode_b64
(char *in_data, unsigned char **data_p, size_t *data_len_p, shkey_t *key)
function
int shencrypt
(int alg, shbuf_t *out_buff, unsigned char *data, size_t data_len, unsigned char *key, size_t key_len)
function
int shdecrypt
(shbuf_t *out_buff, unsigned char *data, size_t data_len, unsigned char *key, size_t key_len)
function
int shdecrypt_verify
(unsigned char *data, size_t data_len)
function
int shencrypt_derive
(shesig_t *cert, shalg_t pub, shbuf_t *buff, unsigned char *key_data, size_t key_len)
function
int shdecrypt_derive_verify
(shesig_t *cert, shalg_t pub)
function
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
function
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
function
int shlock_close
(shkey_t *key)
Unlock a mutex.
function
(static) (inline)
static uint32_t swab32
(uint32_t v)
function
(static) (inline)
static void swap32yes
(void *out, const void *in, size_t sz)
function
void shscrypt_peer
(scrypt_peer *peer, char *nonce1, double diff)
function
int shscrypt
(scrypt_work *work, int step)
function
int shscrypt_verify
(scrypt_work *work)
function
void shscrypt_peer_gen
(scrypt_peer *peer, double diff)
function
double shscrypt_hash_diff
(scrypt_work *work)
function
void shscrypt_work
(scrypt_peer *peer, scrypt_work *work, char **merkle_list, char *prev_hash, char *coinbase1, char *coinbase2, char *nbit, char *ntime)
function
void shscrypt_swap256
(void *dest_p, const void *src_p)
function
void sh_calc_midstate
(struct scrypt_work *work)
function
void shtree_data_set
(shtree_t *node, void *data)
Set a data segment for a tree node.
function
void* shtree_data_get
(shtree_t *node)
Get a data segment from a tree node.
function
shtree_t* shtree_new
(shtree_t *tree, void *data)
function
shtree_t* shtree_init
(int flags)
function
void shtree_free_node
(shtree_t *node)
function
void shtree_remove_branch
(shtree_t *node)
function
shtree_t* shtree_left_new
(shtree_t *tree, void *data)
function
shtree_t* shtree_right_new
(shtree_t *tree, void *data)
function
shtree_t* shtree_right
(shtree_t *tree)
function
shtree_t* shtree_left
(shtree_t *tree)
function
int shtree_leaf
(shtree_t *tree)
function
shtree_t* shtree_root
(shtree_t *node)
function
shtree_t* shtree_parent
(shtree_t *node)
function
int shtree_flags
(shtree_t *node)
function
int shtree_root_flags
(shtree_t *node)
function
void shtree_traverse_pre
(shtree_t *node, shtree_f proc)
function
void shtree_traverse_in
(shtree_t *node, shtree_f proc)
function
void shtree_traverse_post
(shtree_t *node, shtree_f proc)
function
void shtree_traverse
(shtree_t *node, int order, shtree_f proc)
function
void shtree_free
(shtree_t **tree_p)
function
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.
function
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.
function
shz_t* shz_init
(shbuf_t *buff, int flags)
function
void shz_free
(shz_t **z_p)
function
shz_t* shz_fopen
(const char *path, int flags)
function
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.
function
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.
function
int shz_file_add
(shz_t *z, const char *filename)
Add (or over-write) a file in the archive based on a relative path.
function
int shz_file_append
(shz_t *z, const char *filename, shbuf_t *buff)
Add to the contents of a file in the archive.
function
int shz_file_write
(shz_t *z, const char *filename, shbuf_t *buff)
Write the contents of a file to the archive.
function
int shz_file_read
(shz_t *z, const char *filename, shbuf_t *buff)
Read the contents of a file in the archive.
function
const char* shz_type_label
(int type)
Obtain the print label for a SHZ page type.
function
int shz_arch_init
(shz_t *z, shbuf_t *buff, int flags)
function
int shz_arch_fopen
(shz_t *z, const char *path, int flags)
function
void shz_arch_free
(shz_t *z)
function
shz_hdr_t* shz_page_new
(shz_t *z, int type, shz_idx *bnum_p)
Allocate a new block page for the archive.
function
shz_hdr_t* shz_page
(shz_t *z, int bnum)
Obtain a block page from the archive.
function
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.
function
int shz_list_write
(shz_t *z, shz_idx f_idx, char *f_path, shbuf_t *buff, void *p)
function
ssize_t shz_raw_write
(shz_t *z, shz_idx *ret_idx_p, unsigned char *data, size_t data_len)
function
int shz_raw_read
(shz_t *z, shz_idx bnum, shbuf_t *buff)
function
int shz_index_add
(shz_t *z, shz_write_f f, shbuf_t *buff, shz_idx *ret_idx_p)
function
int shz_index_write
(shz_t *z, shz_write_f f, shbuf_t *buff, shz_idx *ret_idx_p)
function
int shz_index_read
(shz_t *z, shz_read_f f, shbuf_t *buff, shz_idx bnum)
function
ssize_t shz_zlib_write
(shz_t *z, shz_idx *z_bnum_p, unsigned char *data, size_t data_len)
function
int shz_zlib_read
(shz_t *z, int page_bnum, shbuf_t *dec_buff)
function
int shz_mod_write
(shz_t *z, shz_idx mod_bnum, shbuf_t *buff)
function
int shz_mod_read
(shz_t *z, shz_mod_t *mod, shbuf_t *buff)
function
time_t shz_mod_ctime
(shz_t *z, shz_idx bnum)
function
time_t shz_mod_mtime
(shz_t *z, shz_idx bnum)
function
const char* shz_mod_label
(shz_t *z, shz_idx bnum)
function
shtime_t shz_ctime
(shz_t *z)
The time that the archive was created.
function
shtime_t shz_mtime
(shz_t *z)
The last time the archive was updated.
function
time_t shz_uctime
(shz_t *z)
The time the archive was created in unix-time.
function
time_t shz_umtime
(shz_t *z)
The last modification time in unix-time format.
function
int shdiff
(shbuf_t *buff, char *str_1, char *str_2)
function
int shdelta
(shbuf_t *src_buff, shbuf_t *in_buff, shbuf_t *out_buff)
function
int shpatch
(shbuf_t *src_buff, shbuf_t *in_buff, shbuf_t *out_buff)
function
int shbase58_decode
(unsigned char *data, size_t *data_len, char *b58)
function
int shbase58_encode
(char *b58, size_t *b58sz, unsigned char *data, size_t data_len)
function
int shbase58_encode_check
(const uint8_t *data, int datalen, char *str, int strsize)
function
int shbase58_decode_check
(const char *str, uint8_t *data, int datalen)
function
int shbase58_decode_size
(char *b58, size_t max_size)
function
int shbase64_decode
(char *enc_data, unsigned char **data_p, size_t *data_len_p)
function
int shbase64_encode
(unsigned char *data, size_t data_len, char **enc_data_p)
function
int shbase32_adecode
(char *in, size_t in_len, unsigned char *out, size_t *out_len_p)
function
int shbase32_decode
(char *in, size_t in_len, unsigned char *out, size_t *out_len_p)
function
void shbase32_encode
(const char *in, size_t inlen, char *out, size_t outlen)
function
size_t shbase32_encode_alloc
(const char *in, size_t inlen, char **out)
function
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.
function
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.
function
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.
function
char* shjson_print
(shjson_t *json)
A JSON text-format of the specified hierarchy.
Return Value
An allocated string in JSON format.
function
char* shjson_Print
(shjson_t *item)
A human-readable JSON text-format of the specified hierarchy.
Return Value
An allocated string in JSON format.
function
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.
function
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.
function
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.
function
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
function
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.
function
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.
function
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
function
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.
function
int shjson_array_count
(shjson_t *json, char *name)
function
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.
function
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.
function
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.
function
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.
function
shjson_t* shjson_obj
(shjson_t *json, char *name)
Return Value
A JSON object contained inside another object.
function
size_t shjson_strlen
(shjson_t *json, char *name)
Return Value
The string length of a JSON object node.
function
shjson_t* shjson_obj_get
(shjson_t *json, char *name)