Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 4 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 5 | * Macros for storing and retrieving data in msb first and lsb first order. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 6 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 7 | * As far as I am concerned, the code I have written for this software |
| 8 | * can be used freely for any purpose. Any derived versions of this |
| 9 | * software must be clearly marked as such, and if the derived work is |
| 10 | * incompatible with the protocol description in the RFC file, it must be |
| 11 | * called by a name other than "ssh" or "Secure Shell". |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 12 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 13 | |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 14 | /* RCSID("$OpenBSD: getput.h,v 1.6 2000/12/19 23:17:56 markus Exp $"); */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 15 | |
| 16 | #ifndef GETPUT_H |
| 17 | #define GETPUT_H |
| 18 | |
| 19 | /*------------ macros for storing/extracting msb first words -------------*/ |
| 20 | |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 21 | #define GET_32BIT(cp) (((u_long)(u_char)(cp)[0] << 24) | \ |
| 22 | ((u_long)(u_char)(cp)[1] << 16) | \ |
| 23 | ((u_long)(u_char)(cp)[2] << 8) | \ |
| 24 | ((u_long)(u_char)(cp)[3])) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 25 | |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 26 | #define GET_16BIT(cp) (((u_long)(u_char)(cp)[0] << 8) | \ |
| 27 | ((u_long)(u_char)(cp)[1])) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 28 | |
| 29 | #define PUT_32BIT(cp, value) do { \ |
| 30 | (cp)[0] = (value) >> 24; \ |
| 31 | (cp)[1] = (value) >> 16; \ |
| 32 | (cp)[2] = (value) >> 8; \ |
| 33 | (cp)[3] = (value); } while (0) |
| 34 | |
| 35 | #define PUT_16BIT(cp, value) do { \ |
| 36 | (cp)[0] = (value) >> 8; \ |
| 37 | (cp)[1] = (value); } while (0) |
| 38 | |
| 39 | /*------------ macros for storing/extracting lsb first words -------------*/ |
| 40 | |
| 41 | #define GET_32BIT_LSB_FIRST(cp) \ |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 42 | (((u_long)(u_char)(cp)[0]) | \ |
| 43 | ((u_long)(u_char)(cp)[1] << 8) | \ |
| 44 | ((u_long)(u_char)(cp)[2] << 16) | \ |
| 45 | ((u_long)(u_char)(cp)[3] << 24)) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 46 | |
| 47 | #define GET_16BIT_LSB_FIRST(cp) \ |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 48 | (((u_long)(u_char)(cp)[0]) | \ |
| 49 | ((u_long)(u_char)(cp)[1] << 8)) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 50 | |
| 51 | #define PUT_32BIT_LSB_FIRST(cp, value) do { \ |
| 52 | (cp)[0] = (value); \ |
| 53 | (cp)[1] = (value) >> 8; \ |
| 54 | (cp)[2] = (value) >> 16; \ |
| 55 | (cp)[3] = (value) >> 24; } while (0) |
| 56 | |
| 57 | #define PUT_16BIT_LSB_FIRST(cp, value) do { \ |
| 58 | (cp)[0] = (value); \ |
| 59 | (cp)[1] = (value) >> 8; } while (0) |
| 60 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 61 | #endif /* GETPUT_H */ |