forked from dple/ecdsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
81 lines (60 loc) · 1.31 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* utils.h
*
* Created on: Apr 14, 2011
* Author: dple
*/
#ifndef UTILS_H_
#define UTILS_H_
/*
* Useful functions for integer
*/
char trapkey(void);
int getNumber();
// Accepts a decimal integer and returns a binary coded string
char* dectobin(long i);
// Show a decimal number in binary
void showbits(int h);
// Count the number of 1-bits, the Hamming weight for an integer
int hammingWeight(unsigned int n);
// Count the number of bits
int bitcount(unsigned int n);
// If the bit at position pos is 1, function return true. Else return false
bool bit(int n, int pos);
// Extract a chain of bit from a number n
int extract(int n, int tail, int size);
/*
* Useful functions for gmp integers
*/
int bitlength(mpz_t x);
bool mod_is_zero(mpz_t x, mpz_t mod);
/*
#ifndef __linux__
#undef USE_GMP
#endif
#ifdef USE_GMP
#include <gmpxx.h>
#endif
#ifdef _MSC_VER
typedef unsigned __int64 uint64;
typedef __int64 sint64;
#else
typedef unsigned long long uint64;
typedef long long sint64;
#endif
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
*/
/*
#ifdef _WIN32
#include <time.h>
static inline double GetCurrTime();
#else
#include <sys/time.h>
#include <stdio.h>
static inline double GetCurrTime();
#endif
static inline uint64 getRdtsc();
*/
#endif /* UTILS_H_ */