| * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. |
| * Licensed under the Apache License 2.0 (the "License"). You may not use |
| * this file except in compliance with the License. You can obtain a copy |
| * in the file LICENSE in the source distribution or at |
| * https://www.openssl.org/source/license.html |
| #include "internal/cryptlib.h" |
| int BN_bn2mpi(const BIGNUM *a, unsigned char *d) |
| ext = ((bits & 0x07) == 0); |
| d[0] = (unsigned char)(l >> 24) & 0xff; |
| d[1] = (unsigned char)(l >> 16) & 0xff; |
| d[2] = (unsigned char)(l >> 8) & 0xff; |
| d[3] = (unsigned char)(l) & 0xff; |
| num = BN_bn2bin(a, &(d[4 + ext])); |
| BIGNUM *BN_mpi2bn(const unsigned char *d, int n, BIGNUM *ain) |
| if (n < 4 || (d[0] & 0x80) != 0) { |
| ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH); |
| len = ((long)d[0] << 24) | ((long)d[1] << 16) | ((int)d[2] << 8) | (int) |
| ERR_raise(ERR_LIB_BN, BN_R_ENCODING_ERROR); |
| if (BN_bin2bn(d, (int)len, a) == NULL) { |
| BN_clear_bit(a, BN_num_bits(a) - 1); |