| OLD | NEW |
| 1 /* | 1 /* |
| 2 * datatypes.h | 2 * datatypes.h |
| 3 * | 3 * |
| 4 * data types for bit vectors and finite fields | 4 * data types for bit vectors and finite fields |
| 5 * | 5 * |
| 6 * David A. McGrew | 6 * David A. McGrew |
| 7 * Cisco Systems, Inc. | 7 * Cisco Systems, Inc. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /* | 10 /* |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 # elif defined HAVE_BYTESWAP_METHODS_H | 63 # elif defined HAVE_BYTESWAP_METHODS_H |
| 64 # include <stdlib.h> | 64 # include <stdlib.h> |
| 65 # define ntohl(x) _byteswap_ulong (x) | 65 # define ntohl(x) _byteswap_ulong (x) |
| 66 # define ntohs(x) _byteswap_ushort (x) | 66 # define ntohs(x) _byteswap_ushort (x) |
| 67 # define htonl(x) _byteswap_ulong (x) | 67 # define htonl(x) _byteswap_ulong (x) |
| 68 # define htons(x) _byteswap_ushort (x) | 68 # define htons(x) _byteswap_ushort (x) |
| 69 # endif | 69 # endif |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 | 72 |
| 73 | |
| 74 /* if DATATYPES_USE_MACROS is defined, then little functions are macros */ | 73 /* if DATATYPES_USE_MACROS is defined, then little functions are macros */ |
| 75 #define DATATYPES_USE_MACROS | 74 #define DATATYPES_USE_MACROS |
| 76 | 75 |
| 77 typedef union { | 76 typedef union { |
| 78 uint8_t v8[2]; | 77 uint8_t v8[2]; |
| 79 uint16_t value; | 78 uint16_t value; |
| 80 } v16_t; | 79 } v16_t; |
| 81 | 80 |
| 82 typedef union { | 81 typedef union { |
| 83 uint8_t v8[4]; | 82 uint8_t v8[4]; |
| 84 uint16_t v16[2]; | 83 uint16_t v16[2]; |
| 85 uint32_t value; | 84 uint32_t value; |
| 86 } v32_t; | 85 } v32_t; |
| 87 | 86 |
| 88 typedef union { | 87 typedef union { |
| 89 uint8_t v8[8]; | 88 uint8_t v8[8]; |
| 90 uint16_t v16[4]; | 89 uint16_t v16[4]; |
| 91 uint32_t v32[2]; | 90 uint32_t v32[2]; |
| 92 uint64_t value; | 91 uint64_t value; |
| 93 } v64_t; | 92 } v64_t; |
| 94 | 93 |
| 95 typedef union { | 94 typedef union { |
| 96 uint8_t v8[16]; | 95 uint8_t v8[16]; |
| 97 uint16_t v16[8]; | 96 uint16_t v16[8]; |
| 98 uint32_t v32[4]; | 97 uint32_t v32[4]; |
| 99 uint64_t v64[2]; | 98 uint64_t v64[2]; |
| 100 } v128_t; | 99 } v128_t; |
| 101 | 100 |
| 101 typedef union { |
| 102 uint8_t v8[32]; |
| 103 uint16_t v16[16]; |
| 104 uint32_t v32[8]; |
| 105 uint64_t v64[4]; |
| 106 } v256_t; |
| 102 | 107 |
| 103 | 108 |
| 104 /* some useful and simple math functions */ | 109 /* some useful and simple math functions */ |
| 105 | 110 |
| 106 #define pow_2(X) ( (unsigned int)1 << (X) ) /* 2^X */ | 111 #define pow_2(X) ( (unsigned int)1 << (X) ) /* 2^X */ |
| 107 | 112 |
| 108 #define pow_minus_one(X) ( (X) ? -1 : 1 ) /* (-1)^X */ | 113 #define pow_minus_one(X) ( (X) ? -1 : 1 ) /* (-1)^X */ |
| 109 | 114 |
| 110 | 115 |
| 111 /* | 116 /* |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 * and b are not equal, returns 0 otherwise | 382 * and b are not equal, returns 0 otherwise |
| 378 */ | 383 */ |
| 379 | 384 |
| 380 int | 385 int |
| 381 octet_string_is_eq(uint8_t *a, uint8_t *b, int len); | 386 octet_string_is_eq(uint8_t *a, uint8_t *b, int len); |
| 382 | 387 |
| 383 void | 388 void |
| 384 octet_string_set_to_zero(uint8_t *s, int len); | 389 octet_string_set_to_zero(uint8_t *s, int len); |
| 385 | 390 |
| 386 | 391 |
| 387 #ifndef SRTP_KERNEL_LINUX | 392 #if !defined(SRTP_KERNEL_LINUX) //&& defined(HAVE_CONFIG_H) |
| 388 | 393 |
| 389 /* | 394 /* |
| 390 * Convert big endian integers to CPU byte order. | 395 * Convert big endian integers to CPU byte order. |
| 391 */ | 396 */ |
| 392 #ifdef WORDS_BIGENDIAN | 397 #ifdef WORDS_BIGENDIAN |
| 393 /* Nothing to do. */ | 398 /* Nothing to do. */ |
| 394 # define be32_to_cpu(x) (x) | 399 # define be32_to_cpu(x) (x) |
| 395 # define be64_to_cpu(x) (x) | 400 # define be64_to_cpu(x) (x) |
| 396 #elif defined(HAVE_BYTESWAP_H) | 401 #elif defined(HAVE_BYTESWAP_H) |
| 397 /* We have (hopefully) optimized versions in byteswap.h */ | 402 /* We have (hopefully) optimized versions in byteswap.h */ |
| 398 # include <byteswap.h> | 403 # include <byteswap.h> |
| 399 # define be32_to_cpu(x) bswap_32((x)) | 404 # define be32_to_cpu(x) bswap_32((x)) |
| 400 # define be64_to_cpu(x) bswap_64((x)) | 405 # define be64_to_cpu(x) bswap_64((x)) |
| 401 #else | 406 #else |
| 402 | 407 |
| 403 #if defined(__GNUC__) && defined(HAVE_X86) | 408 #if defined(__GNUC__) && defined(HAVE_X86) |
| 404 /* Fall back. */ | 409 /* Fall back. */ |
| 405 static INLINE uint32_t be32_to_cpu(uint32_t v) { | 410 static inline uint32_t be32_to_cpu(uint32_t v) { |
| 406 /* optimized for x86. */ | 411 /* optimized for x86. */ |
| 407 asm("bswap %0" : "=r" (v) : "0" (v)); | 412 asm("bswap %0" : "=r" (v) : "0" (v)); |
| 408 return v; | 413 return v; |
| 409 } | 414 } |
| 410 # else /* HAVE_X86 */ | 415 # else /* HAVE_X86 */ |
| 411 # ifdef HAVE_NETINET_IN_H | 416 # ifdef HAVE_NETINET_IN_H |
| 412 # include <netinet/in.h> | 417 # include <netinet/in.h> |
| 413 # elif defined HAVE_WINSOCK2_H | 418 # elif defined HAVE_WINSOCK2_H |
| 414 # include <winsock2.h> | 419 # include <winsock2.h> |
| 415 # endif | 420 # endif |
| 416 # define be32_to_cpu(x) ntohl((x)) | 421 # define be32_to_cpu(x) ntohl((x)) |
| 417 # endif /* HAVE_X86 */ | 422 # endif /* HAVE_X86 */ |
| 418 | 423 |
| 419 static INLINE uint64_t be64_to_cpu(uint64_t v) { | 424 static inline uint64_t be64_to_cpu(uint64_t v) { |
| 420 # ifdef NO_64BIT_MATH | 425 # ifdef NO_64BIT_MATH |
| 421 /* use the make64 functions to do 64-bit math */ | 426 /* use the make64 functions to do 64-bit math */ |
| 422 v = make64(htonl(low32(v)),htonl(high32(v))); | 427 v = make64(htonl(low32(v)),htonl(high32(v))); |
| 423 # else | 428 # else |
| 424 /* use the native 64-bit math */ | 429 /* use the native 64-bit math */ |
| 425 v= (uint64_t)((be32_to_cpu((uint32_t)(v >> 32))) | (((uint64_t)be32_to_cpu((u
int32_t)v)) << 32)); | 430 v= (uint64_t)((be32_to_cpu((uint32_t)(v >> 32))) | (((uint64_t)be32_to_cpu((u
int32_t)v)) << 32)); |
| 426 # endif | 431 # endif |
| 427 return v; | 432 return v; |
| 428 } | 433 } |
| 429 | 434 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 508 |
| 504 void | 509 void |
| 505 bitvector_set_to_zero(bitvector_t *x); | 510 bitvector_set_to_zero(bitvector_t *x); |
| 506 | 511 |
| 507 void | 512 void |
| 508 bitvector_left_shift(bitvector_t *x, int index); | 513 bitvector_left_shift(bitvector_t *x, int index); |
| 509 | 514 |
| 510 char * | 515 char * |
| 511 bitvector_bit_string(bitvector_t *x, char* buf, int len); | 516 bitvector_bit_string(bitvector_t *x, char* buf, int len); |
| 512 | 517 |
| 518 #ifdef TESTAPP_SOURCE |
| 519 int base64_string_to_octet_string(char *raw, int *pad, char *base64, int len); |
| 520 #endif |
| 521 |
| 513 #endif /* _DATATYPES_H */ | 522 #endif /* _DATATYPES_H */ |
| OLD | NEW |