| 1 | /* |
| 2 | * Copyright (C) 1998,1999,2001 Ross Combs ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #include "common/setup_before.h" |
| 19 | #include "common/bn_type.h" |
| 20 | |
| 21 | #include <cstdint> |
| 22 | #include <cstring> |
| 23 | |
| 24 | #include "common/eventlog.h" |
| 25 | #include "common/setup_after.h" |
| 26 | |
| 27 | |
| 28 | /************************************************************/ |
| 29 | |
| 30 | namespace pvpgn |
| 31 | { |
| 32 | |
| 33 | extern int bn_byte_tag_get(bn_byte const * src, char * dst, unsigned int len) |
| 34 | { |
| 35 | unsigned int i; |
| 36 | |
| 37 | if (!dst) |
| 38 | { |
| 39 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 40 | return -1; |
| 41 | } |
| 42 | if (!src) |
| 43 | { |
| 44 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 45 | return -1; |
| 46 | } |
| 47 | if (len < 1) |
| 48 | { |
| 49 | eventlog(eventlog_level_error, __FUNCTION__, "got zero len"); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | for (i = 0; i < len - 1 && i < 1; i++) |
| 54 | dst[i] = (char)(*src)[-i]; |
| 55 | dst[i] = '\0'; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | extern int bn_short_tag_get(bn_short const * src, char * dst, unsigned int len) |
| 62 | { |
| 63 | unsigned int i; |
| 64 | |
| 65 | if (!dst) |
| 66 | { |
| 67 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 68 | return -1; |
| 69 | } |
| 70 | if (!src) |
| 71 | { |
| 72 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 73 | return -1; |
| 74 | } |
| 75 | if (len < 1) |
| 76 | { |
| 77 | eventlog(eventlog_level_error, __FUNCTION__, "got zero len"); |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | for (i = 0; i < len - 1 && i < 2; i++) |
| 82 | dst[i] = (char)(*src)[1 - i]; |
| 83 | dst[i] = '\0'; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | extern int bn_int_tag_get(bn_int const * src, char * dst, unsigned int len) |
| 90 | { |
| 91 | unsigned int i; |
| 92 | |
| 93 | if (!dst) |
| 94 | { |
| 95 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 96 | return -1; |
| 97 | } |
| 98 | if (!src) |
| 99 | { |
| 100 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 101 | return -1; |
| 102 | } |
| 103 | if (len < 1) |
| 104 | { |
| 105 | eventlog(eventlog_level_error, __FUNCTION__, "got zero len"); |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | for (i = 0; i < len - 1 && i < 4; i++) |
| 110 | dst[i] = (char)(*src)[3 - i]; |
| 111 | dst[i] = '\0'; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | extern int bn_long_tag_get(bn_long const * src, char * dst, unsigned int len) |
| 118 | { |
| 119 | unsigned int i; |
| 120 | |
| 121 | if (!dst) |
| 122 | { |
| 123 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 124 | return -1; |
| 125 | } |
| 126 | if (!src) |
| 127 | { |
| 128 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 129 | return -1; |
| 130 | } |
| 131 | if (len < 1) |
| 132 | { |
| 133 | eventlog(eventlog_level_error, __FUNCTION__, "got zero len"); |
| 134 | return -1; |
| 135 | } |
| 136 | |
| 137 | for (i = 0; i < len - 1 && i < 8; i++) |
| 138 | dst[i] = (char)(*src)[7 - i]; |
| 139 | dst[i] = '\0'; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /************************************************************/ |
| 146 | |
| 147 | |
| 148 | extern int bn_byte_tag_set(bn_byte * dst, char const * tag) |
| 149 | { |
| 150 | if (!dst) |
| 151 | { |
| 152 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 153 | return -1; |
| 154 | } |
| 155 | if (!tag) |
| 156 | { |
| 157 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | (*dst)[0] = (unsigned char)tag[0]; |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | extern int bn_short_tag_set(bn_short * dst, char const * tag) |
| 167 | { |
| 168 | if (!dst) |
| 169 | { |
| 170 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 171 | return -1; |
| 172 | } |
| 173 | if (!tag) |
| 174 | { |
| 175 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 176 | return -1; |
| 177 | } |
| 178 | |
| 179 | (*dst)[0] = (unsigned char)tag[3]; |
| 180 | (*dst)[1] = (unsigned char)tag[2]; |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | extern int bn_int_tag_set(bn_int * dst, char const * tag) |
| 186 | { |
| 187 | if (!dst) |
| 188 | { |
| 189 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 190 | return -1; |
| 191 | } |
| 192 | if (!tag) |
| 193 | { |
| 194 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 195 | return -1; |
| 196 | } |
| 197 | |
| 198 | (*dst)[0] = (unsigned char)tag[3]; |
| 199 | (*dst)[1] = (unsigned char)tag[2]; |
| 200 | (*dst)[2] = (unsigned char)tag[1]; |
| 201 | (*dst)[3] = (unsigned char)tag[0]; |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | extern int bn_long_tag_set(bn_long * dst, char const * tag) |
| 207 | { |
| 208 | if (!dst) |
| 209 | { |
| 210 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 211 | return -1; |
| 212 | } |
| 213 | if (!tag) |
| 214 | { |
| 215 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | (*dst)[0] = (unsigned char)tag[7]; |
| 220 | (*dst)[1] = (unsigned char)tag[6]; |
| 221 | (*dst)[2] = (unsigned char)tag[5]; |
| 222 | (*dst)[3] = (unsigned char)tag[4]; |
| 223 | (*dst)[4] = (unsigned char)tag[3]; |
| 224 | (*dst)[5] = (unsigned char)tag[2]; |
| 225 | (*dst)[6] = (unsigned char)tag[1]; |
| 226 | (*dst)[7] = (unsigned char)tag[0]; |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /************************************************************/ |
| 232 | |
| 233 | |
| 234 | extern std::uint8_t bn_byte_get(bn_byte const src) |
| 235 | { |
| 236 | std::uint8_t temp; |
| 237 | |
| 238 | if (!src) |
| 239 | { |
| 240 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | temp = ((std::uint8_t)src[0]); |
| 245 | return temp; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | extern std::uint16_t bn_short_get(bn_short const src) |
| 250 | { |
| 251 | std::uint16_t temp; |
| 252 | |
| 253 | if (!src) |
| 254 | { |
| 255 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | temp = ((std::uint16_t)src[0]); |
| 260 | temp |= ((std::uint16_t)src[1]) << 8; |
| 261 | return temp; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | extern std::uint16_t bn_short_nget(bn_short const src) |
| 266 | { |
| 267 | std::uint16_t temp; |
| 268 | |
| 269 | if (!src) |
| 270 | { |
| 271 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | temp = ((std::uint16_t)src[1]); |
| 276 | temp |= ((std::uint16_t)src[0]) << 8; |
| 277 | return temp; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | extern std::uint32_t bn_int_get(bn_int const src) |
| 282 | { |
| 283 | std::uint32_t temp; |
| 284 | |
| 285 | if (!src) |
| 286 | { |
| 287 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | temp = ((std::uint32_t)src[0]); |
| 292 | temp |= ((std::uint32_t)src[1]) << 8; |
| 293 | temp |= ((std::uint32_t)src[2]) << 16; |
| 294 | temp |= ((std::uint32_t)src[3]) << 24; |
| 295 | return temp; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | extern std::uint32_t bn_int_nget(bn_int const src) |
| 300 | { |
| 301 | std::uint32_t temp; |
| 302 | |
| 303 | if (!src) |
| 304 | { |
| 305 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | temp = ((std::uint32_t)src[3]); |
| 310 | temp |= ((std::uint32_t)src[2]) << 8; |
| 311 | temp |= ((std::uint32_t)src[1]) << 16; |
| 312 | temp |= ((std::uint32_t)src[0]) << 24; |
| 313 | return temp; |
| 314 | } |
| 315 | |
| 316 | extern std::uint64_t bn_long_get(bn_long const src) |
| 317 | { |
| 318 | std::uint64_t temp; |
| 319 | |
| 320 | if (!src) |
| 321 | { |
| 322 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | temp = ((std::uint64_t)src[0]); |
| 327 | temp |= ((std::uint64_t)src[1]) << 8; |
| 328 | temp |= ((std::uint64_t)src[2]) << 16; |
| 329 | temp |= ((std::uint64_t)src[3]) << 24; |
| 330 | temp |= ((std::uint64_t)src[4]) << 32; |
| 331 | temp |= ((std::uint64_t)src[5]) << 40; |
| 332 | temp |= ((std::uint64_t)src[6]) << 48; |
| 333 | temp |= ((std::uint64_t)src[7]) << 56; |
| 334 | return temp; |
| 335 | } |
| 336 | |
| 337 | extern std::uint32_t bn_long_get_a(bn_long const src) |
| 338 | { |
| 339 | std::uint32_t temp; |
| 340 | |
| 341 | if (!src) |
| 342 | { |
| 343 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | temp = ((std::uint32_t)src[4]); |
| 348 | temp |= ((std::uint32_t)src[5]) << 8; |
| 349 | temp |= ((std::uint32_t)src[6]) << 16; |
| 350 | temp |= ((std::uint32_t)src[7]) << 24; |
| 351 | return temp; |
| 352 | } |
| 353 | |
| 354 | |
| 355 | extern std::uint32_t bn_long_get_b(bn_long const src) |
| 356 | { |
| 357 | std::uint32_t temp; |
| 358 | |
| 359 | if (!src) |
| 360 | { |
| 361 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | temp = ((std::uint32_t)src[0]); |
| 366 | temp |= ((std::uint32_t)src[1]) << 8; |
| 367 | temp |= ((std::uint32_t)src[2]) << 16; |
| 368 | temp |= ((std::uint32_t)src[3]) << 24; |
| 369 | return temp; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | /************************************************************/ |
| 374 | |
| 375 | |
| 376 | extern int bn_byte_set(bn_byte * dst, std::uint8_t src) |
| 377 | { |
| 378 | if (!dst) |
| 379 | { |
| 380 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 381 | return -1; |
| 382 | } |
| 383 | |
| 384 | (*dst)[0] = (std::uint8_t)((src)); |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | |
| 389 | extern int bn_short_set(bn_short * dst, std::uint16_t src) |
| 390 | { |
| 391 | if (!dst) |
| 392 | { |
| 393 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 394 | return -1; |
| 395 | } |
| 396 | |
| 397 | (*dst)[0] = (std::uint8_t)((src)& 0xff); |
| 398 | (*dst)[1] = (std::uint8_t)((src >> 8)); |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | |
| 403 | extern int bn_short_nset(bn_short * dst, std::uint16_t src) |
| 404 | { |
| 405 | if (!dst) |
| 406 | { |
| 407 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 408 | return -1; |
| 409 | } |
| 410 | |
| 411 | (*dst)[0] = (std::uint8_t)((src >> 8)); |
| 412 | (*dst)[1] = (std::uint8_t)((src)& 0xff); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | |
| 417 | extern int bn_int_set(bn_int * dst, std::uint32_t src) |
| 418 | { |
| 419 | if (!dst) |
| 420 | { |
| 421 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 422 | return -1; |
| 423 | } |
| 424 | |
| 425 | (*dst)[0] = (std::uint8_t)((src)& 0xff); |
| 426 | (*dst)[1] = (std::uint8_t)((src >> 8) & 0xff); |
| 427 | (*dst)[2] = (std::uint8_t)((src >> 16) & 0xff); |
| 428 | (*dst)[3] = (std::uint8_t)((src >> 24)); |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | extern int bn_int_nset(bn_int * dst, std::uint32_t src) |
| 434 | { |
| 435 | if (!dst) |
| 436 | { |
| 437 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 438 | return -1; |
| 439 | } |
| 440 | |
| 441 | (*dst)[0] = (std::uint8_t)((src >> 24)); |
| 442 | (*dst)[1] = (std::uint8_t)((src >> 16) & 0xff); |
| 443 | (*dst)[2] = (std::uint8_t)((src >> 8) & 0xff); |
| 444 | (*dst)[3] = (std::uint8_t)((src)& 0xff); |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | extern int bn_long_set(bn_long * dst, std::uint64_t src) |
| 449 | { |
| 450 | if (!dst) |
| 451 | { |
| 452 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 453 | return -1; |
| 454 | } |
| 455 | |
| 456 | (*dst)[0] = (std::uint8_t)((src)& 0xff); |
| 457 | (*dst)[1] = (std::uint8_t)((src >> 8) & 0xff); |
| 458 | (*dst)[2] = (std::uint8_t)((src >> 16) & 0xff); |
| 459 | (*dst)[3] = (std::uint8_t)((src >> 24) & 0xff); |
| 460 | (*dst)[4] = (std::uint8_t)((src >> 32) & 0xff); |
| 461 | (*dst)[5] = (std::uint8_t)((src >> 40) & 0xff); |
| 462 | (*dst)[6] = (std::uint8_t)((src >> 48) & 0xff); |
| 463 | (*dst)[7] = (std::uint8_t)((src >> 56)); |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | extern int bn_long_nset(bn_long * dst, std::uint64_t src) |
| 469 | { |
| 470 | if (!dst) |
| 471 | { |
| 472 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 473 | return -1; |
| 474 | } |
| 475 | |
| 476 | (*dst)[0] = (std::uint8_t)((src >> 56)); |
| 477 | (*dst)[1] = (std::uint8_t)((src >> 48) & 0xff); |
| 478 | (*dst)[2] = (std::uint8_t)((src >> 40) & 0xff); |
| 479 | (*dst)[3] = (std::uint8_t)((src >> 32) & 0xff); |
| 480 | (*dst)[4] = (std::uint8_t)((src >> 24) & 0xff); |
| 481 | (*dst)[5] = (std::uint8_t)((src >> 16) & 0xff); |
| 482 | (*dst)[6] = (std::uint8_t)((src >> 8) & 0xff); |
| 483 | (*dst)[7] = (std::uint8_t)((src)& 0xff); |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | extern int bn_long_set_a_b(bn_long * dst, std::uint32_t srca, std::uint32_t srcb) |
| 488 | { |
| 489 | if (!dst) |
| 490 | { |
| 491 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | (*dst)[0] = (std::uint8_t)((srcb)& 0xff); |
| 496 | (*dst)[1] = (std::uint8_t)((srcb >> 8) & 0xff); |
| 497 | (*dst)[2] = (std::uint8_t)((srcb >> 16) & 0xff); |
| 498 | (*dst)[3] = (std::uint8_t)((srcb >> 24) & 0xff); |
| 499 | (*dst)[4] = (std::uint8_t)((srca)& 0xff); |
| 500 | (*dst)[5] = (std::uint8_t)((srca >> 8) & 0xff); |
| 501 | (*dst)[6] = (std::uint8_t)((srca >> 16) & 0xff); |
| 502 | (*dst)[7] = (std::uint8_t)((srca >> 24)); |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | |
| 507 | extern int bn_long_nset_a_b(bn_long * dst, std::uint32_t srca, std::uint32_t srcb) |
| 508 | { |
| 509 | if (!dst) |
| 510 | { |
| 511 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 512 | return -1; |
| 513 | } |
| 514 | |
| 515 | (*dst)[0] = (std::uint8_t)((srca >> 24)); |
| 516 | (*dst)[1] = (std::uint8_t)((srca >> 16) & 0xff); |
| 517 | (*dst)[2] = (std::uint8_t)((srca >> 8) & 0xff); |
| 518 | (*dst)[3] = (std::uint8_t)((srca)& 0xff); |
| 519 | (*dst)[4] = (std::uint8_t)((srcb >> 24) & 0xff); |
| 520 | (*dst)[5] = (std::uint8_t)((srcb >> 16) & 0xff); |
| 521 | (*dst)[6] = (std::uint8_t)((srcb >> 8) & 0xff); |
| 522 | (*dst)[7] = (std::uint8_t)((srcb)& 0xff); |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | |
| 527 | /************************************************************/ |
| 528 | |
| 529 | |
| 530 | extern int bn_raw_set(void * dst, void const * src, unsigned int len) |
| 531 | { |
| 532 | if (!dst) |
| 533 | { |
| 534 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst"); |
| 535 | return -1; |
| 536 | } |
| 537 | if (!src) |
| 538 | { |
| 539 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 540 | return -1; |
| 541 | } |
| 542 | |
| 543 | std::memcpy(dst, src, len); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | /************************************************************/ |
| 549 | |
| 550 | |
| 551 | extern int bn_byte_tag_eq(bn_byte const src, char const * tag) |
| 552 | { |
| 553 | bn_byte temp; |
| 554 | |
| 555 | if (!src) |
| 556 | { |
| 557 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 558 | return -1; |
| 559 | } |
| 560 | if (!tag) |
| 561 | { |
| 562 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 563 | return -1; |
| 564 | } |
| 565 | |
| 566 | if (bn_byte_tag_set(&temp, tag) < 0) |
| 567 | return -1; |
| 568 | if (bn_byte_get(src) == bn_byte_get(temp)) |
| 569 | return 0; |
| 570 | |
| 571 | return -1; |
| 572 | } |
| 573 | |
| 574 | |
| 575 | extern int bn_short_tag_eq(bn_short const src, char const * tag) |
| 576 | { |
| 577 | bn_short temp; |
| 578 | |
| 579 | if (!src) |
| 580 | { |
| 581 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 582 | return -1; |
| 583 | } |
| 584 | if (!tag) |
| 585 | { |
| 586 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 587 | return -1; |
| 588 | } |
| 589 | |
| 590 | if (bn_short_tag_set(&temp, tag) < 0) |
| 591 | return -1; |
| 592 | if (bn_short_get(src) == bn_short_get(temp)) |
| 593 | return 0; |
| 594 | |
| 595 | return -1; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | extern int bn_int_tag_eq(bn_int const src, char const * tag) |
| 600 | { |
| 601 | bn_int temp; |
| 602 | |
| 603 | if (!src) |
| 604 | { |
| 605 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 606 | return -1; |
| 607 | } |
| 608 | if (!tag) |
| 609 | { |
| 610 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 611 | return -1; |
| 612 | } |
| 613 | |
| 614 | if (bn_int_tag_set(&temp, tag) < 0) |
| 615 | return -1; |
| 616 | if (bn_int_get(src) == bn_int_get(temp)) |
| 617 | return 0; |
| 618 | |
| 619 | return -1; |
| 620 | } |
| 621 | |
| 622 | |
| 623 | extern int bn_long_tag_eq(bn_long const src, char const * tag) |
| 624 | { |
| 625 | bn_long temp; |
| 626 | |
| 627 | if (!src) |
| 628 | { |
| 629 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL src"); |
| 630 | return -1; |
| 631 | } |
| 632 | if (!tag) |
| 633 | { |
| 634 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL tag"); |
| 635 | return -1; |
| 636 | } |
| 637 | |
| 638 | if (bn_long_tag_set(&temp, tag) < 0) |
| 639 | return -1; |
| 640 | if (bn_long_get_a(src) == bn_long_get_a(temp) && |
| 641 | bn_long_get_b(src) == bn_long_get_b(temp)) |
| 642 | return 0; |
| 643 | |
| 644 | return -1; |
| 645 | } |
| 646 | |
| 647 | |
| 648 | /************************************************************/ |
| 649 | |
| 650 | |
| 651 | extern int uint32_to_int(std::uint32_t num) |
| 652 | { |
| 653 | if (num < (1UL << 30)) |
| 654 | return (int)num; |
| 655 | return (-(int)((~(num)) + 1)); |
| 656 | } |
| 657 | |
| 658 | } |