Skip to content

Commit d6f4d24

Browse files
Address PR feedback: remove line numbers and update comment style
- Remove all line number references (lines 2707-2736, 319-323, 4269-4285, 2753+, 2738-2751) - Change all // comments to /* */ style in code examples to match wolfSSL coding style - Fix typo: 'directoriesc.' to 'directories' - Replace min() with ternary operator in crypto callback example for portability Addresses feedback from cconlon in PR #233 Co-Authored-By: David Garske <david@wolfssl.com>
1 parent 63d7eea commit d6f4d24

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

wolfSSL-Porting/src/section02.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ Define a custom function that generates seed data. This is the most direct way t
188188

189189
int myGenerateSeed(unsigned char* output, unsigned int sz)
190190
{
191-
// Fill output buffer with sz bytes of entropy from your source
192-
// Return 0 on success, non-zero on error
191+
/* Fill output buffer with sz bytes of entropy from your source */
192+
/* Return 0 on success, non-zero on error */
193193
}
194194
```
195195
@@ -203,13 +203,13 @@ Define a function that returns random values one at a time. wolfSSL will call th
203203
204204
unsigned int myRandFunc(void)
205205
{
206-
// Return a random value from your entropy source
206+
/* Return a random value from your entropy source */
207207
}
208208
```
209209

210210
The `CUSTOM_RAND_TYPE` should match the return type of your function (e.g., `unsigned int`, `unsigned long`, etc.).
211211

212-
Example from `./wolfcrypt/src/random.c` (lines 2707-2736):
212+
Example from `./wolfcrypt/src/random.c`:
213213
```c
214214
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
215215
{
@@ -243,19 +243,19 @@ Runtime usage:
243243

244244
int myCustomSeedFunc(OS_Seed* os, byte* seed, word32 sz)
245245
{
246-
// Generate sz bytes of entropy into seed buffer
247-
// Return 0 on success
246+
/* Generate sz bytes of entropy into seed buffer */
247+
/* Return 0 on success */
248248
}
249249

250-
// Set the callback before initializing RNG
250+
/* Set the callback before initializing RNG */
251251
wc_SetSeed_Cb(myCustomSeedFunc);
252252

253-
// Now initialize and use RNG as normal
253+
/* Now initialize and use RNG as normal */
254254
WC_RNG rng;
255255
wc_InitRng(&rng);
256256
```
257257
258-
The callback function is defined in `./wolfcrypt/src/random.c` (lines 319-323).
258+
The `wc_SetSeed_Cb` function is defined in `./wolfcrypt/src/random.c`.
259259
260260
#### 4. Crypto Callbacks (WC_ALGO_TYPE_SEED)
261261
@@ -271,14 +271,14 @@ Implementation example (from `wolfssl-examples/tls/cryptocb-common.c`):
271271
int myCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
272272
{
273273
if (info->algo_type == WC_ALGO_TYPE_SEED) {
274-
// Generate random seed data
275-
// info->seed.seed = output buffer
276-
// info->seed.sz = requested size
274+
/* Generate random seed data */
275+
/* info->seed.seed = output buffer */
276+
/* info->seed.sz = requested size */
277277

278-
// Example: Fill with entropy from hardware
278+
/* Example: Fill with entropy from hardware */
279279
while (info->seed.sz > 0) {
280-
word32 len = min(info->seed.sz, BLOCK_SIZE);
281-
// Get entropy from your hardware
280+
word32 len = (info->seed.sz < BLOCK_SIZE) ? info->seed.sz : BLOCK_SIZE;
281+
/* Get entropy from your hardware */
282282
getHardwareEntropy(info->seed.seed, len);
283283
info->seed.seed += len;
284284
info->seed.sz -= len;
@@ -288,11 +288,11 @@ int myCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
288288
return CRYPTOCB_UNAVAILABLE;
289289
}
290290

291-
// Register the callback
291+
/* Register the callback */
292292
int devId = 1;
293293
wc_CryptoCb_RegisterDevice(devId, myCryptoCb, NULL);
294294

295-
// Use the device ID when initializing RNG
295+
/* Use the device ID when initializing RNG */
296296
WC_RNG rng;
297297
wc_InitRng_ex(&rng, NULL, devId);
298298
```
@@ -309,14 +309,14 @@ For development and testing purposes only, you can define `WOLFSSL_GENSEED_FORTE
309309
#define WOLFSSL_GENSEED_FORTEST
310310
```
311311

312-
This will generate a deterministic seed pattern (0x00, 0x01, 0x02, ...) suitable only for testing and debugging. The implementation is in `./wolfcrypt/src/random.c` (lines 4269-4285).
312+
This will generate a deterministic seed pattern (0x00, 0x01, 0x02, ...) suitable only for testing and debugging. The implementation can be found in `./wolfcrypt/src/random.c`.
313313

314314
### Platform-Specific Examples
315315

316316
For examples of platform-specific `wc_GenerateSeed()` implementations, reference the existing implementations in `./wolfcrypt/src/random.c`:
317317

318-
- **Windows**: Uses `CryptGenRandom()` or `BCryptGenRandom()` (lines 2753+)
319-
- **SGX**: Uses `sgx_read_rand()` (lines 2738-2751)
318+
- **Windows**: Uses `CryptGenRandom()` or `BCryptGenRandom()`
319+
- **SGX**: Uses `sgx_read_rand()`
320320
- **Embedded platforms**: Various implementations for FreeRTOS, Zephyr, Micrium, etc.
321321
- **Hardware RNG**: Examples for STM32, NXP, Renesas, Infineon, and other platforms
322322

@@ -345,7 +345,7 @@ For examples of platform-specific `wc_GenerateSeed()` implementations, reference
345345
For additional examples and reference implementations, see:
346346
- `./wolfcrypt/src/random.c` - All seed generation implementations
347347
- `wolfssl-examples/tls/cryptocb-common.c` - Crypto callback example with WC_ALGO_TYPE_SEED
348-
- Platform-specific examples in `./wolfcrypt/src/port/` directoriesc.
348+
- Platform-specific examples in `./wolfcrypt/src/port/` directories
349349

350350
## Memory
351351

0 commit comments

Comments
 (0)