TBLT_RETC TBLT_CALLBACK MyBltIx4Crypto(ULONG mode,
TBLT_KH *khPtr,
VOID *keyPtr,
ULONG recNoPlus);
mode I:sub-function to perform
khPtr I:index file control structure
keyPtr IO:key buffer pointer; or node stream pointer
recNoPlus I:number of the record (informational); or node count
Note: This routine is not part of the base Bullet 3 package but is
documented here for the record. An example crypto routine is included in
the regular distribution (crypto.c). Once written, a function pointer to the
crypto routine is assigned to TBLT_KH.cryptoPtr.
This routine encrypts or decrypts the index key, depending on the mode.
The mode parameter varies depending on which Bullet routine calls here:
CRYPTO_FROM_KEYADD from the btree manager CRYPTO_FROM_KEYGET from the btree manager CRYPTO_FROM_KEYADDBULK from BltFuncIx4Reindex()
For KEYADD, the key buffer should be encrypted. For KEYGET it
should be decrypted. The key is both read and written to keyPtr. The size of the key
is available in khPtr->keyLength. The recNo is provided for informational use.
For KEYADDBULK, keyPtr no longer points to a single key buffer, but instead
points to a stream of key nodes to be encrypted. Also, recNoPlus is now the count of nodes
to encrypt, and not a record number.
The node stream consists of one or more nodes (each of khPtr->nodeSize bytes), with the first byte of each node holding the number of keys on that node (the key count). Each key is khPtr->keyLength in size, with 4 bytes of workspace before the key (an internally-used node pointer) and 4 bytes after the key proper for the record number. Therefore, keys are (4+khPtr->keyLength+4) bytes apart from each other (ie key length plus 8 bytes), within a node.
The first key element (a key element is 4+keylength+4 bytes in size) immediately follows the key count byte. Therefore, the first key proper is at keyPtr[5] (skipping the key count byte, plus the 4-byte nodeptr). The second key proper is at keyPtr[5+khPtr->keyLength+8] (+8 to skip over the first key's record number and the 4-byte nodeptr of the second key).
The first key proper of the second node (if there is more than one node -- as indicated by recNoPlus) is at keyPtr[khPtr->nodeSize+5], and so on.
Return: Non-zero indicates an error, otherwise the data at keyPtr
has been encrypted or decrypted.