Skip to content

Commit bec4824

Browse files
author
Andras Fekete
committed
Add in simple logging for wolfProvider
1 parent 1d46ef2 commit bec4824

36 files changed

+402
-0
lines changed

include/wolfprovider/wp_logging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ int wolfProv_SetLogComponents(int componentMask);
129129

130130
#ifdef WOLFPROV_DEBUG
131131

132+
#define WOLFPROV_STRINGIZE_HELPER(x) #x
133+
#define WOLFPROV_STRINGIZE(x) WOLFPROV_STRINGIZE_HELPER(x)
134+
132135
#define WOLFPROV_ERROR(type, err) \
133136
WOLFPROV_ERROR_LINE(type, err, __FILE__, __LINE__)
134137
#define WOLFPROV_ERROR_MSG(type, msg) \

src/wp_aes_aead.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ static int wp_aead_cache_aad(wp_AeadCtx *ctx, const unsigned char *in,
288288
ctx->aadSet = 1;
289289
}
290290

291+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
291292
return ok;
292293
}
293294
#endif
@@ -320,6 +321,7 @@ static int wp_aead_cache_in(wp_AeadCtx *ctx, const unsigned char *in,
320321
}
321322
}
322323

324+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
323325
return ok;
324326
}
325327
#endif
@@ -423,6 +425,7 @@ static int wp_aead_get_ctx_params(wp_AeadCtx* ctx, OSSL_PARAM params[])
423425
}
424426
#endif
425427

428+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
426429
return ok;
427430
}
428431

@@ -459,6 +462,7 @@ static int wp_aead_set_param_tag(wp_AeadCtx* ctx,
459462
ctx->tagLen = sz;
460463
}
461464

465+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
462466
return ok;
463467
}
464468

@@ -490,6 +494,7 @@ static int wp_aead_set_param_iv_len(wp_AeadCtx* ctx,
490494
}
491495
}
492496

497+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
493498
return ok;
494499
}
495500

@@ -522,6 +527,7 @@ static int wp_aead_set_param_tls1_aad(wp_AeadCtx* ctx,
522527
}
523528
}
524529

530+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
525531
return ok;
526532
}
527533

@@ -560,6 +566,7 @@ static int wp_aead_set_param_tls1_iv_fixed(wp_AeadCtx* ctx,
560566
#endif
561567
}
562568

569+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
563570
return ok;
564571
}
565572

@@ -591,6 +598,7 @@ static int wp_aead_set_param_tls1_iv_rand(wp_AeadCtx* ctx,
591598
}
592599
}
593600

601+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
594602
return ok;
595603
#else
596604
(void)ctx;
@@ -630,6 +638,7 @@ static int wp_aead_set_ctx_params(wp_AeadCtx* ctx, const OSSL_PARAM params[])
630638
}
631639
}
632640

641+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
633642
return ok;
634643
}
635644

@@ -720,6 +729,7 @@ static int wp_aead_get_params(OSSL_PARAM params[], unsigned int md,
720729
}
721730
}
722731

732+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
723733
return ok;
724734
}
725735

@@ -843,6 +853,7 @@ static int wp_aesgcm_get_rand_iv(wp_AeadCtx* ctx, unsigned char* out,
843853
ctx->ivState = IV_STATE_COPIED;
844854
}
845855

856+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
846857
return ok;
847858
}
848859

@@ -871,6 +882,7 @@ static int wp_aesgcm_set_rand_iv(wp_AeadCtx *ctx, unsigned char *in,
871882
ctx->ivState = IV_STATE_COPIED;
872883
}
873884

885+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
874886
return ok;
875887
}
876888

@@ -931,6 +943,7 @@ static int wp_aesgcm_tls_iv_set_fixed(wp_AeadCtx* ctx, unsigned char* iv,
931943
ctx->ivState = IV_STATE_BUFFERED;
932944
}
933945

946+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
934947
return ok;
935948
}
936949

@@ -1007,6 +1020,7 @@ static int wp_aesgcm_einit(wp_AeadCtx* ctx, const unsigned char *key,
10071020
ok = wp_aead_set_ctx_params(ctx, params);
10081021
}
10091022

1023+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
10101024
return ok;
10111025
}
10121026

@@ -1068,6 +1082,7 @@ static int wp_aesgcm_dinit(wp_AeadCtx *ctx, const unsigned char *key,
10681082
ok = wp_aead_set_ctx_params(ctx, params);
10691083
}
10701084

1085+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
10711086
return ok;
10721087
}
10731088

@@ -1150,6 +1165,7 @@ static int wp_aesgcm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out,
11501165
ctx->ivState = IV_STATE_FINISHED;
11511166
ctx->tlsAadLen = UNINITIALISED_SIZET;
11521167
*outLen = oLen;
1168+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
11531169
return ok;
11541170
}
11551171

@@ -1216,6 +1232,7 @@ static int wp_aesgcm_stream_update(wp_AeadCtx *ctx, unsigned char *out,
12161232
*outLen = oLen;
12171233
}
12181234

1235+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
12191236
return ok;
12201237
}
12211238

@@ -1273,6 +1290,7 @@ static int wp_aesgcm_stream_final(wp_AeadCtx *ctx, unsigned char *out,
12731290
*outLen = 0;
12741291
}
12751292

1293+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
12761294
return ok;
12771295
}
12781296

@@ -1346,6 +1364,7 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen)
13461364
ctx->in = NULL;
13471365
ctx->inLen = 0;
13481366

1367+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
13491368
return ok;
13501369
}
13511370

@@ -1395,6 +1414,7 @@ static int wp_aesgcm_stream_update(wp_AeadCtx *ctx, unsigned char *out,
13951414
*outLen = oLen;
13961415
}
13971416

1417+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
13981418
return ok;
13991419
}
14001420

@@ -1425,6 +1445,7 @@ static int wp_aesgcm_stream_final(wp_AeadCtx *ctx, unsigned char *out,
14251445
ctx->ivSet = 0;
14261446
}
14271447

1448+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
14281449
return ok;
14291450
}
14301451

@@ -1462,6 +1483,7 @@ static int wp_aesgcm_cipher(wp_AeadCtx *ctx, unsigned char *out,
14621483
*outLen += finalLen;
14631484
}
14641485

1486+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
14651487
return ok;
14661488
}
14671489

@@ -1542,6 +1564,7 @@ static int wp_aesccm_tls_iv_set_fixed(wp_AeadCtx* ctx, unsigned char* iv,
15421564
memcpy(ctx->iv, iv, len);
15431565
}
15441566

1567+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
15451568
return ok;
15461569
}
15471570

@@ -1590,6 +1613,7 @@ static int wp_aesccm_init(wp_AeadCtx* ctx, const unsigned char *key,
15901613
ok = wp_aead_set_ctx_params(ctx, params);
15911614
}
15921615

1616+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
15931617
return ok;
15941618
}
15951619

@@ -1706,6 +1730,7 @@ static int wp_aesccm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out,
17061730
}
17071731

17081732
*outLen = olen;
1733+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
17091734
return ok;
17101735
}
17111736

@@ -1767,6 +1792,7 @@ static int wp_aesccm_encdec(wp_AeadCtx *ctx, unsigned char *out,
17671792
ctx->aadLen = 0;
17681793
ctx->aadSet = 0;
17691794

1795+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
17701796
return ok;
17711797
}
17721798
/**
@@ -1822,6 +1848,7 @@ static int wp_aesccm_stream_update(wp_AeadCtx *ctx, unsigned char *out,
18221848
*outLen = (size_t)oLen;
18231849
}
18241850

1851+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
18251852
return ok;
18261853
}
18271854

@@ -1857,6 +1884,7 @@ static int wp_aesccm_stream_final(wp_AeadCtx *ctx, unsigned char *out,
18571884
}
18581885
}
18591886

1887+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
18601888
return ok;
18611889
}
18621890

@@ -1892,6 +1920,7 @@ static int wp_aesccm_cipher(wp_AeadCtx *ctx, unsigned char *out,
18921920
*outLen += finalLen;
18931921
}
18941922

1923+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
18951924
return ok;
18961925
}
18971926

src/wp_aes_block.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static int wp_aes_block_get_params(OSSL_PARAM params[], unsigned int mode,
181181
}
182182
}
183183

184+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
184185
return ok;
185186
}
186187

@@ -266,6 +267,7 @@ static int wp_aes_init_iv(wp_AesBlockCtx *ctx, const unsigned char *iv,
266267
}
267268
}
268269

270+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
269271
return ok;
270272
}
271273
#endif
@@ -329,6 +331,7 @@ static int wp_aes_block_init(wp_AesBlockCtx *ctx, const unsigned char *key,
329331
ok = wp_aes_block_set_ctx_params(ctx, params);
330332
}
331333

334+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
332335
return ok;
333336
}
334337

@@ -516,6 +519,7 @@ static int wp_aes_block_update(wp_AesBlockCtx *ctx, unsigned char *out,
516519
ok = invalid == 0;
517520
}
518521

522+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
519523
return ok;
520524
}
521525

@@ -564,6 +568,7 @@ static int wp_aes_block_final_enc(wp_AesBlockCtx* ctx, unsigned char *out,
564568
ctx->bufSz = 0;
565569
*outLen = oLen;
566570
}
571+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
567572
return ok;
568573
}
569574

@@ -629,6 +634,7 @@ static int wp_aes_block_final_dec(wp_AesBlockCtx* ctx, unsigned char *out,
629634
*outLen = 0;
630635
}
631636

637+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
632638
return ok;
633639
}
634640

@@ -660,6 +666,7 @@ static int wp_aes_block_final(wp_AesBlockCtx* ctx, unsigned char *out,
660666
}
661667
}
662668

669+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
663670
return ok;
664671
}
665672

@@ -693,6 +700,7 @@ static int wp_aes_block_cipher(wp_AesBlockCtx* ctx, unsigned char* out,
693700
*outLen = inLen;
694701
}
695702

703+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
696704
return ok;
697705
}
698706

@@ -748,6 +756,7 @@ static int wp_aes_block_get_ctx_params(wp_AesBlockCtx* ctx, OSSL_PARAM params[])
748756
}
749757
}
750758

759+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
751760
return ok;
752761
}
753762

@@ -794,6 +803,7 @@ static int wp_aes_block_set_ctx_params(wp_AesBlockCtx *ctx,
794803
}
795804
}
796805

806+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
797807
return ok;
798808
}
799809

src/wp_aes_stream.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static int wp_aes_stream_get_params(OSSL_PARAM params[], unsigned int mode,
171171
}
172172
}
173173

174+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
174175
return ok;
175176
}
176177

@@ -245,6 +246,7 @@ static int wp_aes_init_iv(wp_AesStreamCtx *ctx, const unsigned char *iv,
245246
XMEMCPY(ctx->oiv, iv, ivLen);
246247
}
247248

249+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
248250
return ok;
249251
}
250252

@@ -303,6 +305,7 @@ static int wp_aes_stream_init(wp_AesStreamCtx *ctx, const unsigned char *key,
303305
ok = wp_aes_stream_set_ctx_params(ctx, params);
304306
}
305307

308+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
306309
return ok;
307310
}
308311

@@ -394,6 +397,7 @@ static int wp_aes_stream_doit(wp_AesStreamCtx *ctx, unsigned char *out,
394397
#endif
395398
{}
396399

400+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
397401
return ok;
398402
}
399403

@@ -424,6 +428,7 @@ static int wp_aes_stream_update(wp_AesStreamCtx *ctx, unsigned char *out,
424428
*outLen = inLen;
425429
}
426430

431+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
427432
return ok;
428433
}
429434

@@ -476,6 +481,7 @@ static int wp_aes_stream_cipher(wp_AesStreamCtx* ctx, unsigned char* out,
476481
}
477482

478483
*outLen = inLen;
484+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
479485
return ok;
480486
}
481487

@@ -526,6 +532,7 @@ static int wp_aes_stream_get_ctx_params(wp_AesStreamCtx* ctx,
526532
}
527533
}
528534

535+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
529536
return ok;
530537
}
531538

@@ -560,6 +567,7 @@ static int wp_aes_stream_set_ctx_params(wp_AesStreamCtx *ctx,
560567
(void)val;
561568
}
562569

570+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
563571
return ok;
564572
}
565573

0 commit comments

Comments
 (0)