Skip to content

Commit

Permalink
Update chapter06.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbrett authored Mar 18, 2024
1 parent 0557a04 commit c105613
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions wolfSSL/src/chapter06.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ The `wc_CryptoInfo` structure contains a union of different structures (some of
To determine the type of cryptographic request and process it accordingly, one would typically use a switch-case statement on the `algo_type` field of the `wc_CryptoInfo` structure. Each case within the switch would correspond to a different cryptographic operation, such as a symmetric cipher, hashing, public key operations, etc. There is a one-to-one mapping between `wc_AlgoType` and the corresponding algo type union, which are commented in the `wc_CryptoInfo` struct definition in
`wolfssl/wolfcrypt/cryptocb.h`.

The crypto callback should return zero on success, or a nonzero error code on failure. For unsupported algorithms, the callback should return `CRYPTOCB_UNAVAILABLE`, which will cause wolfCrypt to fall back to the internal implementation.
The crypto callback should return zero on success, or a valid wolfCrypt error code on failure. For unsupported algorithms, the callback should return `CRYPTOCB_UNAVAILABLE`, which will cause wolfCrypt to fall back to the internal implementation.

Here's a simplified example to illustrate this:

Expand All @@ -266,17 +266,17 @@ int myCryptoCallback(int devId, wc_CryptoInfo* info, void* ctx)
switch (info->algo_type) {
case WC_ALGO_TYPE_HASH:
/* Handle hashing, using algo type union: info->hash */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
case WC_ALGO_TYPE_PK:
/* Handle public key operations, using algo type union: info->pk */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
case WC_ALGO_TYPE_CIPHER:
/* Handle cipher operations, using algo type union: info->cipher */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
/* and so on for other algo types... */
Expand All @@ -301,24 +301,24 @@ int myCryptoCallback(int devId, wc_CryptoInfo* info, void* ctx)
switch (info->pk.type) { /* pk type is of type wc_PkType */
case WC_PK_TYPE_ECDH:
/* use info->pk.ecdh */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
case WC_PK_TYPE_ECDSA_SIGN:
/* use info->pk.eccsign */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
case WC_PK_TYPE_ECDSA_VERIFY:
/* use info->pk.eccverify */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
}
break;
case WC_ALGO_TYPE_RNG:
/* use info->rng */
ret = 0; /* or non-zero error code */
ret = 0; /* or wolfCrypt error code */
break;
}
Expand Down

0 comments on commit c105613

Please sign in to comment.