1 /* 2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL license (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #ifndef OPENSSL_HEADER_DECREPIT_MACROS_H 11 #define OPENSSL_HEADER_DECREPIT_MACROS_H 12 13 #include "../crypto/internal.h" 14 15 16 // NOTE - c is not incremented as per n2l 17 #define n2ln(c, l1, l2, n) \ 18 { \ 19 c += n; \ 20 l1 = l2 = 0; \ 21 switch (n) { \ 22 case 8: \ 23 l2 = ((uint32_t)(*(--(c)))); \ 24 [[fallthrough]]; \ 25 case 7: \ 26 l2 |= ((uint32_t)(*(--(c)))) << 8; \ 27 [[fallthrough]]; \ 28 case 6: \ 29 l2 |= ((uint32_t)(*(--(c)))) << 16; \ 30 [[fallthrough]]; \ 31 case 5: \ 32 l2 |= ((uint32_t)(*(--(c)))) << 24; \ 33 [[fallthrough]]; \ 34 case 4: \ 35 l1 = ((uint32_t)(*(--(c)))); \ 36 [[fallthrough]]; \ 37 case 3: \ 38 l1 |= ((uint32_t)(*(--(c)))) << 8; \ 39 [[fallthrough]]; \ 40 case 2: \ 41 l1 |= ((uint32_t)(*(--(c)))) << 16; \ 42 [[fallthrough]]; \ 43 case 1: \ 44 l1 |= ((uint32_t)(*(--(c)))) << 24; \ 45 } \ 46 } 47 48 // NOTE - c is not incremented as per l2n 49 #define l2nn(l1, l2, c, n) \ 50 { \ 51 c += n; \ 52 switch (n) { \ 53 case 8: \ 54 *(--(c)) = (unsigned char)(((l2)) & 0xff); \ 55 [[fallthrough]]; \ 56 case 7: \ 57 *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \ 58 [[fallthrough]]; \ 59 case 6: \ 60 *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \ 61 [[fallthrough]]; \ 62 case 5: \ 63 *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \ 64 [[fallthrough]]; \ 65 case 4: \ 66 *(--(c)) = (unsigned char)(((l1)) & 0xff); \ 67 [[fallthrough]]; \ 68 case 3: \ 69 *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \ 70 [[fallthrough]]; \ 71 case 2: \ 72 *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \ 73 [[fallthrough]]; \ 74 case 1: \ 75 *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \ 76 } \ 77 } 78 79 #define l2n(l, c) \ 80 (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \ 81 *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \ 82 *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \ 83 *((c)++) = (unsigned char)(((l)) & 0xff)) 84 85 #define n2l(c, l) \ 86 (l = ((uint32_t)(*((c)++))) << 24L, l |= ((uint32_t)(*((c)++))) << 16L, \ 87 l |= ((uint32_t)(*((c)++))) << 8L, l |= ((uint32_t)(*((c)++)))) 88 89 90 #endif // OPENSSL_HEADER_DECREPIT_MACROS_H 91