2022-09-09 06:47:49 +00:00
|
|
|
#include <stdio.h>
|
2022-11-24 06:49:46 +00:00
|
|
|
#include <stdlib.h>
|
2022-09-09 06:47:49 +00:00
|
|
|
#include "debugprint.h"
|
2024-07-06 14:48:18 +00:00
|
|
|
#include "blst/bindings/blst.h"
|
2022-11-24 06:49:46 +00:00
|
|
|
#include "base64.h"
|
2022-09-09 06:47:49 +00:00
|
|
|
|
2022-11-24 06:49:46 +00:00
|
|
|
void print_bytes(const char* label, void *toprint, int length, char separator){
|
2022-09-09 06:47:49 +00:00
|
|
|
printf("%s", label);
|
|
|
|
for(int i=0;i<length;i++){
|
2022-11-24 06:49:46 +00:00
|
|
|
printf("%.2x", ((byte *) toprint)[i]);
|
|
|
|
if(separator != '\0') printf("%c", separator);
|
2022-09-09 06:47:49 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2022-11-24 06:49:46 +00:00
|
|
|
void print_base64(void *toprint, int input_len){
|
|
|
|
int buffer_size;
|
|
|
|
char* output;
|
|
|
|
|
|
|
|
buffer_size = (((input_len + 2) / 3) * 4) + 1;
|
|
|
|
|
|
|
|
output = malloc(buffer_size); //create a buffer large enough for the base64'd input, including with padding if need be
|
2023-03-21 20:46:42 +00:00
|
|
|
if(output == NULL) return;
|
2022-11-24 06:49:46 +00:00
|
|
|
|
|
|
|
base64_encode_oneshot(toprint, input_len, output);
|
|
|
|
printf("%s\n", output);
|
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
|
2022-09-09 08:48:16 +00:00
|
|
|
void debug_print_bytes(__attribute__((unused)) const char* label, __attribute__((unused)) void *toprint, __attribute__((unused)) int length){
|
2022-09-09 06:47:49 +00:00
|
|
|
#ifdef INSECURE_CTM_DEBUG_PRINT
|
2022-11-24 06:49:46 +00:00
|
|
|
print_bytes(label, toprint, length, ' ');
|
2022-09-09 06:47:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_scalar(const char* label, blst_scalar *toprint){
|
|
|
|
byte temp_buffer[32];
|
|
|
|
blst_bendian_from_scalar(temp_buffer, toprint);
|
|
|
|
|
|
|
|
debug_print_bytes(label, temp_buffer, 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
void debug_print_scalar(__attribute__((unused)) const char* label, __attribute__((unused)) blst_scalar *toprint){
|
|
|
|
#ifdef INSECURE_CTM_DEBUG_PRINT
|
|
|
|
print_scalar(label, toprint);
|
|
|
|
#endif
|
|
|
|
}
|