MPHELL  4.0.0
mphell-util.h
Go to the documentation of this file.
1 /*
2  MPHELL-4.0
3  Author(s): The MPHELL team
4 
5  (C) Copyright 2015-2018 - Institut Fourier / Univ. Grenoble Alpes (France)
6 
7  This file is part of the MPHELL Library.
8  MPHELL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation, version 3 of the License.
11 
12  MPHELL is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with MPHELL. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
26 #ifndef MPHELL_UTIL_H
27 #define MPHELL_UTIL_H
28 
29 #include <string.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <math.h>
34 
35 #include "mphell-define.h"
36 
37 /* For all tests */
38 
45 uint8_t
46 bits_to_nblock (const uint16_t nbits);
47 
55 uint8_t max_size(uint8_t a, uint8_t b);
56 
64 time_t get_s(struct timespec * start, struct timespec * end);
65 
73 unsigned int get_ns(struct timespec * start, struct timespec * end);
74 
75 /* For DRBG tests */
76 
83 void
84 print_bytes_string_hex(const uint8_t * bytes_string, uint16_t length);
85 
93 void
94 bytes_string2hex(char * hex_string, const uint8_t * bytes_string, uint16_t length);
95 
103 void
104 hex_string2bytes(uint8_t * bytes_string, const char * hex_string, uint16_t length);
105 
113 void
114 bin2hex(const unsigned char *old, const uint32_t oldlen, unsigned char* result);
115 
123 uint32_t
124 hex2bin(const char *in, unsigned char *out);
125 
134 int
135 FindMarker (FILE *infile, const char *marker);
136 
147 int
148 ReadHex (FILE *infile, char *A, const int Length, char *str);
149 
150 /* For ecdsa benchmark */
151 
158 void
159 char2bin(char c, uint8_t * b);
160 
166 void
167 printchar2bin(uint8_t b);
168 
175 void
176 string2bin(char* s, uint8_t * output);
177 
184 void
185 printstring2bin(uint8_t * s, uint32_t len);
186 
187 #endif
time_t get_s(struct timespec *start, struct timespec *end)
Return the elapsed time in second between "start" and "end".
Definition: mphell-util.c:39
int ReadHex(FILE *infile, char *A, const int Length, char *str)
Read an hexadecimal string in file "infile".
Definition: mphell-util.c:196
void bytes_string2hex(char *hex_string, const uint8_t *bytes_string, uint16_t length)
Convert the byte string "bytes_string" under hexadecimal form.
Definition: mphell-util.c:67
void printchar2bin(uint8_t b)
print a byte
Definition: mphell-util.c:254
void string2bin(char *s, uint8_t *output)
Convert a string into a byte array.
Definition: mphell-util.c:271
void printstring2bin(uint8_t *s, uint32_t len)
Print a byte array.
Definition: mphell-util.c:281
int FindMarker(FILE *infile, const char *marker)
Find a marker in a file.
Definition: mphell-util.c:167
uint32_t hex2bin(const char *in, unsigned char *out)
Convert an hexadecimal string into a binary string.
Definition: mphell-util.c:111
void hex_string2bytes(uint8_t *bytes_string, const char *hex_string, uint16_t length)
Convert the hexadecimal string "hex_string" under bytes string form.
Definition: mphell-util.c:78
void char2bin(char c, uint8_t *b)
Convert a character into a byte (according to its ascii value)
Definition: mphell-util.c:242
Wrap the config.h generated by configure.ac.
uint8_t bits_to_nblock(const uint16_t nbits)
Return the number of blocks required to store a nbits number.
Definition: mphell-util.c:29
unsigned int get_ns(struct timespec *start, struct timespec *end)
Return the elapsed time in nano second to add to the result of get_s().
Definition: mphell-util.c:48
void print_bytes_string_hex(const uint8_t *bytes_string, uint16_t length)
Print the byte string "bytes_string" under hexadecimal form.
Definition: mphell-util.c:58
uint8_t max_size(uint8_t a, uint8_t b)
Return the max of a and b.
Definition: mphell-util.c:34