* copy vendor drop to trunk
[lab.git] / Dev / utvpn / utvpn-unix-v101-7101-public / src / Mayaqua / openssl / pq_compat.h
1 /* crypto/pqueue/pqueue_compat.h */\r
2 /* \r
3  * DTLS implementation written by Nagendra Modadugu\r
4  * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  \r
5  */\r
6 /* ====================================================================\r
7  * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.\r
8  *\r
9  * Redistribution and use in source and binary forms, with or without\r
10  * modification, are permitted provided that the following conditions\r
11  * are met:\r
12  *\r
13  * 1. Redistributions of source code must retain the above copyright\r
14  *    notice, this list of conditions and the following disclaimer. \r
15  *\r
16  * 2. Redistributions in binary form must reproduce the above copyright\r
17  *    notice, this list of conditions and the following disclaimer in\r
18  *    the documentation and/or other materials provided with the\r
19  *    distribution.\r
20  *\r
21  * 3. All advertising materials mentioning features or use of this\r
22  *    software must display the following acknowledgment:\r
23  *    "This product includes software developed by the OpenSSL Project\r
24  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
25  *\r
26  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
27  *    endorse or promote products derived from this software without\r
28  *    prior written permission. For written permission, please contact\r
29  *    openssl-core@OpenSSL.org.\r
30  *\r
31  * 5. Products derived from this software may not be called "OpenSSL"\r
32  *    nor may "OpenSSL" appear in their names without prior written\r
33  *    permission of the OpenSSL Project.\r
34  *\r
35  * 6. Redistributions of any form whatsoever must retain the following\r
36  *    acknowledgment:\r
37  *    "This product includes software developed by the OpenSSL Project\r
38  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
39  *\r
40  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
41  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
43  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
44  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
46  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
47  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
49  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
51  * OF THE POSSIBILITY OF SUCH DAMAGE.\r
52  * ====================================================================\r
53  *\r
54  * This product includes cryptographic software written by Eric Young\r
55  * (eay@cryptsoft.com).  This product includes software written by Tim\r
56  * Hudson (tjh@cryptsoft.com).\r
57  *\r
58  */\r
59 \r
60 #include "opensslconf.h"\r
61 #include <openssl/bn.h>\r
62 \r
63 /* \r
64  * The purpose of this header file is for supporting 64-bit integer\r
65  * manipulation on 32-bit (and lower) machines.  Currently the only\r
66  * such environment is VMS, Utrix and those with smaller default integer\r
67  * sizes than 32 bits.  For all such environment, we fall back to using\r
68  * BIGNUM.  We may need to fine tune the conditions for systems that\r
69  * are incorrectly configured.\r
70  *\r
71  * The only clients of this code are (1) pqueue for priority, and\r
72  * (2) DTLS, for sequence number manipulation.\r
73  */\r
74 \r
75 #if (defined(THIRTY_TWO_BIT) && !defined(BN_LLONG)) || defined(SIXTEEN_BIT) || defined(EIGHT_BIT)\r
76 \r
77 #define PQ_64BIT_IS_INTEGER 0\r
78 #define PQ_64BIT_IS_BIGNUM 1\r
79 \r
80 #define PQ_64BIT     BIGNUM\r
81 #define PQ_64BIT_CTX BN_CTX\r
82 \r
83 #define pq_64bit_init(x)           BN_init(x)\r
84 #define pq_64bit_free(x)           BN_free(x)\r
85 \r
86 #define pq_64bit_ctx_new(ctx)      BN_CTX_new()\r
87 #define pq_64bit_ctx_free(x)       BN_CTX_free(x)\r
88 \r
89 #define pq_64bit_assign(x, y)      BN_copy(x, y)\r
90 #define pq_64bit_assign_word(x, y) BN_set_word(x, y)\r
91 #define pq_64bit_gt(x, y)          BN_ucmp(x, y) >= 1 ? 1 : 0\r
92 #define pq_64bit_eq(x, y)          BN_ucmp(x, y) == 0 ? 1 : 0\r
93 #define pq_64bit_add_word(x, w)    BN_add_word(x, w)\r
94 #define pq_64bit_sub(r, x, y)      BN_sub(r, x, y)\r
95 #define pq_64bit_sub_word(x, w)    BN_sub_word(x, w)\r
96 #define pq_64bit_mod(r, x, n, ctx) BN_mod(r, x, n, ctx)\r
97 \r
98 #define pq_64bit_bin2num(bn, bytes, len)   BN_bin2bn(bytes, len, bn)\r
99 #define pq_64bit_num2bin(bn, bytes)        BN_bn2bin(bn, bytes)\r
100 #define pq_64bit_get_word(x)               BN_get_word(x)\r
101 #define pq_64bit_is_bit_set(x, offset)     BN_is_bit_set(x, offset)\r
102 #define pq_64bit_lshift(r, x, shift)       BN_lshift(r, x, shift)\r
103 #define pq_64bit_set_bit(x, num)           BN_set_bit(x, num)\r
104 #define pq_64bit_get_length(x)             BN_num_bits((x))\r
105 \r
106 #else\r
107 \r
108 #define PQ_64BIT_IS_INTEGER 1\r
109 #define PQ_64BIT_IS_BIGNUM 0\r
110 \r
111 #if defined(SIXTY_FOUR_BIT)\r
112 #define PQ_64BIT BN_ULONG\r
113 #define PQ_64BIT_PRINT "%lld"\r
114 #elif defined(SIXTY_FOUR_BIT_LONG)\r
115 #define PQ_64BIT BN_ULONG\r
116 #define PQ_64BIT_PRINT "%ld"\r
117 #elif defined(THIRTY_TWO_BIT)\r
118 #define PQ_64BIT BN_ULLONG\r
119 #define PQ_64BIT_PRINT "%lld"\r
120 #endif\r
121 \r
122 #define PQ_64BIT_CTX      void\r
123 \r
124 #define pq_64bit_init(x)\r
125 #define pq_64bit_free(x)\r
126 #define pq_64bit_ctx_new(ctx)        (ctx)\r
127 #define pq_64bit_ctx_free(x)\r
128 \r
129 #define pq_64bit_assign(x, y)        (*(x) = *(y))\r
130 #define pq_64bit_assign_word(x, y)   (*(x) = y)\r
131 #define pq_64bit_gt(x, y)                (*(x) > *(y))\r
132 #define pq_64bit_eq(x, y)            (*(x) == *(y))\r
133 #define pq_64bit_add_word(x, w)      (*(x) = (*(x) + (w)))\r
134 #define pq_64bit_sub(r, x, y)        (*(r) = (*(x) - *(y)))\r
135 #define pq_64bit_sub_word(x, w)      (*(x) = (*(x) - (w)))\r
136 #define pq_64bit_mod(r, x, n, ctx)\r
137 \r
138 #define pq_64bit_bin2num(num, bytes, len) bytes_to_long_long(bytes, num)\r
139 #define pq_64bit_num2bin(num, bytes)      long_long_to_bytes(num, bytes)\r
140 #define pq_64bit_get_word(x)              *(x)\r
141 #define pq_64bit_lshift(r, x, shift)      (*(r) = (*(x) << (shift)))\r
142 #define pq_64bit_set_bit(x, num)          do { \\r
143                                               PQ_64BIT mask = 1; \\r
144                                               mask = mask << (num); \\r
145                                               *(x) |= mask; \\r
146                                           } while(0)\r
147 #endif /* OPENSSL_SYS_VMS */\r