| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_DECREPIT_MACROS_H |
| 16 | #define OPENSSL_HEADER_DECREPIT_MACROS_H |
| 17 |
| 18 | #include "../crypto/internal.h" |
| 19 |
| 20 |
| 21 | // NOTE - c is not incremented as per n2l |
| 22 | #define n2ln(c, l1, l2, n) \ |
| 23 | { \ |
| 24 | c += n; \ |
| 25 | l1 = l2 = 0; \ |
| 26 | switch (n) { \ |
| 27 | case 8: \ |
| 28 | l2 = ((uint32_t)(*(--(c)))); \ |
| 29 | [[fallthrough]]; \ |
| 30 | case 7: \ |
| 31 | l2 |= ((uint32_t)(*(--(c)))) << 8; \ |
| 32 | [[fallthrough]]; \ |
| 33 | case 6: \ |
| 34 | l2 |= ((uint32_t)(*(--(c)))) << 16; \ |
| 35 | [[fallthrough]]; \ |
| 36 | case 5: \ |
| 37 | l2 |= ((uint32_t)(*(--(c)))) << 24; \ |
| 38 | [[fallthrough]]; \ |
| 39 | case 4: \ |
| 40 | l1 = ((uint32_t)(*(--(c)))); \ |
| 41 | [[fallthrough]]; \ |
| 42 | case 3: \ |
| 43 | l1 |= ((uint32_t)(*(--(c)))) << 8; \ |
| 44 | [[fallthrough]]; \ |
| 45 | case 2: \ |
| 46 | l1 |= ((uint32_t)(*(--(c)))) << 16; \ |
| 47 | [[fallthrough]]; \ |
| 48 | case 1: \ |
| 49 | l1 |= ((uint32_t)(*(--(c)))) << 24; \ |
| 50 | } \ |
| 51 | } |
| 52 |
| 53 | // NOTE - c is not incremented as per l2n |
| 54 | #define l2nn(l1, l2, c, n) \ |
| 55 | { \ |
| 56 | c += n; \ |
| 57 | switch (n) { \ |
| 58 | case 8: \ |
| 59 | *(--(c)) = (unsigned char)(((l2)) & 0xff); \ |
| 60 | [[fallthrough]]; \ |
| 61 | case 7: \ |
| 62 | *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \ |
| 63 | [[fallthrough]]; \ |
| 64 | case 6: \ |
| 65 | *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \ |
| 66 | [[fallthrough]]; \ |
| 67 | case 5: \ |
| 68 | *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \ |
| 69 | [[fallthrough]]; \ |
| 70 | case 4: \ |
| 71 | *(--(c)) = (unsigned char)(((l1)) & 0xff); \ |
| 72 | [[fallthrough]]; \ |
| 73 | case 3: \ |
| 74 | *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \ |
| 75 | [[fallthrough]]; \ |
| 76 | case 2: \ |
| 77 | *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \ |
| 78 | [[fallthrough]]; \ |
| 79 | case 1: \ |
| 80 | *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \ |
| 81 | } \ |
| 82 | } |
| 83 |
| 84 | #define l2n(l, c) \ |
| 85 | (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \ |
| 86 | *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \ |
| 87 | *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \ |
| 88 | *((c)++) = (unsigned char)(((l)) & 0xff)) |
| 89 |
| 90 | #define n2l(c, l) \ |
| 91 | (l = ((uint32_t)(*((c)++))) << 24L, l |= ((uint32_t)(*((c)++))) << 16L, \ |
| 92 | l |= ((uint32_t)(*((c)++))) << 8L, l |= ((uint32_t)(*((c)++)))) |
| 93 |
| 94 |
| 95 | #endif // OPENSSL_HEADER_DECREPIT_MACROS_H |
| 96 |