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