now with function
This commit is contained in:
parent
8a278843bb
commit
1cc5630207
|
@ -133,3 +133,21 @@ uint8_t prf_tls12_next(void* dest, prf_tls12_ctx_t* ctx){
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint8_t prf_tls12_fill(void* dest, uint16_t length_B, prf_tls12_ctx_t* ctx){
|
||||
uint16_t bs = ctx->blocklength_b/8;
|
||||
while(length_B>=bs){
|
||||
if(prf_tls12_next(dest, ctx)){
|
||||
return 1;
|
||||
}
|
||||
length_B -= bs;
|
||||
dest = (uint8_t*)dest + bs;
|
||||
}
|
||||
if(length_B){
|
||||
uint8_t buffer[bs];
|
||||
if(prf_tls12_next(buffer, ctx)){
|
||||
return 2;
|
||||
}
|
||||
memcpy(dest, buffer, length_B);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ uint8_t prf_tls12_init_w_label(prf_tls12_ctx_t* ctx, const hfdesc_t* hash,
|
|||
|
||||
void prf_tls12_free(prf_tls12_ctx_t* ctx);
|
||||
uint8_t prf_tls12_next(void* dest, prf_tls12_ctx_t* ctx);
|
||||
uint8_t prf_tls12_fill(void* dest, uint16_t length_B, prf_tls12_ctx_t* ctx);
|
||||
|
||||
|
||||
#endif /* PRF_TLS12_H_ */
|
||||
|
|
|
@ -76,17 +76,13 @@ const char test_label[] = "test label";
|
|||
|
||||
void test_prf(const hfdesc_t* hash){
|
||||
prf_tls12_ctx_t ctx;
|
||||
uint8_t buffer[100];
|
||||
prf_tls12_init_w_label(&ctx, hash, test_secret, 16*8, test_label, strlen(test_label), test_seed, 16*8);
|
||||
uint8_t buffer[ctx.blocklength_b/8];
|
||||
uint16_t i=0;
|
||||
cli_putstr("\r\n== Testing PRF-TLSv1.2 with ");
|
||||
cli_putstr(hash->name);
|
||||
cli_putstr(" ==\r\n");
|
||||
do{
|
||||
prf_tls12_next(buffer, &ctx);
|
||||
cli_hexdump_block(buffer, ctx.blocklength_b/8, 4, 8);
|
||||
i += ctx.blocklength_b/8;
|
||||
}while(i<100);
|
||||
prf_tls12_fill(buffer, 100, &ctx);
|
||||
cli_hexdump_block(buffer, 100, 4, 8);
|
||||
prf_tls12_free(&ctx);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue