xref: /titanic_50/usr/src/cmd/ssh/include/getput.h (revision 174bc6499d233e329ecd3d98a880a7b07df16bfa)
1 /*	$OpenBSD: getput.h,v 1.8 2002/03/04 17:27:39 stevesk Exp $	*/
2 
3 #ifndef	_GETPUT_H
4 #define	_GETPUT_H
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 
13 /*
14  * Author: Tatu Ylonen <ylo@cs.hut.fi>
15  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
16  *                    All rights reserved
17  * Macros for storing and retrieving data in msb first and lsb first order.
18  *
19  * As far as I am concerned, the code I have written for this software
20  * can be used freely for any purpose.  Any derived versions of this
21  * software must be clearly marked as such, and if the derived work is
22  * incompatible with the protocol description in the RFC file, it must be
23  * called by a name other than "ssh" or "Secure Shell".
24  */
25 
26 /*------------ macros for storing/extracting msb first words -------------*/
27 
28 #define GET_64BIT(cp) (((u_int64_t)(u_char)(cp)[0] << 56) | \
29 		       ((u_int64_t)(u_char)(cp)[1] << 48) | \
30 		       ((u_int64_t)(u_char)(cp)[2] << 40) | \
31 		       ((u_int64_t)(u_char)(cp)[3] << 32) | \
32 		       ((u_int64_t)(u_char)(cp)[4] << 24) | \
33 		       ((u_int64_t)(u_char)(cp)[5] << 16) | \
34 		       ((u_int64_t)(u_char)(cp)[6] << 8) | \
35 		       ((u_int64_t)(u_char)(cp)[7]))
36 
37 #define GET_32BIT(cp) (((u_long)(u_char)(cp)[0] << 24) | \
38 		       ((u_long)(u_char)(cp)[1] << 16) | \
39 		       ((u_long)(u_char)(cp)[2] << 8) | \
40 		       ((u_long)(u_char)(cp)[3]))
41 
42 #define GET_16BIT(cp) (((u_long)(u_char)(cp)[0] << 8) | \
43 		       ((u_long)(u_char)(cp)[1]))
44 
45 #define PUT_64BIT(cp, value) do { \
46   (cp)[0] = (value) >> 56; \
47   (cp)[1] = (value) >> 48; \
48   (cp)[2] = (value) >> 40; \
49   (cp)[3] = (value) >> 32; \
50   (cp)[4] = (value) >> 24; \
51   (cp)[5] = (value) >> 16; \
52   (cp)[6] = (value) >> 8; \
53   (cp)[7] = (value); } while (0)
54 
55 #define PUT_32BIT(cp, value) do { \
56   (cp)[0] = (value) >> 24; \
57   (cp)[1] = (value) >> 16; \
58   (cp)[2] = (value) >> 8; \
59   (cp)[3] = (value); } while (0)
60 
61 #define PUT_16BIT(cp, value) do { \
62   (cp)[0] = (value) >> 8; \
63   (cp)[1] = (value); } while (0)
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif /* _GETPUT_H */
70