# Conflicts: # opendbc # panda # selfdrive/car/volkswagen/carstate.pypull/81/head
commit
e229c4db71
182 changed files with 1364 additions and 31915 deletions
@ -1 +1 @@ |
||||
Subproject commit 6eb3994daa0f64f57a36606a7bdd982ed2ac9d2d |
||||
Subproject commit 29f4fe89ef710ff86a5aeb998a357187d0619fb8 |
@ -1 +1 @@ |
||||
Subproject commit e47ba47de2ad62f3c31cfdffa5aa381557a45d08 |
||||
Subproject commit 226adc655e1488474468a97ab4a7705aad7e5837 |
@ -0,0 +1,6 @@ |
||||
#!/usr/bin/bash |
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" |
||||
|
||||
export FINGERPRINT="TOYOTA COROLLA TSS2 2019" |
||||
$DIR/../launch_openpilot.sh |
@ -0,0 +1,9 @@ |
||||
#!/usr/bin/env python3 |
||||
import numpy as np |
||||
from selfdrive.hardware.tici.power_monitor import sample_power |
||||
|
||||
if __name__ == '__main__': |
||||
print("measuring for 5 seconds") |
||||
for _ in range(3): |
||||
pwrs = sample_power() |
||||
print("mean %.2f std %.2f" % (np.mean(pwrs), np.std(pwrs))) |
@ -0,0 +1,61 @@ |
||||
#!/usr/bin/env python3 |
||||
import unittest |
||||
import time |
||||
import math |
||||
from collections import OrderedDict |
||||
|
||||
from selfdrive.hardware import HARDWARE, TICI |
||||
from selfdrive.hardware.tici.power_monitor import get_power |
||||
from selfdrive.manager.process_config import managed_processes |
||||
from selfdrive.manager.manager import manager_cleanup |
||||
|
||||
POWER = OrderedDict( |
||||
camerad=2.58, |
||||
modeld=0.90, |
||||
dmonitoringmodeld=0.25, |
||||
loggerd=0.45, |
||||
) |
||||
|
||||
|
||||
class TestPowerDraw(unittest.TestCase): |
||||
|
||||
@classmethod |
||||
def setUpClass(cls): |
||||
if not TICI: |
||||
raise unittest.SkipTest |
||||
|
||||
def setUp(self): |
||||
HARDWARE.initialize_hardware() |
||||
HARDWARE.set_power_save(False) |
||||
|
||||
def tearDown(self): |
||||
manager_cleanup() |
||||
|
||||
def test_camera_procs(self): |
||||
baseline = get_power() |
||||
|
||||
prev = baseline |
||||
used = {} |
||||
for proc in POWER.keys(): |
||||
managed_processes[proc].start() |
||||
time.sleep(6) |
||||
|
||||
now = get_power(8) |
||||
used[proc] = now - prev |
||||
prev = now |
||||
|
||||
manager_cleanup() |
||||
|
||||
print("-"*35) |
||||
print(f"Baseline {baseline:.2f}W\n") |
||||
for proc in POWER.keys(): |
||||
cur = used[proc] |
||||
expected = POWER[proc] |
||||
print(f"{proc.ljust(20)} {expected:.2f}W {cur:.2f}W") |
||||
with self.subTest(proc=proc): |
||||
self.assertTrue(math.isclose(cur, expected, rel_tol=0.10, abs_tol=0.1)) |
||||
print("-"*35) |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
unittest.main() |
@ -0,0 +1,118 @@ |
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
||||
|
||||
#include <cassert> |
||||
#include <cstdlib> |
||||
|
||||
#include "selfdrive/loggerd/video_writer.h" |
||||
#include "selfdrive/common/swaglog.h" |
||||
#include "selfdrive/common/util.h" |
||||
|
||||
VideoWriter::VideoWriter(const char *path, const char *filename, bool remuxing, int width, int height, int fps, bool h265, bool raw) |
||||
: remuxing(remuxing), raw(raw) { |
||||
vid_path = util::string_format("%s/%s", path, filename); |
||||
lock_path = util::string_format("%s/%s.lock", path, filename); |
||||
|
||||
int lock_fd = HANDLE_EINTR(open(lock_path.c_str(), O_RDWR | O_CREAT, 0664)); |
||||
assert(lock_fd >= 0); |
||||
close(lock_fd); |
||||
|
||||
LOGD("encoder_open %s remuxing:%d", this->vid_path.c_str(), this->remuxing); |
||||
if (this->remuxing) { |
||||
avformat_alloc_output_context2(&this->ofmt_ctx, NULL, raw ? "matroska" : NULL, this->vid_path.c_str()); |
||||
assert(this->ofmt_ctx); |
||||
|
||||
// set codec correctly. needed?
|
||||
av_register_all(); |
||||
|
||||
AVCodec *codec = NULL; |
||||
assert(!h265); |
||||
codec = avcodec_find_encoder(raw ? AV_CODEC_ID_FFVHUFF : AV_CODEC_ID_H264); |
||||
assert(codec); |
||||
|
||||
this->codec_ctx = avcodec_alloc_context3(codec); |
||||
assert(this->codec_ctx); |
||||
this->codec_ctx->width = width; |
||||
this->codec_ctx->height = height; |
||||
this->codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; |
||||
this->codec_ctx->time_base = (AVRational){ 1, fps }; |
||||
|
||||
if (raw) { |
||||
// since the codec is actually used, we open it
|
||||
int err = avcodec_open2(this->codec_ctx, codec, NULL); |
||||
assert(err >= 0); |
||||
} |
||||
|
||||
this->out_stream = avformat_new_stream(this->ofmt_ctx, raw ? codec : NULL); |
||||
assert(this->out_stream); |
||||
|
||||
int err = avio_open(&this->ofmt_ctx->pb, this->vid_path.c_str(), AVIO_FLAG_WRITE); |
||||
assert(err >= 0); |
||||
|
||||
this->wrote_codec_config = false; |
||||
} else { |
||||
this->of = util::safe_fopen(this->vid_path.c_str(), "wb"); |
||||
assert(this->of); |
||||
} |
||||
} |
||||
|
||||
void VideoWriter::write(uint8_t *data, int len, long long timestamp, bool codecconfig, bool keyframe) { |
||||
if (of && data) { |
||||
size_t written = util::safe_fwrite(data, 1, len, of); |
||||
if (written != len) { |
||||
LOGE("failed to write file.errno=%d", errno); |
||||
} |
||||
} |
||||
|
||||
if (remuxing) { |
||||
if (codecconfig) { |
||||
if (data) { |
||||
codec_ctx->extradata = (uint8_t*)av_mallocz(len + AV_INPUT_BUFFER_PADDING_SIZE); |
||||
codec_ctx->extradata_size = len; |
||||
memcpy(codec_ctx->extradata, data, len); |
||||
} |
||||
int err = avcodec_parameters_from_context(out_stream->codecpar, codec_ctx); |
||||
assert(err >= 0); |
||||
err = avformat_write_header(ofmt_ctx, NULL); |
||||
assert(err >= 0); |
||||
} else { |
||||
// input timestamps are in microseconds
|
||||
AVRational in_timebase = {1, 1000000}; |
||||
|
||||
AVPacket pkt; |
||||
av_init_packet(&pkt); |
||||
pkt.data = data; |
||||
pkt.size = len; |
||||
|
||||
enum AVRounding rnd = static_cast<enum AVRounding>(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); |
||||
pkt.pts = pkt.dts = av_rescale_q_rnd(timestamp, in_timebase, ofmt_ctx->streams[0]->time_base, rnd); |
||||
pkt.duration = av_rescale_q(50*1000, in_timebase, ofmt_ctx->streams[0]->time_base); |
||||
|
||||
if (keyframe) { |
||||
pkt.flags |= AV_PKT_FLAG_KEY; |
||||
} |
||||
|
||||
// TODO: can use av_write_frame for non raw?
|
||||
int err = av_interleaved_write_frame(ofmt_ctx, &pkt); |
||||
if (err < 0) { LOGW("ts encoder write issue"); } |
||||
|
||||
av_free_packet(&pkt); |
||||
} |
||||
} |
||||
} |
||||
|
||||
VideoWriter::~VideoWriter() { |
||||
if (this->remuxing) { |
||||
if (this->raw) { avcodec_close(this->codec_ctx); } |
||||
int err = av_write_trailer(this->ofmt_ctx); |
||||
if (err != 0) LOGE("av_write_trailer failed %d", err); |
||||
avcodec_free_context(&this->codec_ctx); |
||||
err = avio_closep(&this->ofmt_ctx->pb); |
||||
if (err != 0) LOGE("avio_closep failed %d", err); |
||||
avformat_free_context(this->ofmt_ctx); |
||||
} else { |
||||
util::safe_fflush(this->of); |
||||
fclose(this->of); |
||||
this->of = nullptr; |
||||
} |
||||
unlink(this->lock_path.c_str()); |
||||
} |
@ -0,0 +1,25 @@ |
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
extern "C" { |
||||
#include <libavformat/avformat.h> |
||||
} |
||||
|
||||
class VideoWriter { |
||||
public: |
||||
VideoWriter(const char *path, const char *filename, bool remuxing, int width, int height, int fps, bool h265, bool raw); |
||||
void write(uint8_t *data, int len, long long timestamp, bool codecconfig, bool keyframe); |
||||
~VideoWriter(); |
||||
AVCodecContext *codec_ctx; |
||||
private: |
||||
std::string vid_path, lock_path; |
||||
|
||||
FILE *of = nullptr; |
||||
|
||||
AVFormatContext *ofmt_ctx; |
||||
AVStream *out_stream; |
||||
bool remuxing, raw; |
||||
|
||||
bool wrote_codec_config; |
||||
}; |
@ -1 +1 @@ |
||||
ea48ff4478914b6aff56a979a647fe13b4993711 |
||||
8d369bed132b691e1c000a726ab253ce7cbf8e09 |
@ -1,274 +0,0 @@ |
||||
BoringSSL is a fork of OpenSSL. As such, large parts of it fall under OpenSSL |
||||
licensing. Files that are completely new have a Google copyright and an ISC |
||||
license. This license is reproduced at the bottom of this file. |
||||
|
||||
Contributors to BoringSSL are required to follow the CLA rules for Chromium: |
||||
https://cla.developers.google.com/clas |
||||
|
||||
Files in third_party/ have their own licenses, as described therein. The MIT |
||||
license, for third_party/fiat, which, unlike other third_party directories, is |
||||
compiled into non-test libraries, is included below. |
||||
|
||||
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of the |
||||
OpenSSL License and the original SSLeay license apply to the toolkit. See below |
||||
for the actual license texts. Actually both licenses are BSD-style Open Source |
||||
licenses. In case of any license issues related to OpenSSL please contact |
||||
openssl-core@openssl.org. |
||||
|
||||
The following are Google-internal bug numbers where explicit permission from |
||||
some authors is recorded for use of their work. (This is purely for our own |
||||
record keeping.) |
||||
27287199 |
||||
27287880 |
||||
27287883 |
||||
|
||||
OpenSSL License |
||||
--------------- |
||||
|
||||
/* ==================================================================== |
||||
* Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* 3. All advertising materials mentioning features or use of this |
||||
* software must display the following acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
||||
* |
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
||||
* endorse or promote products derived from this software without |
||||
* prior written permission. For written permission, please contact |
||||
* openssl-core@openssl.org. |
||||
* |
||||
* 5. Products derived from this software may not be called "OpenSSL" |
||||
* nor may "OpenSSL" appear in their names without prior written |
||||
* permission of the OpenSSL Project. |
||||
* |
||||
* 6. Redistributions of any form whatsoever must retain the following |
||||
* acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
||||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* ==================================================================== |
||||
* |
||||
* This product includes cryptographic software written by Eric Young |
||||
* (eay@cryptsoft.com). This product includes software written by Tim |
||||
* Hudson (tjh@cryptsoft.com). |
||||
* |
||||
*/ |
||||
|
||||
Original SSLeay License |
||||
----------------------- |
||||
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] |
||||
*/ |
||||
|
||||
|
||||
ISC license used for completely new code in BoringSSL: |
||||
|
||||
/* Copyright (c) 2015, Google Inc. |
||||
* |
||||
* Permission to use, copy, modify, and/or distribute this software for any |
||||
* purpose with or without fee is hereby granted, provided that the above |
||||
* copyright notice and this permission notice appear in all copies. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
||||
|
||||
|
||||
The code in third_party/fiat carries the MIT license: |
||||
|
||||
Copyright (c) 2015-2016 the fiat-crypto authors (see |
||||
https://github.com/mit-plv/fiat-crypto/blob/master/AUTHORS). |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
||||
|
||||
|
||||
The code in third_party/sike also carries the MIT license: |
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved. |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE |
||||
|
||||
|
||||
Licenses for support code |
||||
------------------------- |
||||
|
||||
Parts of the TLS test suite are under the Go license. This code is not included |
||||
in BoringSSL (i.e. libcrypto and libssl) when compiled, however, so |
||||
distributing code linked against BoringSSL does not trigger this license: |
||||
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved. |
||||
|
||||
Redistribution and use in source and binary forms, with or without |
||||
modification, are permitted provided that the following conditions are |
||||
met: |
||||
|
||||
* Redistributions of source code must retain the above copyright |
||||
notice, this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above |
||||
copyright notice, this list of conditions and the following disclaimer |
||||
in the documentation and/or other materials provided with the |
||||
distribution. |
||||
* Neither the name of Google Inc. nor the names of its |
||||
contributors may be used to endorse or promote products derived from |
||||
this software without specific prior written permission. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
|
||||
BoringSSL uses the Chromium test infrastructure to run a continuous build, |
||||
trybots etc. The scripts which manage this, and the script for generating build |
||||
metadata, are under the Chromium license. Distributing code linked against |
||||
BoringSSL does not trigger this license. |
||||
|
||||
Copyright 2015 The Chromium Authors. All rights reserved. |
||||
|
||||
Redistribution and use in source and binary forms, with or without |
||||
modification, are permitted provided that the following conditions are |
||||
met: |
||||
|
||||
* Redistributions of source code must retain the above copyright |
||||
notice, this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above |
||||
copyright notice, this list of conditions and the following disclaimer |
||||
in the documentation and/or other materials provided with the |
||||
distribution. |
||||
* Neither the name of Google Inc. nor the names of its |
||||
contributors may be used to endorse or promote products derived from |
||||
this software without specific prior written permission. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
@ -1,192 +0,0 @@ |
||||
BoringSSL is a fork of OpenSSL. As such, large parts of it fall under OpenSSL |
||||
licensing. Files that are completely new have a Google copyright and an ISC |
||||
license. This license is reproduced at the bottom of this file. |
||||
|
||||
Contributors to BoringSSL are required to follow the CLA rules for Chromium: |
||||
https://cla.developers.google.com/clas |
||||
|
||||
Some files from Intel are under yet another license, which is also included |
||||
underneath. |
||||
|
||||
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of the |
||||
OpenSSL License and the original SSLeay license apply to the toolkit. See below |
||||
for the actual license texts. Actually both licenses are BSD-style Open Source |
||||
licenses. In case of any license issues related to OpenSSL please contact |
||||
openssl-core@openssl.org. |
||||
|
||||
The following are Google-internal bug numbers where explicit permission from |
||||
some authors is recorded for use of their work. (This is purely for our own |
||||
record keeping.) |
||||
27287199 |
||||
27287880 |
||||
27287883 |
||||
|
||||
OpenSSL License |
||||
--------------- |
||||
|
||||
/* ==================================================================== |
||||
* Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* 3. All advertising materials mentioning features or use of this |
||||
* software must display the following acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
||||
* |
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
||||
* endorse or promote products derived from this software without |
||||
* prior written permission. For written permission, please contact |
||||
* openssl-core@openssl.org. |
||||
* |
||||
* 5. Products derived from this software may not be called "OpenSSL" |
||||
* nor may "OpenSSL" appear in their names without prior written |
||||
* permission of the OpenSSL Project. |
||||
* |
||||
* 6. Redistributions of any form whatsoever must retain the following |
||||
* acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
||||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* ==================================================================== |
||||
* |
||||
* This product includes cryptographic software written by Eric Young |
||||
* (eay@cryptsoft.com). This product includes software written by Tim |
||||
* Hudson (tjh@cryptsoft.com). |
||||
* |
||||
*/ |
||||
|
||||
Original SSLeay License |
||||
----------------------- |
||||
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] |
||||
*/ |
||||
|
||||
|
||||
ISC license used for completely new code in BoringSSL: |
||||
|
||||
/* Copyright (c) 2015, Google Inc. |
||||
* |
||||
* Permission to use, copy, modify, and/or distribute this software for any |
||||
* purpose with or without fee is hereby granted, provided that the above |
||||
* copyright notice and this permission notice appear in all copies. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
||||
|
||||
|
||||
Some files from Intel carry the following license: |
||||
|
||||
# Copyright (c) 2012, Intel Corporation |
||||
# |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# |
||||
# * Redistributions in binary form must reproduce the above copyright |
||||
# notice, this list of conditions and the following disclaimer in the |
||||
# documentation and/or other materials provided with the |
||||
# distribution. |
||||
# |
||||
# * Neither the name of the Intel Corporation nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION ""AS IS"" AND ANY |
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR |
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
@ -1,7 +0,0 @@ |
||||
# with neos tree |
||||
cd ~/android/system |
||||
mka libcrypt_static libssl_static |
||||
|
||||
cp ~/android/system/out/target/product/oneplus3/obj/STATIC_LIBRARIES/libcrypto_static_intermediates/libcrypto_static.a lib/ |
||||
cp ~/android/system/out/target/product/oneplus3/obj/STATIC_LIBRARIES/libssl_static_intermediates/libssl_static.a lib/ |
||||
|
@ -1,315 +0,0 @@ |
||||
/* Copyright (c) 2014, Google Inc.
|
||||
* |
||||
* Permission to use, copy, modify, and/or distribute this software for any |
||||
* purpose with or without fee is hereby granted, provided that the above |
||||
* copyright notice and this permission notice appear in all copies. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
||||
|
||||
#ifndef OPENSSL_HEADER_AEAD_H |
||||
#define OPENSSL_HEADER_AEAD_H |
||||
|
||||
#include <openssl/base.h> |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* Authenticated Encryption with Additional Data.
|
||||
* |
||||
* AEAD couples confidentiality and integrity in a single primtive. AEAD |
||||
* algorithms take a key and then can seal and open individual messages. Each |
||||
* message has a unique, per-message nonce and, optionally, additional data |
||||
* which is authenticated but not included in the ciphertext. |
||||
* |
||||
* The |EVP_AEAD_CTX_init| function initialises an |EVP_AEAD_CTX| structure and |
||||
* performs any precomputation needed to use |aead| with |key|. The length of |
||||
* the key, |key_len|, is given in bytes. |
||||
* |
||||
* The |tag_len| argument contains the length of the tags, in bytes, and allows |
||||
* for the processing of truncated authenticators. A zero value indicates that |
||||
* the default tag length should be used and this is defined as |
||||
* |EVP_AEAD_DEFAULT_TAG_LENGTH| in order to make the code clear. Using |
||||
* truncated tags increases an attacker's chance of creating a valid forgery. |
||||
* Be aware that the attacker's chance may increase more than exponentially as |
||||
* would naively be expected. |
||||
* |
||||
* When no longer needed, the initialised |EVP_AEAD_CTX| structure must be |
||||
* passed to |EVP_AEAD_CTX_cleanup|, which will deallocate any memory used. |
||||
* |
||||
* With an |EVP_AEAD_CTX| in hand, one can seal and open messages. These |
||||
* operations are intended to meet the standard notions of privacy and |
||||
* authenticity for authenticated encryption. For formal definitions see |
||||
* Bellare and Namprempre, "Authenticated encryption: relations among notions |
||||
* and analysis of the generic composition paradigm," Lecture Notes in Computer |
||||
* Science B<1976> (2000), 531–545, |
||||
* http://www-cse.ucsd.edu/~mihir/papers/oem.html.
|
||||
* |
||||
* When sealing messages, a nonce must be given. The length of the nonce is |
||||
* fixed by the AEAD in use and is returned by |EVP_AEAD_nonce_length|. *The |
||||
* nonce must be unique for all messages with the same key*. This is critically |
||||
* important - nonce reuse may completely undermine the security of the AEAD. |
||||
* Nonces may be predictable and public, so long as they are unique. Uniqueness |
||||
* may be achieved with a simple counter or, if large enough, may be generated |
||||
* randomly. The nonce must be passed into the "open" operation by the receiver |
||||
* so must either be implicit (e.g. a counter), or must be transmitted along |
||||
* with the sealed message. |
||||
* |
||||
* The "seal" and "open" operations are atomic - an entire message must be |
||||
* encrypted or decrypted in a single call. Large messages may have to be split |
||||
* up in order to accomodate this. When doing so, be mindful of the need not to |
||||
* repeat nonces and the possibility that an attacker could duplicate, reorder |
||||
* or drop message chunks. For example, using a single key for a given (large) |
||||
* message and sealing chunks with nonces counting from zero would be secure as |
||||
* long as the number of chunks was securely transmitted. (Otherwise an |
||||
* attacker could truncate the message by dropping chunks from the end.) |
||||
* |
||||
* The number of chunks could be transmitted by prefixing it to the plaintext, |
||||
* for example. This also assumes that no other message would ever use the same |
||||
* key otherwise the rule that nonces must be unique for a given key would be |
||||
* violated. |
||||
* |
||||
* The "seal" and "open" operations also permit additional data to be |
||||
* authenticated via the |ad| parameter. This data is not included in the |
||||
* ciphertext and must be identical for both the "seal" and "open" call. This |
||||
* permits implicit context to be authenticated but may be empty if not needed. |
||||
* |
||||
* The "seal" and "open" operations may work in-place if the |out| and |in| |
||||
* arguments are equal. They may also be used to shift the data left inside the |
||||
* same buffer if |out| is less than |in|. However, |out| may not point inside |
||||
* the input data otherwise the input may be overwritten before it has been |
||||
* read. This situation will cause an error. |
||||
* |
||||
* The "seal" and "open" operations return one on success and zero on error. */ |
||||
|
||||
|
||||
/* AEAD algorithms. */ |
||||
|
||||
/* EVP_aead_aes_128_gcm is AES-128 in Galois Counter Mode. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm(void); |
||||
|
||||
/* EVP_aead_aes_256_gcm is AES-256 in Galois Counter Mode. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm(void); |
||||
|
||||
/* EVP_aead_chacha20_poly1305 is an AEAD built from ChaCha20 and Poly1305. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_chacha20_poly1305(void); |
||||
|
||||
/* EVP_aead_aes_128_key_wrap is AES-128 Key Wrap mode. This should never be
|
||||
* used except to interoperate with existing systems that use this mode. |
||||
* |
||||
* If the nonce is empty then the default nonce will be used, otherwise it must |
||||
* be eight bytes long. The input must be a multiple of eight bytes long. No |
||||
* additional data can be given to this mode. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_key_wrap(void); |
||||
|
||||
/* EVP_aead_aes_256_key_wrap is AES-256 in Key Wrap mode. This should never be
|
||||
* used except to interoperate with existing systems that use this mode. |
||||
* |
||||
* See |EVP_aead_aes_128_key_wrap| for details. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_key_wrap(void); |
||||
|
||||
/* EVP_aead_aes_128_ctr_hmac_sha256 is AES-128 in CTR mode with HMAC-SHA256 for
|
||||
* authentication. The nonce is 12 bytes; the bottom 32-bits are used as the |
||||
* block counter, thus the maximum plaintext size is 64GB. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ctr_hmac_sha256(void); |
||||
|
||||
/* EVP_aead_aes_128_ctr_hmac_sha256 is AES-256 in CTR mode with HMAC-SHA256 for
|
||||
* authentication. See |EVP_aead_aes_128_ctr_hmac_sha256| for details. */ |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_ctr_hmac_sha256(void); |
||||
|
||||
/* EVP_has_aes_hardware returns one if we enable hardware support for fast and
|
||||
* constant-time AES-GCM. */ |
||||
OPENSSL_EXPORT int EVP_has_aes_hardware(void); |
||||
|
||||
|
||||
/* TLS-specific AEAD algorithms.
|
||||
* |
||||
* These AEAD primitives do not meet the definition of generic AEADs. They are |
||||
* all specific to TLS and should not be used outside of that context. They must |
||||
* be initialized with |EVP_AEAD_CTX_init_with_direction|, are stateful, and may |
||||
* not be used concurrently. Any nonces are used as IVs, so they must be |
||||
* unpredictable. They only accept an |ad| parameter of length 11 (the standard |
||||
* TLS one with length omitted). */ |
||||
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_rc4_md5_tls(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_rc4_sha1_tls(void); |
||||
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls(void); |
||||
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha256_tls(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha384_tls(void); |
||||
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(void); |
||||
|
||||
|
||||
/* SSLv3-specific AEAD algorithms.
|
||||
* |
||||
* These AEAD primitives do not meet the definition of generic AEADs. They are |
||||
* all specific to SSLv3 and should not be used outside of that context. They |
||||
* must be initialized with |EVP_AEAD_CTX_init_with_direction|, are stateful, |
||||
* and may not be used concurrently. They only accept an |ad| parameter of |
||||
* length 9 (the standard TLS one with length and version omitted). */ |
||||
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_rc4_md5_ssl3(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_rc4_sha1_ssl3(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_ssl3(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_ssl3(void); |
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_ssl3(void); |
||||
|
||||
|
||||
/* Utility functions. */ |
||||
|
||||
/* EVP_AEAD_key_length returns the length, in bytes, of the keys used by
|
||||
* |aead|. */ |
||||
OPENSSL_EXPORT size_t EVP_AEAD_key_length(const EVP_AEAD *aead); |
||||
|
||||
/* EVP_AEAD_nonce_length returns the length, in bytes, of the per-message nonce
|
||||
* for |aead|. */ |
||||
OPENSSL_EXPORT size_t EVP_AEAD_nonce_length(const EVP_AEAD *aead); |
||||
|
||||
/* EVP_AEAD_max_overhead returns the maximum number of additional bytes added
|
||||
* by the act of sealing data with |aead|. */ |
||||
OPENSSL_EXPORT size_t EVP_AEAD_max_overhead(const EVP_AEAD *aead); |
||||
|
||||
/* EVP_AEAD_max_tag_len returns the maximum tag length when using |aead|. This
|
||||
* is the largest value that can be passed as |tag_len| to |
||||
* |EVP_AEAD_CTX_init|. */ |
||||
OPENSSL_EXPORT size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead); |
||||
|
||||
|
||||
/* AEAD operations. */ |
||||
|
||||
/* An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key
|
||||
* and message-independent IV. */ |
||||
typedef struct evp_aead_ctx_st { |
||||
const EVP_AEAD *aead; |
||||
/* aead_state is an opaque pointer to whatever state the AEAD needs to
|
||||
* maintain. */ |
||||
void *aead_state; |
||||
} EVP_AEAD_CTX; |
||||
|
||||
/* EVP_AEAD_MAX_KEY_LENGTH contains the maximum key length used by
|
||||
* any AEAD defined in this header. */ |
||||
#define EVP_AEAD_MAX_KEY_LENGTH 80 |
||||
|
||||
/* EVP_AEAD_MAX_NONCE_LENGTH contains the maximum nonce length used by
|
||||
* any AEAD defined in this header. */ |
||||
#define EVP_AEAD_MAX_NONCE_LENGTH 16 |
||||
|
||||
/* EVP_AEAD_MAX_OVERHEAD contains the maximum overhead used by any AEAD
|
||||
* defined in this header. */ |
||||
#define EVP_AEAD_MAX_OVERHEAD 64 |
||||
|
||||
/* EVP_AEAD_DEFAULT_TAG_LENGTH is a magic value that can be passed to
|
||||
* EVP_AEAD_CTX_init to indicate that the default tag length for an AEAD should |
||||
* be used. */ |
||||
#define EVP_AEAD_DEFAULT_TAG_LENGTH 0 |
||||
|
||||
/* evp_aead_direction_t denotes the direction of an AEAD operation. */ |
||||
enum evp_aead_direction_t { |
||||
evp_aead_open, |
||||
evp_aead_seal, |
||||
}; |
||||
|
||||
/* EVP_AEAD_CTX_init initializes |ctx| for the given AEAD algorithm from |impl|.
|
||||
* The |impl| argument may be NULL to choose the default implementation. |
||||
* Authentication tags may be truncated by passing a size as |tag_len|. A |
||||
* |tag_len| of zero indicates the default tag length and this is defined as |
||||
* EVP_AEAD_DEFAULT_TAG_LENGTH for readability. |
||||
* |
||||
* Returns 1 on success. Otherwise returns 0 and pushes to the error stack. In |
||||
* the error case, you do not need to call |EVP_AEAD_CTX_cleanup|, but it's |
||||
* harmless to do so. */ |
||||
OPENSSL_EXPORT int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, |
||||
const uint8_t *key, size_t key_len, |
||||
size_t tag_len, ENGINE *impl); |
||||
|
||||
/* EVP_AEAD_CTX_init_with_direction calls |EVP_AEAD_CTX_init| for normal
|
||||
* AEADs. For TLS-specific and SSL3-specific AEADs, it initializes |ctx| for a |
||||
* given direction. */ |
||||
OPENSSL_EXPORT int EVP_AEAD_CTX_init_with_direction( |
||||
EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, const uint8_t *key, size_t key_len, |
||||
size_t tag_len, enum evp_aead_direction_t dir); |
||||
|
||||
/* EVP_AEAD_CTX_cleanup frees any data allocated by |ctx|. It is a no-op to
|
||||
* call |EVP_AEAD_CTX_cleanup| on a |EVP_AEAD_CTX| that has been |memset| to |
||||
* all zeros. */ |
||||
OPENSSL_EXPORT void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx); |
||||
|
||||
/* EVP_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and
|
||||
* authenticates |ad_len| bytes from |ad| and writes the result to |out|. It |
||||
* returns one on success and zero otherwise. |
||||
* |
||||
* This function may be called (with the same |EVP_AEAD_CTX|) concurrently with |
||||
* itself or |EVP_AEAD_CTX_open|. |
||||
* |
||||
* At most |max_out_len| bytes are written to |out| and, in order to ensure |
||||
* success, |max_out_len| should be |in_len| plus the result of |
||||
* |EVP_AEAD_max_overhead|. On successful return, |*out_len| is set to the |
||||
* actual number of bytes written. |
||||
* |
||||
* The length of |nonce|, |nonce_len|, must be equal to the result of |
||||
* |EVP_AEAD_nonce_length| for this AEAD. |
||||
* |
||||
* |EVP_AEAD_CTX_seal| never results in a partial output. If |max_out_len| is |
||||
* insufficient, zero will be returned. (In this case, |*out_len| is set to |
||||
* zero.) |
||||
* |
||||
* If |in| and |out| alias then |out| must be <= |in|. */ |
||||
OPENSSL_EXPORT int EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, uint8_t *out, |
||||
size_t *out_len, size_t max_out_len, |
||||
const uint8_t *nonce, size_t nonce_len, |
||||
const uint8_t *in, size_t in_len, |
||||
const uint8_t *ad, size_t ad_len); |
||||
|
||||
/* EVP_AEAD_CTX_open authenticates |in_len| bytes from |in| and |ad_len| bytes
|
||||
* from |ad| and decrypts at most |in_len| bytes into |out|. It returns one on |
||||
* success and zero otherwise. |
||||
* |
||||
* This function may be called (with the same |EVP_AEAD_CTX|) concurrently with |
||||
* itself or |EVP_AEAD_CTX_seal|. |
||||
* |
||||
* At most |in_len| bytes are written to |out|. In order to ensure success, |
||||
* |max_out_len| should be at least |in_len|. On successful return, |*out_len| |
||||
* is set to the the actual number of bytes written. |
||||
* |
||||
* The length of |nonce|, |nonce_len|, must be equal to the result of |
||||
* |EVP_AEAD_nonce_length| for this AEAD. |
||||
* |
||||
* |EVP_AEAD_CTX_open| never results in a partial output. If |max_out_len| is |
||||
* insufficient, zero will be returned. (In this case, |*out_len| is set to |
||||
* zero.) |
||||
* |
||||
* If |in| and |out| alias then |out| must be <= |in|. */ |
||||
OPENSSL_EXPORT int EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, uint8_t *out, |
||||
size_t *out_len, size_t max_out_len, |
||||
const uint8_t *nonce, size_t nonce_len, |
||||
const uint8_t *in, size_t in_len, |
||||
const uint8_t *ad, size_t ad_len); |
||||
|
||||
|
||||
/* Obscure functions. */ |
||||
|
||||
/* EVP_AEAD_CTX_get_rc4_state sets |*out_key| to point to an RC4 key structure.
|
||||
* It returns one on success or zero if |ctx| doesn't have an RC4 key. */ |
||||
OPENSSL_EXPORT int EVP_AEAD_CTX_get_rc4_state(const EVP_AEAD_CTX *ctx, |
||||
const RC4_KEY **out_key); |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#endif /* OPENSSL_HEADER_AEAD_H */ |
@ -1,158 +0,0 @@ |
||||
/* ====================================================================
|
||||
* Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* 3. All advertising materials mentioning features or use of this |
||||
* software must display the following acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
* |
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
||||
* endorse or promote products derived from this software without |
||||
* prior written permission. For written permission, please contact |
||||
* openssl-core@openssl.org. |
||||
* |
||||
* 5. Products derived from this software may not be called "OpenSSL" |
||||
* nor may "OpenSSL" appear in their names without prior written |
||||
* permission of the OpenSSL Project. |
||||
* |
||||
* 6. Redistributions of any form whatsoever must retain the following |
||||
* acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
||||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* ==================================================================== */ |
||||
|
||||
#ifndef OPENSSL_HEADER_AES_H |
||||
#define OPENSSL_HEADER_AES_H |
||||
|
||||
#include <openssl/base.h> |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* Raw AES functions. */ |
||||
|
||||
|
||||
#define AES_ENCRYPT 1 |
||||
#define AES_DECRYPT 0 |
||||
|
||||
/* AES_MAXNR is the maximum number of AES rounds. */ |
||||
#define AES_MAXNR 14 |
||||
|
||||
#define AES_BLOCK_SIZE 16 |
||||
|
||||
/* aes_key_st should be an opaque type, but EVP requires that the size be
|
||||
* known. */ |
||||
struct aes_key_st { |
||||
uint32_t rd_key[4 * (AES_MAXNR + 1)]; |
||||
unsigned rounds; |
||||
}; |
||||
typedef struct aes_key_st AES_KEY; |
||||
|
||||
/* AES_set_encrypt_key configures |aeskey| to encrypt with the |bits|-bit key,
|
||||
* |key|. |
||||
* |
||||
* WARNING: unlike other OpenSSL functions, this returns zero on success and a |
||||
* negative number on error. */ |
||||
OPENSSL_EXPORT int AES_set_encrypt_key(const uint8_t *key, unsigned bits, |
||||
AES_KEY *aeskey); |
||||
|
||||
/* AES_set_decrypt_key configures |aeskey| to decrypt with the |bits|-bit key,
|
||||
* |key|. |
||||
* |
||||
* WARNING: unlike other OpenSSL functions, this returns zero on success and a |
||||
* negative number on error. */ |
||||
OPENSSL_EXPORT int AES_set_decrypt_key(const uint8_t *key, unsigned bits, |
||||
AES_KEY *aeskey); |
||||
|
||||
/* AES_encrypt encrypts a single block from |in| to |out| with |key|. The |in|
|
||||
* and |out| pointers may overlap. */ |
||||
OPENSSL_EXPORT void AES_encrypt(const uint8_t *in, uint8_t *out, |
||||
const AES_KEY *key); |
||||
|
||||
/* AES_decrypt decrypts a single block from |in| to |out| with |key|. The |in|
|
||||
* and |out| pointers may overlap. */ |
||||
OPENSSL_EXPORT void AES_decrypt(const uint8_t *in, uint8_t *out, |
||||
const AES_KEY *key); |
||||
|
||||
|
||||
/* Block cipher modes. */ |
||||
|
||||
/* AES_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode) |len|
|
||||
* bytes from |in| to |out|. The |num| parameter must be set to zero on the |
||||
* first call and |ivec| will be incremented. */ |
||||
OPENSSL_EXPORT void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out, |
||||
size_t len, const AES_KEY *key, |
||||
uint8_t ivec[AES_BLOCK_SIZE], |
||||
uint8_t ecount_buf[AES_BLOCK_SIZE], |
||||
unsigned int *num); |
||||
|
||||
/* AES_ecb_encrypt encrypts (or decrypts, if |enc| == |AES_DECRYPT|) a single,
|
||||
* 16 byte block from |in| to |out|. */ |
||||
OPENSSL_EXPORT void AES_ecb_encrypt(const uint8_t *in, uint8_t *out, |
||||
const AES_KEY *key, const int enc); |
||||
|
||||
/* AES_cbc_encrypt encrypts (or decrypts, if |enc| == |AES_DECRYPT|) |len|
|
||||
* bytes from |in| to |out|. The length must be a multiple of the block size. */ |
||||
OPENSSL_EXPORT void AES_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, |
||||
const AES_KEY *key, uint8_t *ivec, |
||||
const int enc); |
||||
|
||||
/* AES_ofb128_encrypt encrypts (or decrypts, it's the same in CTR mode) |len|
|
||||
* bytes from |in| to |out|. The |num| parameter must be set to zero on the |
||||
* first call. */ |
||||
OPENSSL_EXPORT void AES_ofb128_encrypt(const uint8_t *in, uint8_t *out, |
||||
size_t len, const AES_KEY *key, |
||||
uint8_t *ivec, int *num); |
||||
|
||||
/* AES_cfb128_encrypt encrypts (or decrypts, if |enc| == |AES_DECRYPT|) |len|
|
||||
* bytes from |in| to |out|. The |num| parameter must be set to zero on the |
||||
* first call. */ |
||||
OPENSSL_EXPORT void AES_cfb128_encrypt(const uint8_t *in, uint8_t *out, |
||||
size_t len, const AES_KEY *key, |
||||
uint8_t *ivec, int *num, int enc); |
||||
|
||||
|
||||
/* Android compatibility section.
|
||||
* |
||||
* These functions are declared, temporarily, for Android because |
||||
* wpa_supplicant will take a little time to sync with upstream. Outside of |
||||
* Android they'll have no definition. */ |
||||
|
||||
OPENSSL_EXPORT int AES_wrap_key(AES_KEY *key, const uint8_t *iv, uint8_t *out, |
||||
const uint8_t *in, unsigned in_len); |
||||
OPENSSL_EXPORT int AES_unwrap_key(AES_KEY *key, const uint8_t *iv, uint8_t *out, |
||||
const uint8_t *in, unsigned in_len); |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#endif /* OPENSSL_HEADER_AES_H */ |
File diff suppressed because it is too large
Load Diff
@ -1,76 +0,0 @@ |
||||
/* crypto/asn1/asn1_mac.h */ |
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
*
|
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] |
||||
*/ |
||||
|
||||
#ifndef HEADER_ASN1_MAC_H |
||||
#define HEADER_ASN1_MAC_H |
||||
|
||||
#include <openssl/asn1.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
OPENSSL_EXPORT int asn1_GetSequence(ASN1_const_CTX *c, long *length); |
||||
|
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif |
@ -1,907 +0,0 @@ |
||||
/* asn1t.h */ |
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000. |
||||
*/ |
||||
/* ====================================================================
|
||||
* Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* 3. All advertising materials mentioning features or use of this |
||||
* software must display the following acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
* |
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
||||
* endorse or promote products derived from this software without |
||||
* prior written permission. For written permission, please contact |
||||
* licensing@OpenSSL.org. |
||||
* |
||||
* 5. Products derived from this software may not be called "OpenSSL" |
||||
* nor may "OpenSSL" appear in their names without prior written |
||||
* permission of the OpenSSL Project. |
||||
* |
||||
* 6. Redistributions of any form whatsoever must retain the following |
||||
* acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
||||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* ==================================================================== |
||||
* |
||||
* This product includes cryptographic software written by Eric Young |
||||
* (eay@cryptsoft.com). This product includes software written by Tim |
||||
* Hudson (tjh@cryptsoft.com). |
||||
* |
||||
*/ |
||||
#ifndef HEADER_ASN1T_H |
||||
#define HEADER_ASN1T_H |
||||
|
||||
#include <openssl/base.h> |
||||
#include <openssl/asn1.h> |
||||
|
||||
#ifdef OPENSSL_BUILD_SHLIBCRYPTO |
||||
# undef OPENSSL_EXTERN |
||||
# define OPENSSL_EXTERN OPENSSL_EXPORT |
||||
#endif |
||||
|
||||
/* ASN1 template defines, structures and functions */ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ |
||||
#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) |
||||
|
||||
|
||||
/* Macros for start and end of ASN1_ITEM definition */ |
||||
|
||||
#define ASN1_ITEM_start(itname) \ |
||||
const ASN1_ITEM itname##_it = { |
||||
|
||||
#define ASN1_ITEM_end(itname) \ |
||||
}; |
||||
|
||||
/* Macros to aid ASN1 template writing */ |
||||
|
||||
#define ASN1_ITEM_TEMPLATE(tname) \ |
||||
static const ASN1_TEMPLATE tname##_item_tt
|
||||
|
||||
#define ASN1_ITEM_TEMPLATE_END(tname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_PRIMITIVE,\
|
||||
-1,\
|
||||
&tname##_item_tt,\
|
||||
0,\
|
||||
NULL,\
|
||||
0,\
|
||||
#tname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
|
||||
/* This is a ASN1 type which just embeds a template */ |
||||
|
||||
/* This pair helps declare a SEQUENCE. We can do:
|
||||
* |
||||
* ASN1_SEQUENCE(stname) = { |
||||
* ... SEQUENCE components ... |
||||
* } ASN1_SEQUENCE_END(stname) |
||||
* |
||||
* This will produce an ASN1_ITEM called stname_it |
||||
* for a structure called stname. |
||||
* |
||||
* If you want the same structure but a different |
||||
* name then use: |
||||
* |
||||
* ASN1_SEQUENCE(itname) = { |
||||
* ... SEQUENCE components ... |
||||
* } ASN1_SEQUENCE_END_name(stname, itname) |
||||
* |
||||
* This will create an item called itname_it using |
||||
* a structure called stname. |
||||
*/ |
||||
|
||||
#define ASN1_SEQUENCE(tname) \ |
||||
static const ASN1_TEMPLATE tname##_seq_tt[]
|
||||
|
||||
#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) |
||||
|
||||
#define ASN1_SEQUENCE_END_name(stname, tname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(stname),\
|
||||
#stname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
#define ASN1_NDEF_SEQUENCE(tname) \ |
||||
ASN1_SEQUENCE(tname) |
||||
|
||||
#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ |
||||
ASN1_SEQUENCE_cb(tname, cb) |
||||
|
||||
#define ASN1_SEQUENCE_cb(tname, cb) \ |
||||
static const ASN1_AUX tname##_aux = {NULL, 0, 0, cb, 0}; \
|
||||
ASN1_SEQUENCE(tname) |
||||
|
||||
#define ASN1_BROKEN_SEQUENCE(tname) \ |
||||
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0}; \
|
||||
ASN1_SEQUENCE(tname) |
||||
|
||||
#define ASN1_SEQUENCE_ref(tname, cb) \ |
||||
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), cb, 0}; \
|
||||
ASN1_SEQUENCE(tname) |
||||
|
||||
#define ASN1_SEQUENCE_enc(tname, enc, cb) \ |
||||
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, cb, offsetof(tname, enc)}; \
|
||||
ASN1_SEQUENCE(tname) |
||||
|
||||
#define ASN1_NDEF_SEQUENCE_END(tname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_NDEF_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(tname),\
|
||||
#tname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) |
||||
|
||||
#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) |
||||
|
||||
#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) |
||||
|
||||
#define ASN1_SEQUENCE_END_ref(stname, tname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
#define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_NDEF_SEQUENCE,\
|
||||
V_ASN1_SEQUENCE,\
|
||||
tname##_seq_tt,\
|
||||
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
|
||||
/* This pair helps declare a CHOICE type. We can do:
|
||||
* |
||||
* ASN1_CHOICE(chname) = { |
||||
* ... CHOICE options ... |
||||
* ASN1_CHOICE_END(chname) |
||||
* |
||||
* This will produce an ASN1_ITEM called chname_it |
||||
* for a structure called chname. The structure |
||||
* definition must look like this: |
||||
* typedef struct { |
||||
* int type; |
||||
* union { |
||||
* ASN1_SOMETHING *opt1; |
||||
* ASN1_SOMEOTHER *opt2; |
||||
* } value; |
||||
* } chname; |
||||
*
|
||||
* the name of the selector must be 'type'. |
||||
* to use an alternative selector name use the |
||||
* ASN1_CHOICE_END_selector() version. |
||||
*/ |
||||
|
||||
#define ASN1_CHOICE(tname) \ |
||||
static const ASN1_TEMPLATE tname##_ch_tt[]
|
||||
|
||||
#define ASN1_CHOICE_cb(tname, cb) \ |
||||
static const ASN1_AUX tname##_aux = {NULL, 0, 0, cb, 0}; \
|
||||
ASN1_CHOICE(tname) |
||||
|
||||
#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) |
||||
|
||||
#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) |
||||
|
||||
#define ASN1_CHOICE_END_selector(stname, tname, selname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_CHOICE,\
|
||||
offsetof(stname,selname) ,\
|
||||
tname##_ch_tt,\
|
||||
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
NULL,\
|
||||
sizeof(stname),\
|
||||
#stname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
#define ASN1_CHOICE_END_cb(stname, tname, selname) \ |
||||
;\
|
||||
ASN1_ITEM_start(tname) \
|
||||
ASN1_ITYPE_CHOICE,\
|
||||
offsetof(stname,selname) ,\
|
||||
tname##_ch_tt,\
|
||||
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
||||
&tname##_aux,\
|
||||
sizeof(stname),\
|
||||
#stname \ |
||||
ASN1_ITEM_end(tname) |
||||
|
||||
/* This helps with the template wrapper form of ASN1_ITEM */ |
||||
|
||||
#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ |
||||
(flags), (tag), 0,\
|
||||
#name, ASN1_ITEM_ref(type) } |
||||
|
||||
/* These help with SEQUENCE or CHOICE components */ |
||||
|
||||
/* used to declare other types */ |
||||
|
||||
#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ |
||||
(flags), (tag), offsetof(stname, field),\
|
||||
#field, ASN1_ITEM_ref(type) } |
||||
|
||||
/* used when the structure is combined with the parent */ |
||||
|
||||
#define ASN1_EX_COMBINE(flags, tag, type) { \ |
||||
(flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) } |
||||
|
||||
/* implicit and explicit helper macros */ |
||||
|
||||
#define ASN1_IMP_EX(stname, field, type, tag, ex) \ |
||||
ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type) |
||||
|
||||
#define ASN1_EXP_EX(stname, field, type, tag, ex) \ |
||||
ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type) |
||||
|
||||
/* Any defined by macros: the field used is in the table itself */ |
||||
|
||||
#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } |
||||
#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } |
||||
/* Plain simple type */ |
||||
#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) |
||||
|
||||
/* OPTIONAL simple type */ |
||||
#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) |
||||
|
||||
/* IMPLICIT tagged simple type */ |
||||
#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) |
||||
|
||||
/* IMPLICIT tagged OPTIONAL simple type */ |
||||
#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) |
||||
|
||||
/* Same as above but EXPLICIT */ |
||||
|
||||
#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) |
||||
#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) |
||||
|
||||
/* SEQUENCE OF type */ |
||||
#define ASN1_SEQUENCE_OF(stname, field, type) \ |
||||
ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) |
||||
|
||||
/* OPTIONAL SEQUENCE OF */ |
||||
#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ |
||||
ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) |
||||
|
||||
/* Same as above but for SET OF */ |
||||
|
||||
#define ASN1_SET_OF(stname, field, type) \ |
||||
ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) |
||||
|
||||
#define ASN1_SET_OF_OPT(stname, field, type) \ |
||||
ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) |
||||
|
||||
/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ |
||||
|
||||
#define ASN1_IMP_SET_OF(stname, field, type, tag) \ |
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) |
||||
|
||||
#define ASN1_EXP_SET_OF(stname, field, type, tag) \ |
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) |
||||
|
||||
#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ |
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) |
||||
|
||||
#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ |
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) |
||||
|
||||
#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ |
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) |
||||
|
||||
#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ |
||||
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) |
||||
|
||||
#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ |
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) |
||||
|
||||
#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ |
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) |
||||
|
||||
/* EXPLICIT using indefinite length constructed form */ |
||||
#define ASN1_NDEF_EXP(stname, field, type, tag) \ |
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) |
||||
|
||||
/* EXPLICIT OPTIONAL using indefinite length constructed form */ |
||||
#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ |
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) |
||||
|
||||
/* Macros for the ASN1_ADB structure */ |
||||
|
||||
#define ASN1_ADB(name) \ |
||||
static const ASN1_ADB_TABLE name##_adbtbl[]
|
||||
|
||||
#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ |
||||
;\
|
||||
static const ASN1_ADB name##_adb = {\
|
||||
flags,\
|
||||
offsetof(name, field),\
|
||||
app_table,\
|
||||
name##_adbtbl,\
|
||||
sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
|
||||
def,\
|
||||
none\
|
||||
} |
||||
|
||||
#define ADB_ENTRY(val, template) {val, template} |
||||
|
||||
#define ASN1_ADB_TEMPLATE(name) \ |
||||
static const ASN1_TEMPLATE name##_tt
|
||||
|
||||
/* This is the ASN1 template structure that defines
|
||||
* a wrapper round the actual type. It determines the |
||||
* actual position of the field in the value structure, |
||||
* various flags such as OPTIONAL and the field name. |
||||
*/ |
||||
|
||||
struct ASN1_TEMPLATE_st { |
||||
unsigned long flags; /* Various flags */ |
||||
long tag; /* tag, not used if no tagging */ |
||||
unsigned long offset; /* Offset of this field in structure */ |
||||
#ifndef NO_ASN1_FIELD_NAMES |
||||
const char *field_name; /* Field name */ |
||||
#endif |
||||
ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ |
||||
}; |
||||
|
||||
/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ |
||||
|
||||
#define ASN1_TEMPLATE_item(t) (t->item_ptr) |
||||
#define ASN1_TEMPLATE_adb(t) (t->item_ptr) |
||||
|
||||
typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; |
||||
typedef struct ASN1_ADB_st ASN1_ADB; |
||||
|
||||
struct ASN1_ADB_st { |
||||
unsigned long flags; /* Various flags */ |
||||
unsigned long offset; /* Offset of selector field */ |
||||
STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */ |
||||
const ASN1_ADB_TABLE *tbl; /* Table of possible types */ |
||||
long tblcount; /* Number of entries in tbl */ |
||||
const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ |
||||
const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ |
||||
}; |
||||
|
||||
struct ASN1_ADB_TABLE_st { |
||||
long value; /* NID for an object or value for an int */ |
||||
const ASN1_TEMPLATE tt; /* item for this value */ |
||||
}; |
||||
|
||||
/* template flags */ |
||||
|
||||
/* Field is optional */ |
||||
#define ASN1_TFLG_OPTIONAL (0x1) |
||||
|
||||
/* Field is a SET OF */ |
||||
#define ASN1_TFLG_SET_OF (0x1 << 1) |
||||
|
||||
/* Field is a SEQUENCE OF */ |
||||
#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) |
||||
|
||||
/* Special case: this refers to a SET OF that
|
||||
* will be sorted into DER order when encoded *and* |
||||
* the corresponding STACK will be modified to match |
||||
* the new order. |
||||
*/ |
||||
#define ASN1_TFLG_SET_ORDER (0x3 << 1) |
||||
|
||||
/* Mask for SET OF or SEQUENCE OF */ |
||||
#define ASN1_TFLG_SK_MASK (0x3 << 1) |
||||
|
||||
/* These flags mean the tag should be taken from the
|
||||
* tag field. If EXPLICIT then the underlying type |
||||
* is used for the inner tag. |
||||
*/ |
||||
|
||||
/* IMPLICIT tagging */ |
||||
#define ASN1_TFLG_IMPTAG (0x1 << 3) |
||||
|
||||
|
||||
/* EXPLICIT tagging, inner tag from underlying type */ |
||||
#define ASN1_TFLG_EXPTAG (0x2 << 3) |
||||
|
||||
#define ASN1_TFLG_TAG_MASK (0x3 << 3) |
||||
|
||||
/* context specific IMPLICIT */ |
||||
#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT |
||||
|
||||
/* context specific EXPLICIT */ |
||||
#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT |
||||
|
||||
/* If tagging is in force these determine the
|
||||
* type of tag to use. Otherwise the tag is |
||||
* determined by the underlying type. These
|
||||
* values reflect the actual octet format. |
||||
*/ |
||||
|
||||
/* Universal tag */
|
||||
#define ASN1_TFLG_UNIVERSAL (0x0<<6) |
||||
/* Application tag */
|
||||
#define ASN1_TFLG_APPLICATION (0x1<<6) |
||||
/* Context specific tag */
|
||||
#define ASN1_TFLG_CONTEXT (0x2<<6) |
||||
/* Private tag */
|
||||
#define ASN1_TFLG_PRIVATE (0x3<<6) |
||||
|
||||
#define ASN1_TFLG_TAG_CLASS (0x3<<6) |
||||
|
||||
/* These are for ANY DEFINED BY type. In this case
|
||||
* the 'item' field points to an ASN1_ADB structure |
||||
* which contains a table of values to decode the |
||||
* relevant type |
||||
*/ |
||||
|
||||
#define ASN1_TFLG_ADB_MASK (0x3<<8) |
||||
|
||||
#define ASN1_TFLG_ADB_OID (0x1<<8) |
||||
|
||||
#define ASN1_TFLG_ADB_INT (0x1<<9) |
||||
|
||||
/* This flag means a parent structure is passed
|
||||
* instead of the field: this is useful is a |
||||
* SEQUENCE is being combined with a CHOICE for |
||||
* example. Since this means the structure and |
||||
* item name will differ we need to use the |
||||
* ASN1_CHOICE_END_name() macro for example. |
||||
*/ |
||||
|
||||
#define ASN1_TFLG_COMBINE (0x1<<10) |
||||
|
||||
/* This flag when present in a SEQUENCE OF, SET OF
|
||||
* or EXPLICIT causes indefinite length constructed |
||||
* encoding to be used if required. |
||||
*/ |
||||
|
||||
#define ASN1_TFLG_NDEF (0x1<<11) |
||||
|
||||
/* This is the actual ASN1 item itself */ |
||||
|
||||
struct ASN1_ITEM_st { |
||||
char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */ |
||||
long utype; /* underlying type */ |
||||
const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */ |
||||
long tcount; /* Number of templates if SEQUENCE or CHOICE */ |
||||
const void *funcs; /* functions that handle this type */ |
||||
long size; /* Structure size (usually)*/ |
||||
#ifndef NO_ASN1_FIELD_NAMES |
||||
const char *sname; /* Structure name */ |
||||
#endif |
||||
}; |
||||
|
||||
/* These are values for the itype field and
|
||||
* determine how the type is interpreted. |
||||
* |
||||
* For PRIMITIVE types the underlying type |
||||
* determines the behaviour if items is NULL. |
||||
* |
||||
* Otherwise templates must contain a single
|
||||
* template and the type is treated in the |
||||
* same way as the type specified in the template. |
||||
* |
||||
* For SEQUENCE types the templates field points |
||||
* to the members, the size field is the |
||||
* structure size. |
||||
* |
||||
* For CHOICE types the templates field points |
||||
* to each possible member (typically a union) |
||||
* and the 'size' field is the offset of the |
||||
* selector. |
||||
* |
||||
* The 'funcs' field is used for application |
||||
* specific functions.
|
||||
* |
||||
* For COMPAT types the funcs field gives a |
||||
* set of functions that handle this type, this |
||||
* supports the old d2i, i2d convention. |
||||
* |
||||
* The EXTERN type uses a new style d2i/i2d. |
||||
* The new style should be used where possible |
||||
* because it avoids things like the d2i IMPLICIT |
||||
* hack. |
||||
* |
||||
* MSTRING is a multiple string type, it is used |
||||
* for a CHOICE of character strings where the |
||||
* actual strings all occupy an ASN1_STRING |
||||
* structure. In this case the 'utype' field |
||||
* has a special meaning, it is used as a mask |
||||
* of acceptable types using the B_ASN1 constants. |
||||
* |
||||
* NDEF_SEQUENCE is the same as SEQUENCE except |
||||
* that it will use indefinite length constructed |
||||
* encoding if requested. |
||||
* |
||||
*/ |
||||
|
||||
#define ASN1_ITYPE_PRIMITIVE 0x0 |
||||
|
||||
#define ASN1_ITYPE_SEQUENCE 0x1 |
||||
|
||||
#define ASN1_ITYPE_CHOICE 0x2 |
||||
|
||||
#define ASN1_ITYPE_COMPAT 0x3 |
||||
|
||||
#define ASN1_ITYPE_EXTERN 0x4 |
||||
|
||||
#define ASN1_ITYPE_MSTRING 0x5 |
||||
|
||||
#define ASN1_ITYPE_NDEF_SEQUENCE 0x6 |
||||
|
||||
/* Cache for ASN1 tag and length, so we
|
||||
* don't keep re-reading it for things |
||||
* like CHOICE |
||||
*/ |
||||
|
||||
struct ASN1_TLC_st{ |
||||
char valid; /* Values below are valid */ |
||||
int ret; /* return value */ |
||||
long plen; /* length */ |
||||
int ptag; /* class value */ |
||||
int pclass; /* class value */ |
||||
int hdrlen; /* header length */ |
||||
}; |
||||
|
||||
/* Typedefs for ASN1 function pointers */ |
||||
|
||||
typedef ASN1_VALUE * ASN1_new_func(void); |
||||
typedef void ASN1_free_func(ASN1_VALUE *a); |
||||
typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length); |
||||
typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); |
||||
|
||||
typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, |
||||
int tag, int aclass, char opt, ASN1_TLC *ctx); |
||||
|
||||
typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); |
||||
typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
|
||||
typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval,
|
||||
int indent, const char *fname,
|
||||
const ASN1_PCTX *pctx); |
||||
|
||||
typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); |
||||
typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); |
||||
typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx); |
||||
|
||||
typedef struct ASN1_COMPAT_FUNCS_st { |
||||
ASN1_new_func *asn1_new; |
||||
ASN1_free_func *asn1_free; |
||||
ASN1_d2i_func *asn1_d2i; |
||||
ASN1_i2d_func *asn1_i2d; |
||||
} ASN1_COMPAT_FUNCS; |
||||
|
||||
typedef struct ASN1_EXTERN_FUNCS_st { |
||||
void *app_data; |
||||
ASN1_ex_new_func *asn1_ex_new; |
||||
ASN1_ex_free_func *asn1_ex_free; |
||||
ASN1_ex_free_func *asn1_ex_clear; |
||||
ASN1_ex_d2i *asn1_ex_d2i; |
||||
ASN1_ex_i2d *asn1_ex_i2d; |
||||
ASN1_ex_print_func *asn1_ex_print; |
||||
} ASN1_EXTERN_FUNCS; |
||||
|
||||
typedef struct ASN1_PRIMITIVE_FUNCS_st { |
||||
void *app_data; |
||||
unsigned long flags; |
||||
ASN1_ex_new_func *prim_new; |
||||
ASN1_ex_free_func *prim_free; |
||||
ASN1_ex_free_func *prim_clear; |
||||
ASN1_primitive_c2i *prim_c2i; |
||||
ASN1_primitive_i2c *prim_i2c; |
||||
ASN1_primitive_print *prim_print; |
||||
} ASN1_PRIMITIVE_FUNCS; |
||||
|
||||
/* This is the ASN1_AUX structure: it handles various
|
||||
* miscellaneous requirements. For example the use of |
||||
* reference counts and an informational callback. |
||||
* |
||||
* The "informational callback" is called at various |
||||
* points during the ASN1 encoding and decoding. It can |
||||
* be used to provide minor customisation of the structures |
||||
* used. This is most useful where the supplied routines |
||||
* *almost* do the right thing but need some extra help |
||||
* at a few points. If the callback returns zero then |
||||
* it is assumed a fatal error has occurred and the
|
||||
* main operation should be abandoned. |
||||
* |
||||
* If major changes in the default behaviour are required |
||||
* then an external type is more appropriate. |
||||
*/ |
||||
|
||||
typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, |
||||
void *exarg); |
||||
|
||||
typedef struct ASN1_AUX_st { |
||||
void *app_data; |
||||
int flags; |
||||
int ref_offset; /* Offset of reference value */ |
||||
ASN1_aux_cb *asn1_cb; |
||||
int enc_offset; /* Offset of ASN1_ENCODING structure */ |
||||
} ASN1_AUX; |
||||
|
||||
/* For print related callbacks exarg points to this structure */ |
||||
typedef struct ASN1_PRINT_ARG_st { |
||||
BIO *out; |
||||
int indent; |
||||
const ASN1_PCTX *pctx; |
||||
} ASN1_PRINT_ARG; |
||||
|
||||
/* For streaming related callbacks exarg points to this structure */ |
||||
typedef struct ASN1_STREAM_ARG_st { |
||||
/* BIO to stream through */ |
||||
BIO *out; |
||||
/* BIO with filters appended */ |
||||
BIO *ndef_bio; |
||||
/* Streaming I/O boundary */ |
||||
unsigned char **boundary; |
||||
} ASN1_STREAM_ARG; |
||||
|
||||
/* Flags in ASN1_AUX */ |
||||
|
||||
/* Use a reference count */ |
||||
#define ASN1_AFLG_REFCOUNT 1 |
||||
/* Save the encoding of structure (useful for signatures) */ |
||||
#define ASN1_AFLG_ENCODING 2 |
||||
/* The Sequence length is invalid */ |
||||
#define ASN1_AFLG_BROKEN 4 |
||||
|
||||
/* operation values for asn1_cb */ |
||||
|
||||
#define ASN1_OP_NEW_PRE 0 |
||||
#define ASN1_OP_NEW_POST 1 |
||||
#define ASN1_OP_FREE_PRE 2 |
||||
#define ASN1_OP_FREE_POST 3 |
||||
#define ASN1_OP_D2I_PRE 4 |
||||
#define ASN1_OP_D2I_POST 5 |
||||
#define ASN1_OP_I2D_PRE 6 |
||||
#define ASN1_OP_I2D_POST 7 |
||||
#define ASN1_OP_PRINT_PRE 8 |
||||
#define ASN1_OP_PRINT_POST 9 |
||||
#define ASN1_OP_STREAM_PRE 10 |
||||
#define ASN1_OP_STREAM_POST 11 |
||||
#define ASN1_OP_DETACHED_PRE 12 |
||||
#define ASN1_OP_DETACHED_POST 13 |
||||
|
||||
/* Macro to implement a primitive type */ |
||||
#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) |
||||
#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ |
||||
ASN1_ITEM_start(itname) \
|
||||
ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
|
||||
ASN1_ITEM_end(itname) |
||||
|
||||
/* Macro to implement a multi string type */ |
||||
#define IMPLEMENT_ASN1_MSTRING(itname, mask) \ |
||||
ASN1_ITEM_start(itname) \
|
||||
ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
|
||||
ASN1_ITEM_end(itname) |
||||
|
||||
/* Macro to implement an ASN1_ITEM in terms of old style funcs */ |
||||
|
||||
#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE) |
||||
|
||||
#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \ |
||||
static const ASN1_COMPAT_FUNCS sname##_ff = { \
|
||||
(ASN1_new_func *)sname##_new, \
|
||||
(ASN1_free_func *)sname##_free, \
|
||||
(ASN1_d2i_func *)d2i_##sname, \
|
||||
(ASN1_i2d_func *)i2d_##sname, \
|
||||
}; \
|
||||
ASN1_ITEM_start(sname) \
|
||||
ASN1_ITYPE_COMPAT, \
|
||||
tag, \
|
||||
NULL, \
|
||||
0, \
|
||||
&sname##_ff, \
|
||||
0, \
|
||||
#sname \ |
||||
ASN1_ITEM_end(sname) |
||||
|
||||
#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ |
||||
ASN1_ITEM_start(sname) \
|
||||
ASN1_ITYPE_EXTERN, \
|
||||
tag, \
|
||||
NULL, \
|
||||
0, \
|
||||
&fptrs, \
|
||||
0, \
|
||||
#sname \ |
||||
ASN1_ITEM_end(sname) |
||||
|
||||
/* Macro to implement standard functions in terms of ASN1_ITEM structures */ |
||||
|
||||
#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) |
||||
|
||||
#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) |
||||
|
||||
#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ |
||||
IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) |
||||
|
||||
#define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ |
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) |
||||
|
||||
#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ |
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) |
||||
|
||||
#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ |
||||
pre stname *fname##_new(void) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
|
||||
} \
|
||||
pre void fname##_free(stname *a) \
|
||||
{ \
|
||||
ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
|
||||
} |
||||
|
||||
#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ |
||||
stname *fname##_new(void) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
|
||||
} \
|
||||
void fname##_free(stname *a) \
|
||||
{ \
|
||||
ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
|
||||
} |
||||
|
||||
#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ |
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) |
||||
|
||||
#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ |
||||
stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
|
||||
} \
|
||||
int i2d_##fname(stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
|
||||
}
|
||||
|
||||
#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ |
||||
int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
|
||||
}
|
||||
|
||||
/* This includes evil casts to remove const: they will go away when full
|
||||
* ASN1 constification is done. |
||||
*/ |
||||
#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ |
||||
stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
|
||||
{ \
|
||||
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
|
||||
} \
|
||||
int i2d_##fname(const stname *a, unsigned char **out) \
|
||||
{ \
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
|
||||
}
|
||||
|
||||
#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ |
||||
stname * stname##_dup(stname *x) \
|
||||
{ \
|
||||
return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
|
||||
} |
||||
|
||||
#define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ |
||||
IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) |
||||
|
||||
#define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ |
||||
int fname##_print_ctx(BIO *out, stname *x, int indent, \
|
||||
const ASN1_PCTX *pctx) \
|
||||
{ \
|
||||
return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
|
||||
ASN1_ITEM_rptr(itname), pctx); \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ |
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) |
||||
|
||||
#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ |
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) |
||||
|
||||
/* external definitions for primitive types */ |
||||
|
||||
DECLARE_ASN1_ITEM(ASN1_BOOLEAN) |
||||
DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) |
||||
DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) |
||||
DECLARE_ASN1_ITEM(ASN1_SEQUENCE) |
||||
DECLARE_ASN1_ITEM(CBIGNUM) |
||||
DECLARE_ASN1_ITEM(BIGNUM) |
||||
DECLARE_ASN1_ITEM(LONG) |
||||
DECLARE_ASN1_ITEM(ZLONG) |
||||
|
||||
DECLARE_STACK_OF(ASN1_VALUE) |
||||
|
||||
/* Functions used internally by the ASN1 code */ |
||||
|
||||
int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
||||
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
|
||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
||||
int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt); |
||||
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, |
||||
int tag, int aclass, char opt, ASN1_TLC *ctx); |
||||
|
||||
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); |
||||
int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt); |
||||
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
|
||||
int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); |
||||
int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); |
||||
|
||||
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); |
||||
|
||||
ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
||||
|
||||
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr); |
||||
|
||||
void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
|
||||
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); |
||||
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif |
@ -1,233 +0,0 @@ |
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* 3. All advertising materials mentioning features or use of this |
||||
* software must display the following acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
* |
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
||||
* endorse or promote products derived from this software without |
||||
* prior written permission. For written permission, please contact |
||||
* openssl-core@openssl.org. |
||||
* |
||||
* 5. Products derived from this software may not be called "OpenSSL" |
||||
* nor may "OpenSSL" appear in their names without prior written |
||||
* permission of the OpenSSL Project. |
||||
* |
||||
* 6. Redistributions of any form whatsoever must retain the following |
||||
* acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
||||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* ==================================================================== |
||||
* |
||||
* This product includes cryptographic software written by Eric Young |
||||
* (eay@cryptsoft.com). This product includes software written by Tim |
||||
* Hudson (tjh@cryptsoft.com). */ |
||||
|
||||
#ifndef OPENSSL_HEADER_BASE_H |
||||
#define OPENSSL_HEADER_BASE_H |
||||
|
||||
|
||||
/* This file should be the first included by all BoringSSL headers. */ |
||||
|
||||
#include <stddef.h> |
||||
#include <stdint.h> |
||||
#include <sys/types.h> |
||||
|
||||
#include <openssl/opensslfeatures.h> |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
#if defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) |
||||
#define OPENSSL_64_BIT |
||||
#define OPENSSL_X86_64 |
||||
#elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86) |
||||
#define OPENSSL_32_BIT |
||||
#define OPENSSL_X86 |
||||
#elif defined(__aarch64__) |
||||
#define OPENSSL_64_BIT |
||||
#define OPENSSL_AARCH64 |
||||
#elif defined(__arm) || defined(__arm__) || defined(_M_ARM) |
||||
#define OPENSSL_32_BIT |
||||
#define OPENSSL_ARM |
||||
#elif defined(__aarch64__) |
||||
#define OPENSSL_64_BIT |
||||
#define OPENSSL_AARCH64 |
||||
#elif defined(__mips__) && !defined(__LP64__) |
||||
#define OPENSSL_32_BIT |
||||
#define OPENSSL_MIPS |
||||
#elif defined(__mips__) && defined(__LP64__) |
||||
#define OPENSSL_64_BIT |
||||
#define OPENSSL_MIPS64 |
||||
#elif defined(__pnacl__) |
||||
#define OPENSSL_32_BIT |
||||
#define OPENSSL_PNACL |
||||
#else |
||||
#error "Unknown target CPU" |
||||
#endif |
||||
|
||||
#if defined(__APPLE__) |
||||
#define OPENSSL_APPLE |
||||
#endif |
||||
|
||||
#if defined(WIN32) || defined(_WIN32) |
||||
#define OPENSSL_WINDOWS |
||||
#endif |
||||
|
||||
#if defined(TRUSTY) |
||||
#define OPENSSL_TRUSTY |
||||
#define OPENSSL_NO_THREADS |
||||
#endif |
||||
|
||||
#define OPENSSL_IS_BORINGSSL |
||||
#define OPENSSL_VERSION_NUMBER 0x10002000 |
||||
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY) |
||||
|
||||
#if defined(OPENSSL_WINDOWS) |
||||
|
||||
#if defined(BORINGSSL_IMPLEMENTATION) |
||||
#define OPENSSL_EXPORT __declspec(dllexport) |
||||
#else |
||||
#define OPENSSL_EXPORT __declspec(dllimport) |
||||
#endif |
||||
|
||||
#else /* defined(OPENSSL_WINDOWS) */ |
||||
|
||||
#if defined(BORINGSSL_IMPLEMENTATION) |
||||
#define OPENSSL_EXPORT __attribute__((visibility("default"))) |
||||
#else |
||||
#define OPENSSL_EXPORT |
||||
#endif |
||||
|
||||
#endif /* defined(OPENSSL_WINDOWS) */ |
||||
|
||||
#else /* defined(BORINGSSL_SHARED_LIBRARY) */ |
||||
|
||||
#define OPENSSL_EXPORT |
||||
|
||||
#endif /* defined(BORINGSSL_SHARED_LIBRARY) */ |
||||
|
||||
/* CRYPTO_THREADID is a dummy value. */ |
||||
typedef int CRYPTO_THREADID; |
||||
|
||||
typedef int ASN1_BOOLEAN; |
||||
typedef int ASN1_NULL; |
||||
typedef struct ASN1_ITEM_st ASN1_ITEM; |
||||
typedef struct asn1_object_st ASN1_OBJECT; |
||||
typedef struct asn1_pctx_st ASN1_PCTX; |
||||
typedef struct asn1_string_st ASN1_BIT_STRING; |
||||
typedef struct asn1_string_st ASN1_BMPSTRING; |
||||
typedef struct asn1_string_st ASN1_ENUMERATED; |
||||
typedef struct asn1_string_st ASN1_GENERALIZEDTIME; |
||||
typedef struct asn1_string_st ASN1_GENERALSTRING; |
||||
typedef struct asn1_string_st ASN1_IA5STRING; |
||||
typedef struct asn1_string_st ASN1_INTEGER; |
||||
typedef struct asn1_string_st ASN1_OCTET_STRING; |
||||
typedef struct asn1_string_st ASN1_PRINTABLESTRING; |
||||
typedef struct asn1_string_st ASN1_STRING; |
||||
typedef struct asn1_string_st ASN1_T61STRING; |
||||
typedef struct asn1_string_st ASN1_TIME; |
||||
typedef struct asn1_string_st ASN1_UNIVERSALSTRING; |
||||
typedef struct asn1_string_st ASN1_UTCTIME; |
||||
typedef struct asn1_string_st ASN1_UTF8STRING; |
||||
typedef struct asn1_string_st ASN1_VISIBLESTRING; |
||||
|
||||
typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID; |
||||
typedef struct DIST_POINT_st DIST_POINT; |
||||
typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT; |
||||
typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; |
||||
typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; |
||||
typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; |
||||
typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; |
||||
typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; |
||||
typedef struct X509_algor_st X509_ALGOR; |
||||
typedef struct X509_crl_st X509_CRL; |
||||
typedef struct X509_pubkey_st X509_PUBKEY; |
||||
typedef struct bignum_ctx BN_CTX; |
||||
typedef struct bignum_st BIGNUM; |
||||
typedef struct bio_method_st BIO_METHOD; |
||||
typedef struct bio_st BIO; |
||||
typedef struct bn_gencb_st BN_GENCB; |
||||
typedef struct bn_mont_ctx_st BN_MONT_CTX; |
||||
typedef struct buf_mem_st BUF_MEM; |
||||
typedef struct cbb_st CBB; |
||||
typedef struct cbs_st CBS; |
||||
typedef struct cmac_ctx_st CMAC_CTX; |
||||
typedef struct conf_st CONF; |
||||
typedef struct conf_value_st CONF_VALUE; |
||||
typedef struct dh_method DH_METHOD; |
||||
typedef struct dh_st DH; |
||||
typedef struct dsa_method DSA_METHOD; |
||||
typedef struct dsa_st DSA; |
||||
typedef struct ec_key_st EC_KEY; |
||||
typedef struct ecdsa_method_st ECDSA_METHOD; |
||||
typedef struct ecdsa_sig_st ECDSA_SIG; |
||||
typedef struct engine_st ENGINE; |
||||
typedef struct env_md_ctx_st EVP_MD_CTX; |
||||
typedef struct env_md_st EVP_MD; |
||||
typedef struct evp_aead_st EVP_AEAD; |
||||
typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; |
||||
typedef struct evp_cipher_st EVP_CIPHER; |
||||
typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD; |
||||
typedef struct evp_pkey_ctx_st EVP_PKEY_CTX; |
||||
typedef struct evp_pkey_method_st EVP_PKEY_METHOD; |
||||
typedef struct evp_pkey_st EVP_PKEY; |
||||
typedef struct hmac_ctx_st HMAC_CTX; |
||||
typedef struct md4_state_st MD4_CTX; |
||||
typedef struct md5_state_st MD5_CTX; |
||||
typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; |
||||
typedef struct pkcs12_st PKCS12; |
||||
typedef struct rand_meth_st RAND_METHOD; |
||||
typedef struct rc4_key_st RC4_KEY; |
||||
typedef struct rsa_meth_st RSA_METHOD; |
||||
typedef struct rsa_st RSA; |
||||
typedef struct sha256_state_st SHA256_CTX; |
||||
typedef struct sha512_state_st SHA512_CTX; |
||||
typedef struct sha_state_st SHA_CTX; |
||||
typedef struct ssl_ctx_st SSL_CTX; |
||||
typedef struct ssl_st SSL; |
||||
typedef struct st_ERR_FNS ERR_FNS; |
||||
typedef struct v3_ext_ctx X509V3_CTX; |
||||
typedef struct x509_crl_method_st X509_CRL_METHOD; |
||||
typedef struct x509_revoked_st X509_REVOKED; |
||||
typedef struct x509_st X509; |
||||
typedef struct x509_store_ctx_st X509_STORE_CTX; |
||||
typedef struct x509_store_st X509_STORE; |
||||
typedef void *OPENSSL_BLOCK; |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#endif /* OPENSSL_HEADER_BASE_H */ |
@ -1,179 +0,0 @@ |
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] */ |
||||
|
||||
#ifndef OPENSSL_HEADER_BASE64_H |
||||
#define OPENSSL_HEADER_BASE64_H |
||||
|
||||
#include <openssl/base.h> |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* base64 functions.
|
||||
* |
||||
* For historical reasons, these functions have the EVP_ prefix but just do |
||||
* base64 encoding and decoding. */ |
||||
|
||||
|
||||
typedef struct evp_encode_ctx_st EVP_ENCODE_CTX; |
||||
|
||||
|
||||
/* Encoding */ |
||||
|
||||
/* EVP_EncodeInit initialises |*ctx|, which is typically stack
|
||||
* allocated, for an encoding operation. |
||||
* |
||||
* NOTE: The encoding operation breaks its output with newlines every |
||||
* 64 characters of output (48 characters of input). Use |
||||
* EVP_EncodeBlock to encode raw base64. */ |
||||
OPENSSL_EXPORT void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); |
||||
|
||||
/* EVP_EncodeUpdate encodes |in_len| bytes from |in| and writes an encoded
|
||||
* version of them to |out| and sets |*out_len| to the number of bytes written. |
||||
* Some state may be contained in |ctx| so |EVP_EncodeFinal| must be used to |
||||
* flush it before using the encoded data. */ |
||||
OPENSSL_EXPORT void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, |
||||
int *out_len, const uint8_t *in, |
||||
size_t in_len); |
||||
|
||||
/* EVP_EncodeFinal flushes any remaining output bytes from |ctx| to |out| and
|
||||
* sets |*out_len| to the number of bytes written. */ |
||||
OPENSSL_EXPORT void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, |
||||
int *out_len); |
||||
|
||||
/* EVP_EncodeBlock encodes |src_len| bytes from |src| and writes the
|
||||
* result to |dst| with a trailing NUL. It returns the number of bytes |
||||
* written, not including this trailing NUL. */ |
||||
OPENSSL_EXPORT size_t EVP_EncodeBlock(uint8_t *dst, const uint8_t *src, |
||||
size_t src_len); |
||||
|
||||
/* EVP_EncodedLength sets |*out_len| to the number of bytes that will be needed
|
||||
* to call |EVP_EncodeBlock| on an input of length |len|. This includes the |
||||
* final NUL that |EVP_EncodeBlock| writes. It returns one on success or zero |
||||
* on error. */ |
||||
OPENSSL_EXPORT int EVP_EncodedLength(size_t *out_len, size_t len); |
||||
|
||||
|
||||
/* Decoding */ |
||||
|
||||
/* EVP_DecodedLength sets |*out_len| to the maximum number of bytes
|
||||
* that will be needed to call |EVP_DecodeBase64| on an input of |
||||
* length |len|. */ |
||||
OPENSSL_EXPORT int EVP_DecodedLength(size_t *out_len, size_t len); |
||||
|
||||
/* EVP_DecodeBase64 decodes |in_len| bytes from base64 and writes
|
||||
* |*out_len| bytes to |out|. |max_out| is the size of the output |
||||
* buffer. If it is not enough for the maximum output size, the |
||||
* operation fails. */ |
||||
OPENSSL_EXPORT int EVP_DecodeBase64(uint8_t *out, size_t *out_len, |
||||
size_t max_out, const uint8_t *in, |
||||
size_t in_len); |
||||
|
||||
/* EVP_DecodeInit initialises |*ctx|, which is typically stack allocated, for
|
||||
* a decoding operation. |
||||
* |
||||
* TODO(davidben): This isn't a straight-up base64 decode either. Document |
||||
* and/or fix exactly what's going on here; maximum line length and such. */ |
||||
OPENSSL_EXPORT void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); |
||||
|
||||
/* EVP_DecodeUpdate decodes |in_len| bytes from |in| and writes the decoded
|
||||
* data to |out| and sets |*out_len| to the number of bytes written. Some state |
||||
* may be contained in |ctx| so |EVP_DecodeFinal| must be used to flush it |
||||
* before using the encoded data. |
||||
* |
||||
* It returns -1 on error, one if a full line of input was processed and zero |
||||
* if the line was short (i.e. it was the last line). */ |
||||
OPENSSL_EXPORT int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, |
||||
int *out_len, const uint8_t *in, |
||||
size_t in_len); |
||||
|
||||
/* EVP_DecodeFinal flushes any remaining output bytes from |ctx| to |out| and
|
||||
* sets |*out_len| to the number of bytes written. It returns one on success |
||||
* and minus one on error. */ |
||||
OPENSSL_EXPORT int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, |
||||
int *out_len); |
||||
|
||||
/* Deprecated: EVP_DecodeBlock encodes |src_len| bytes from |src| and
|
||||
* writes the result to |dst|. It returns the number of bytes written |
||||
* or -1 on error. |
||||
* |
||||
* WARNING: EVP_DecodeBlock's return value does not take padding into |
||||
* account. It also strips leading whitespace and trailing |
||||
* whitespace. */ |
||||
OPENSSL_EXPORT int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, |
||||
size_t src_len); |
||||
|
||||
|
||||
struct evp_encode_ctx_st { |
||||
unsigned num; /* number saved in a partial encode/decode */ |
||||
unsigned length; /* The length is either the output line length
|
||||
* (in input bytes) or the shortest input line |
||||
* length that is ok. Once decoding begins, |
||||
* the length is adjusted up each time a longer |
||||
* line is decoded */ |
||||
uint8_t enc_data[80]; /* data to encode */ |
||||
unsigned line_num; /* number read on current line */ |
||||
int expect_nl; |
||||
}; |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#endif /* OPENSSL_HEADER_BASE64_H */ |
@ -1,910 +0,0 @@ |
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] */ |
||||
|
||||
#ifndef OPENSSL_HEADER_BIO_H |
||||
#define OPENSSL_HEADER_BIO_H |
||||
|
||||
#include <openssl/base.h> |
||||
|
||||
#include <stdio.h> /* For FILE */ |
||||
|
||||
#include <openssl/err.h> /* for ERR_print_errors_fp */ |
||||
#include <openssl/ex_data.h> |
||||
#include <openssl/stack.h> |
||||
#include <openssl/thread.h> |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* BIO abstracts over a file-descriptor like interface. */ |
||||
|
||||
|
||||
/* Allocation and freeing. */ |
||||
|
||||
DEFINE_STACK_OF(BIO); |
||||
|
||||
/* BIO_new creates a new BIO with the given type and a reference count of one.
|
||||
* It returns the fresh |BIO|, or NULL on error. */ |
||||
OPENSSL_EXPORT BIO *BIO_new(const BIO_METHOD *type); |
||||
|
||||
/* BIO_free decrements the reference count of |bio|. If the reference count
|
||||
* drops to zero, it (optionally) calls the BIO's callback with |BIO_CB_FREE|, |
||||
* frees the ex_data and then, if the BIO has a destroy callback for the |
||||
* method, calls it. Finally it frees |bio| itself. It then repeats that for |
||||
* the next BIO in the chain, if any. |
||||
* |
||||
* It returns one on success or zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_free(BIO *bio); |
||||
|
||||
/* BIO_vfree performs the same actions as |BIO_free|, but has a void return
|
||||
* value. This is provided for API-compat. |
||||
* |
||||
* TODO(fork): remove. */ |
||||
OPENSSL_EXPORT void BIO_vfree(BIO *bio); |
||||
|
||||
/* BIO_up_ref increments the reference count of |bio| and returns it. */ |
||||
OPENSSL_EXPORT BIO *BIO_up_ref(BIO *bio); |
||||
|
||||
|
||||
/* Basic I/O. */ |
||||
|
||||
/* BIO_read attempts to read |len| bytes into |data|. It returns the number of
|
||||
* bytes read, zero on EOF, or a negative number on error. */ |
||||
OPENSSL_EXPORT int BIO_read(BIO *bio, void *data, int len); |
||||
|
||||
/* BIO_gets "reads a line" from |bio| and puts at most |size| bytes into |buf|.
|
||||
* It returns the number of bytes read or a negative number on error. The |
||||
* phrase "reads a line" is in quotes in the previous sentence because the |
||||
* exact operation depends on the BIO's method. For example, a digest BIO will |
||||
* return the digest in response to a |BIO_gets| call. |
||||
* |
||||
* TODO(fork): audit the set of BIOs that we end up needing. If all actually |
||||
* return a line for this call, remove the warning above. */ |
||||
OPENSSL_EXPORT int BIO_gets(BIO *bio, char *buf, int size); |
||||
|
||||
/* BIO_write writes |len| bytes from |data| to BIO. It returns the number of
|
||||
* bytes written or a negative number on error. */ |
||||
OPENSSL_EXPORT int BIO_write(BIO *bio, const void *data, int len); |
||||
|
||||
/* BIO_puts writes a NUL terminated string from |buf| to |bio|. It returns the
|
||||
* number of bytes written or a negative number on error. */ |
||||
OPENSSL_EXPORT int BIO_puts(BIO *bio, const char *buf); |
||||
|
||||
/* BIO_flush flushes any buffered output. It returns one on success and zero
|
||||
* otherwise. */ |
||||
OPENSSL_EXPORT int BIO_flush(BIO *bio); |
||||
|
||||
|
||||
/* Low-level control functions.
|
||||
* |
||||
* These are generic functions for sending control requests to a BIO. In |
||||
* general one should use the wrapper functions like |BIO_get_close|. */ |
||||
|
||||
/* BIO_ctrl sends the control request |cmd| to |bio|. The |cmd| argument should
|
||||
* be one of the |BIO_C_*| values. */ |
||||
OPENSSL_EXPORT long BIO_ctrl(BIO *bio, int cmd, long larg, void *parg); |
||||
|
||||
/* BIO_ptr_ctrl acts like |BIO_ctrl| but passes the address of a |void*|
|
||||
* pointer as |parg| and returns the value that is written to it, or NULL if |
||||
* the control request returns <= 0. */ |
||||
OPENSSL_EXPORT char *BIO_ptr_ctrl(BIO *bp, int cmd, long larg); |
||||
|
||||
/* BIO_int_ctrl acts like |BIO_ctrl| but passes the address of a copy of |iarg|
|
||||
* as |parg|. */ |
||||
OPENSSL_EXPORT long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); |
||||
|
||||
/* BIO_reset resets |bio| to its initial state, the precise meaning of which
|
||||
* depends on the concrete type of |bio|. It returns one on success and zero |
||||
* otherwise. */ |
||||
OPENSSL_EXPORT int BIO_reset(BIO *bio); |
||||
|
||||
/* BIO_set_flags ORs |flags| with |bio->flags|. */ |
||||
OPENSSL_EXPORT void BIO_set_flags(BIO *bio, int flags); |
||||
|
||||
/* BIO_test_flags returns |bio->flags| AND |flags|. */ |
||||
OPENSSL_EXPORT int BIO_test_flags(const BIO *bio, int flags); |
||||
|
||||
/* BIO_should_read returns non-zero if |bio| encountered a temporary error
|
||||
* while reading (i.e. EAGAIN), indicating that the caller should retry the |
||||
* read. */ |
||||
OPENSSL_EXPORT int BIO_should_read(const BIO *bio); |
||||
|
||||
/* BIO_should_write returns non-zero if |bio| encountered a temporary error
|
||||
* while writing (i.e. EAGAIN), indicating that the caller should retry the |
||||
* write. */ |
||||
OPENSSL_EXPORT int BIO_should_write(const BIO *bio); |
||||
|
||||
/* BIO_should_retry returns non-zero if the reason that caused a failed I/O
|
||||
* operation is temporary and thus the operation should be retried. Otherwise, |
||||
* it was a permanent error and it returns zero. */ |
||||
OPENSSL_EXPORT int BIO_should_retry(const BIO *bio); |
||||
|
||||
/* BIO_should_io_special returns non-zero if |bio| encountered a temporary
|
||||
* error while performing a special I/O operation, indicating that the caller |
||||
* should retry. The operation that caused the error is returned by |
||||
* |BIO_get_retry_reason|. */ |
||||
OPENSSL_EXPORT int BIO_should_io_special(const BIO *bio); |
||||
|
||||
/* BIO_RR_SSL_X509_LOOKUP indicates that an SSL BIO blocked because the SSL
|
||||
* library returned with SSL_ERROR_WANT_X509_LOOKUP. |
||||
* |
||||
* TODO(fork): remove. */ |
||||
#define BIO_RR_SSL_X509_LOOKUP 0x01 |
||||
|
||||
/* BIO_RR_CONNECT indicates that a connect would have blocked */ |
||||
#define BIO_RR_CONNECT 0x02 |
||||
|
||||
/* BIO_RR_ACCEPT indicates that an accept would have blocked */ |
||||
#define BIO_RR_ACCEPT 0x03 |
||||
|
||||
/* BIO_RR_SSL_CHANNEL_ID_LOOKUP indicates that the ChannelID code cannot find
|
||||
* a private key for a TLS connection. */ |
||||
#define BIO_RR_SSL_CHANNEL_ID_LOOKUP 0x04 |
||||
|
||||
/* BIO_get_retry_reason returns the special I/O operation that needs to be
|
||||
* retried. The return value is one of the |BIO_RR_*| values. */ |
||||
OPENSSL_EXPORT int BIO_get_retry_reason(const BIO *bio); |
||||
|
||||
/* BIO_clear_flags ANDs |bio->flags| with the bitwise-complement of |flags|. */ |
||||
OPENSSL_EXPORT void BIO_clear_flags(BIO *bio, int flags); |
||||
|
||||
/* BIO_set_retry_read sets the |BIO_FLAGS_READ| and |BIO_FLAGS_SHOULD_RETRY|
|
||||
* flags on |bio|. */ |
||||
OPENSSL_EXPORT void BIO_set_retry_read(BIO *bio); |
||||
|
||||
/* BIO_set_retry_read sets the |BIO_FLAGS_WRITE| and |BIO_FLAGS_SHOULD_RETRY|
|
||||
* flags on |bio|. */ |
||||
OPENSSL_EXPORT void BIO_set_retry_write(BIO *bio); |
||||
|
||||
/* BIO_get_retry_flags gets the |BIO_FLAGS_READ|, |BIO_FLAGS_WRITE|,
|
||||
* |BIO_FLAGS_IO_SPECIAL| and |BIO_FLAGS_SHOULD_RETRY| flags from |bio|. */ |
||||
OPENSSL_EXPORT int BIO_get_retry_flags(BIO *bio); |
||||
|
||||
/* BIO_clear_retry_flags clears the |BIO_FLAGS_READ|, |BIO_FLAGS_WRITE|,
|
||||
* |BIO_FLAGS_IO_SPECIAL| and |BIO_FLAGS_SHOULD_RETRY| flags from |bio|. */ |
||||
OPENSSL_EXPORT void BIO_clear_retry_flags(BIO *bio); |
||||
|
||||
/* BIO_method_type returns the type of |bio|, which is one of the |BIO_TYPE_*|
|
||||
* values. */ |
||||
OPENSSL_EXPORT int BIO_method_type(const BIO *bio); |
||||
|
||||
/* bio_info_cb is the type of a callback function that can be called for most
|
||||
* BIO operations. The |event| argument is one of |BIO_CB_*| and can be ORed |
||||
* with |BIO_CB_RETURN| if the callback is being made after the operation in |
||||
* question. In that case, |return_value| will contain the return value from |
||||
* the operation. */ |
||||
typedef long (*bio_info_cb)(BIO *bio, int event, const char *parg, int cmd, |
||||
long larg, long return_value); |
||||
|
||||
/* BIO_callback_ctrl allows the callback function to be manipulated. The |cmd|
|
||||
* arg will generally be |BIO_CTRL_SET_CALLBACK| but arbitary command values |
||||
* can be interpreted by the |BIO|. */ |
||||
OPENSSL_EXPORT long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp); |
||||
|
||||
/* BIO_pending returns the number of bytes pending to be read. */ |
||||
OPENSSL_EXPORT size_t BIO_pending(const BIO *bio); |
||||
|
||||
/* BIO_ctrl_pending calls |BIO_pending| and exists only for compatibility with
|
||||
* OpenSSL. */ |
||||
OPENSSL_EXPORT size_t BIO_ctrl_pending(const BIO *bio); |
||||
|
||||
/* BIO_wpending returns the number of bytes pending to be written. */ |
||||
OPENSSL_EXPORT size_t BIO_wpending(const BIO *bio); |
||||
|
||||
/* BIO_set_close sets the close flag for |bio|. The meaning of which depends on
|
||||
* the type of |bio| but, for example, a memory BIO interprets the close flag |
||||
* as meaning that it owns its buffer. It returns one on success and zero |
||||
* otherwise. */ |
||||
OPENSSL_EXPORT int BIO_set_close(BIO *bio, int close_flag); |
||||
|
||||
/* BIO_set_callback sets a callback function that will be called before and
|
||||
* after most operations. See the comment above |bio_info_cb|. */ |
||||
OPENSSL_EXPORT void BIO_set_callback(BIO *bio, bio_info_cb callback_func); |
||||
|
||||
/* BIO_set_callback_arg sets the opaque pointer value that can be read within a
|
||||
* callback with |BIO_get_callback_arg|. */ |
||||
OPENSSL_EXPORT void BIO_set_callback_arg(BIO *bio, char *arg); |
||||
|
||||
/* BIO_get_callback_arg returns the last value of the opaque callback pointer
|
||||
* set by |BIO_set_callback_arg|. */ |
||||
OPENSSL_EXPORT char *BIO_get_callback_arg(const BIO *bio); |
||||
|
||||
/* BIO_number_read returns the number of bytes that have been read from
|
||||
* |bio|. */ |
||||
OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio); |
||||
|
||||
/* BIO_number_written returns the number of bytes that have been written to
|
||||
* |bio|. */ |
||||
OPENSSL_EXPORT size_t BIO_number_written(const BIO *bio); |
||||
|
||||
|
||||
/* Managing chains of BIOs.
|
||||
* |
||||
* BIOs can be put into chains where the output of one is used as the input of |
||||
* the next etc. The most common case is a buffering BIO, which accepts and |
||||
* buffers writes until flushed into the next BIO in the chain. */ |
||||
|
||||
/* BIO_push adds |appended_bio| to the end of the chain with |bio| at the head.
|
||||
* It returns |bio|. Note that |appended_bio| may be the head of a chain itself |
||||
* and thus this function can be used to join two chains. |
||||
* |
||||
* BIO_push takes ownership of the caller's reference to |appended_bio|. */ |
||||
OPENSSL_EXPORT BIO *BIO_push(BIO *bio, BIO *appended_bio); |
||||
|
||||
/* BIO_pop removes |bio| from the head of a chain and returns the next BIO in
|
||||
* the chain, or NULL if there is no next BIO. |
||||
* |
||||
* The caller takes ownership of the chain's reference to |bio|. */ |
||||
OPENSSL_EXPORT BIO *BIO_pop(BIO *bio); |
||||
|
||||
/* BIO_next returns the next BIO in the chain after |bio|, or NULL if there is
|
||||
* no such BIO. */ |
||||
OPENSSL_EXPORT BIO *BIO_next(BIO *bio); |
||||
|
||||
/* BIO_free_all calls |BIO_free|.
|
||||
* |
||||
* TODO(fork): update callers and remove. */ |
||||
OPENSSL_EXPORT void BIO_free_all(BIO *bio); |
||||
|
||||
/* BIO_find_type walks a chain of BIOs and returns the first that matches
|
||||
* |type|, which is one of the |BIO_TYPE_*| values. */ |
||||
OPENSSL_EXPORT BIO *BIO_find_type(BIO *bio, int type); |
||||
|
||||
/* BIO_copy_next_retry sets the retry flags and |retry_reason| of |bio| from
|
||||
* the next BIO in the chain. */ |
||||
OPENSSL_EXPORT void BIO_copy_next_retry(BIO *bio); |
||||
|
||||
|
||||
/* Printf functions.
|
||||
* |
||||
* These functions are versions of printf functions that output to a BIO rather |
||||
* than a FILE. */ |
||||
#ifdef __GNUC__ |
||||
#define __bio_h__attr__ __attribute__ |
||||
#else |
||||
#define __bio_h__attr__(x) |
||||
#endif |
||||
OPENSSL_EXPORT int BIO_printf(BIO *bio, const char *format, ...) |
||||
__bio_h__attr__((__format__(__printf__, 2, 3))); |
||||
#undef __bio_h__attr__ |
||||
|
||||
|
||||
/* Utility functions. */ |
||||
|
||||
/* BIO_indent prints min(|indent|, |max_indent|) spaces. It returns one on
|
||||
* success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_indent(BIO *bio, unsigned indent, unsigned max_indent); |
||||
|
||||
/* BIO_hexdump writes a hex dump of |data| to |bio|. Each line will be indented
|
||||
* by |indent| spaces. */ |
||||
OPENSSL_EXPORT int BIO_hexdump(BIO *bio, const uint8_t *data, size_t len, |
||||
unsigned indent); |
||||
|
||||
/* BIO_print_errors prints the current contents of the error stack to |bio|
|
||||
* using human readable strings where possible. */ |
||||
OPENSSL_EXPORT void BIO_print_errors(BIO *bio); |
||||
|
||||
/* BIO_read_asn1 reads a single ASN.1 object from |bio|. If successful it sets
|
||||
* |*out| to be an allocated buffer (that should be freed with |OPENSSL_free|), |
||||
* |*out_size| to the length, in bytes, of that buffer and returns one. |
||||
* Otherwise it returns zero. |
||||
* |
||||
* If the length of the object is greater than |max_len| or 2^32 then the |
||||
* function will fail. Long-form tags are not supported. If the length of the |
||||
* object is indefinite the full contents of |bio| are read, unless it would be |
||||
* greater than |max_len|, in which case the function fails. |
||||
* |
||||
* If the function fails then some unknown amount of data may have been read |
||||
* from |bio|. */ |
||||
OPENSSL_EXPORT int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, |
||||
size_t max_len); |
||||
|
||||
|
||||
/* Memory BIOs.
|
||||
* |
||||
* Memory BIOs can be used as a read-only source (with |BIO_new_mem_buf|) or a |
||||
* writable sink (with |BIO_new|, |BIO_s_mem| and |BIO_get_mem_buf|). Data |
||||
* written to a writable, memory BIO can be recalled by reading from it. |
||||
* |
||||
* Calling |BIO_reset| on a read-only BIO resets it to the original contents. |
||||
* On a writable BIO, it clears any data. |
||||
* |
||||
* If the close flag is set to |BIO_NOCLOSE| (not the default) then the |
||||
* underlying |BUF_MEM| will not be freed when the |BIO| is freed. |
||||
* |
||||
* Memory BIOs support |BIO_gets| and |BIO_puts|. |
||||
* |
||||
* |BIO_eof| is true if no data is in the BIO. |
||||
* |
||||
* |BIO_ctrl_pending| returns the number of bytes currently stored. */ |
||||
|
||||
/* BIO_s_mem returns a |BIO_METHOD| that uses a in-memory buffer. */ |
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_s_mem(void); |
||||
|
||||
/* BIO_new_mem_buf creates BIO that reads and writes from |len| bytes at |buf|.
|
||||
* It does not take ownership of |buf|. It returns the BIO or NULL on error. |
||||
* |
||||
* If |len| is negative, then |buf| is treated as a NUL-terminated string, but |
||||
* don't depend on this in new code. */ |
||||
OPENSSL_EXPORT BIO *BIO_new_mem_buf(void *buf, int len); |
||||
|
||||
/* BIO_mem_contents sets |*out_contents| to point to the current contents of
|
||||
* |bio| and |*out_len| to contain the length of that data. It returns one on |
||||
* success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_mem_contents(const BIO *bio, |
||||
const uint8_t **out_contents, |
||||
size_t *out_len); |
||||
|
||||
/* BIO_get_mem_data sets |*contents| to point to the current contents of |bio|
|
||||
* and returns the length of the data. |
||||
* |
||||
* WARNING: don't use this, use |BIO_mem_contents|. A return value of zero from |
||||
* this function can mean either that it failed or that the memory buffer is |
||||
* empty. */ |
||||
OPENSSL_EXPORT long BIO_get_mem_data(BIO *bio, char **contents); |
||||
|
||||
/* BIO_get_mem_ptr sets |*out| to a BUF_MEM containing the current contents of
|
||||
* |bio|. It returns one on success or zero on error. */ |
||||
OPENSSL_EXPORT int BIO_get_mem_ptr(BIO *bio, BUF_MEM **out); |
||||
|
||||
/* BIO_set_mem_buf sets |b| as the contents of |bio|. If |take_ownership| is
|
||||
* non-zero, then |b| will be freed when |bio| is closed. Returns one on |
||||
* success or zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_set_mem_buf(BIO *bio, BUF_MEM *b, int take_ownership); |
||||
|
||||
/* BIO_set_mem_eof_return sets the value that will be returned from reading
|
||||
* |bio| when empty. If |eof_value| is zero then an empty memory BIO will |
||||
* return EOF (that is it will return zero and |BIO_should_retry| will be |
||||
* false). If |eof_value| is non zero then it will return |eof_value| when it |
||||
* is empty and it will set the read retry flag (that is |BIO_read_retry| is |
||||
* true). To avoid ambiguity with a normal positive return value, |eof_value| |
||||
* should be set to a negative value, typically -1. |
||||
* |
||||
* For a read-only BIO, the default is zero (EOF). For a writable BIO, the |
||||
* default is -1 so that additional data can be written once exhausted. */ |
||||
OPENSSL_EXPORT int BIO_set_mem_eof_return(BIO *bio, int eof_value); |
||||
|
||||
|
||||
/* File descriptor BIOs.
|
||||
* |
||||
* File descriptor BIOs are wrappers around the system's |read| and |write| |
||||
* functions. If the close flag is set then then |close| is called on the |
||||
* underlying file descriptor when the BIO is freed. |
||||
* |
||||
* |BIO_reset| attempts to seek the file pointer to the start of file using |
||||
* |lseek|. |
||||
* |
||||
* |BIO_seek| sets the file pointer to position |off| from start of file using |
||||
* |lseek|. |
||||
* |
||||
* |BIO_tell| returns the current file position. */ |
||||
|
||||
/* BIO_s_fd returns a |BIO_METHOD| for file descriptor fds. */ |
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_s_fd(void); |
||||
|
||||
/* BIO_new_fd creates a new file descriptor BIO wrapping |fd|. If |close_flag|
|
||||
* is non-zero, then |fd| will be closed when the BIO is. */ |
||||
OPENSSL_EXPORT BIO *BIO_new_fd(int fd, int close_flag); |
||||
|
||||
/* BIO_set_fd sets the file descriptor of |bio| to |fd|. If |close_flag| is
|
||||
* non-zero then |fd| will be closed when |bio| is. It returns one on success |
||||
* or zero on error. */ |
||||
OPENSSL_EXPORT int BIO_set_fd(BIO *bio, int fd, int close_flag); |
||||
|
||||
/* BIO_get_fd sets |*out_fd| to the file descriptor currently in use by |bio|.
|
||||
* It returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BIO_get_fd(BIO *bio, int *out_fd); |
||||
|
||||
|
||||
/* File BIOs.
|
||||
* |
||||
* File BIOs are wrappers around a C |FILE| object. |
||||
* |
||||
* |BIO_flush| on a file BIO calls |fflush| on the wrapped stream. |
||||
* |
||||
* |BIO_reset| attempts to seek the file pointer to the start of file using |
||||
* |fseek|. |
||||
* |
||||
* |BIO_seek| sets the file pointer to the given position from the start of |
||||
* file using |fseek|. |
||||
* |
||||
* |BIO_eof| calls |feof|. |
||||
* |
||||
* Setting the close flag causes |fclose| to be called on the stream when the |
||||
* BIO is freed. */ |
||||
|
||||
/* BIO_s_file returns a BIO_METHOD that wraps a |FILE|. */ |
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_s_file(void); |
||||
|
||||
/* BIO_new_file creates a file BIO by opening |filename| with the given mode.
|
||||
* See the |fopen| manual page for details of the mode argument. */ |
||||
OPENSSL_EXPORT BIO *BIO_new_file(const char *filename, const char *mode); |
||||
|
||||
/* BIO_new_fp creates a new file BIO that wraps the given |FILE|. If
|
||||
* |close_flag| is |BIO_CLOSE|, then |fclose| will be called on |stream| when |
||||
* the BIO is closed. */ |
||||
OPENSSL_EXPORT BIO *BIO_new_fp(FILE *stream, int close_flag); |
||||
|
||||
/* BIO_get_fp sets |*out_file| to the current |FILE| for |bio|. It returns one
|
||||
* on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_get_fp(BIO *bio, FILE **out_file); |
||||
|
||||
/* BIO_set_fp sets the |FILE| for |bio|. If |close_flag| is |BIO_CLOSE| then
|
||||
* |fclose| will be called on |file| when |bio| is closed. It returns one on |
||||
* sucess and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_set_fp(BIO *bio, FILE *file, int close_flag); |
||||
|
||||
/* BIO_read_filename opens |filename| for reading and sets the result as the
|
||||
* |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| |
||||
* will be closed when |bio| is freed. */ |
||||
OPENSSL_EXPORT int BIO_read_filename(BIO *bio, const char *filename); |
||||
|
||||
/* BIO_write_filename opens |filename| for writing and sets the result as the
|
||||
* |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| |
||||
* will be closed when |bio| is freed. */ |
||||
OPENSSL_EXPORT int BIO_write_filename(BIO *bio, const char *filename); |
||||
|
||||
/* BIO_append_filename opens |filename| for appending and sets the result as
|
||||
* the |FILE| for |bio|. It returns one on success and zero otherwise. The |
||||
* |FILE| will be closed when |bio| is freed. */ |
||||
OPENSSL_EXPORT int BIO_append_filename(BIO *bio, const char *filename); |
||||
|
||||
/* BIO_rw_filename opens |filename| for reading and writing and sets the result
|
||||
* as the |FILE| for |bio|. It returns one on success and zero otherwise. The |
||||
* |FILE| will be closed when |bio| is freed. */ |
||||
OPENSSL_EXPORT int BIO_rw_filename(BIO *bio, const char *filename); |
||||
|
||||
|
||||
/* Buffer BIOs.
|
||||
* |
||||
* Buffer BIOs are a filter-type BIO, i.e. they are designed to be used in a |
||||
* chain of BIOs. They provide buffering to reduce the number of operations on |
||||
* the underlying BIOs. */ |
||||
|
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_f_buffer(void); |
||||
|
||||
/* BIO_set_read_buffer_size sets the size, in bytes, of the read buffer and
|
||||
* clears it. It returns one on success and zero on failure. */ |
||||
OPENSSL_EXPORT int BIO_set_read_buffer_size(BIO *bio, int buffer_size); |
||||
|
||||
/* BIO_set_write_buffer_size sets the size, in bytes, of the write buffer and
|
||||
* clears it. It returns one on success and zero on failure. */ |
||||
OPENSSL_EXPORT int BIO_set_write_buffer_size(BIO *bio, int buffer_size); |
||||
|
||||
|
||||
/* Socket BIOs. */ |
||||
|
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_s_socket(void); |
||||
|
||||
/* BIO_new_socket allocates and initialises a fresh BIO which will read and
|
||||
* write to the socket |fd|. If |close_flag| is |BIO_CLOSE| then closing the |
||||
* BIO will close |fd|. It returns the fresh |BIO| or NULL on error. */ |
||||
OPENSSL_EXPORT BIO *BIO_new_socket(int fd, int close_flag); |
||||
|
||||
|
||||
/* Connect BIOs.
|
||||
* |
||||
* A connection BIO creates a network connection and transfers data over the |
||||
* resulting socket. */ |
||||
|
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_s_connect(void); |
||||
|
||||
/* BIO_new_connect returns a BIO that connects to the given hostname and port.
|
||||
* The |host_and_optional_port| argument should be of the form |
||||
* "www.example.com" or "www.example.com:443". If the port is omitted, it must |
||||
* be provided with |BIO_set_conn_port|. |
||||
* |
||||
* It returns the new BIO on success, or NULL on error. */ |
||||
OPENSSL_EXPORT BIO *BIO_new_connect(const char *host_and_optional_port); |
||||
|
||||
/* BIO_set_conn_hostname sets |host_and_optional_port| as the hostname and
|
||||
* optional port that |bio| will connect to. If the port is omitted, it must be |
||||
* provided with |BIO_set_conn_port|. |
||||
* |
||||
* It returns one on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_set_conn_hostname(BIO *bio, |
||||
const char *host_and_optional_port); |
||||
|
||||
/* BIO_set_conn_port sets |port_str| as the port or service name that |bio|
|
||||
* will connect to. It returns one on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_set_conn_port(BIO *bio, const char *port_str); |
||||
|
||||
/* BIO_set_nbio sets whether |bio| will use non-blocking I/O operations. It
|
||||
* returns one on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_set_nbio(BIO *bio, int on); |
||||
|
||||
|
||||
/* Datagram BIOs.
|
||||
* |
||||
* TODO(fork): not implemented. */ |
||||
|
||||
#define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */ |
||||
|
||||
#define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for MTU. want to use |
||||
this if asking the kernel fails */ |
||||
|
||||
#define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU was exceed in |
||||
the previous write operation. */ |
||||
|
||||
#define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT \ |
||||
45 /* Next DTLS handshake timeout to adjust socket timeouts */ |
||||
|
||||
#define BIO_CTRL_DGRAM_GET_PEER 46 |
||||
|
||||
#define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 |
||||
|
||||
|
||||
/* BIO Pairs.
|
||||
* |
||||
* BIO pairs provide a "loopback" like system: a pair of BIOs where data |
||||
* written to one can be read from the other and vice versa. */ |
||||
|
||||
/* BIO_new_bio_pair sets |*out1| and |*out2| to two freshly created BIOs where
|
||||
* data written to one can be read from the other and vice versa. The |
||||
* |writebuf1| argument gives the size of the buffer used in |*out1| and |
||||
* |writebuf2| for |*out2|. It returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BIO_new_bio_pair(BIO **out1, size_t writebuf1, BIO **out2, |
||||
size_t writebuf2); |
||||
|
||||
/* BIO_new_bio_pair_external_buf is the same as |BIO_new_bio_pair| with the
|
||||
* difference that the caller keeps ownership of the write buffers |
||||
* |ext_writebuf1_len| and |ext_writebuf2_len|. This is useful when using zero |
||||
* copy API for read and write operations, in cases where the buffers need to |
||||
* outlive the BIO pairs. It returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BIO_new_bio_pair_external_buf(BIO** bio1_p, |
||||
size_t writebuf1_len, |
||||
uint8_t* ext_writebuf1, |
||||
BIO** bio2_p, |
||||
size_t writebuf2_len, |
||||
uint8_t* ext_writebuf2); |
||||
|
||||
/* BIO_ctrl_get_read_request returns the number of bytes that the other side of
|
||||
* |bio| tried (unsuccessfully) to read. */ |
||||
OPENSSL_EXPORT size_t BIO_ctrl_get_read_request(BIO *bio); |
||||
|
||||
/* BIO_ctrl_get_write_guarantee returns the number of bytes that |bio| (which
|
||||
* must have been returned by |BIO_new_bio_pair|) will accept on the next |
||||
* |BIO_write| call. */ |
||||
OPENSSL_EXPORT size_t BIO_ctrl_get_write_guarantee(BIO *bio); |
||||
|
||||
/* BIO_shutdown_wr marks |bio| as closed, from the point of view of the other
|
||||
* side of the pair. Future |BIO_write| calls on |bio| will fail. It returns |
||||
* one on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BIO_shutdown_wr(BIO *bio); |
||||
|
||||
|
||||
/* Zero copy versions of BIO_read and BIO_write for BIO pairs. */ |
||||
|
||||
/* BIO_zero_copy_get_read_buf initiates a zero copy read operation.
|
||||
* |out_read_buf| is set to the internal read buffer, and |out_buf_offset| is |
||||
* set to the current read position of |out_read_buf|. The number of bytes |
||||
* available for read from |out_read_buf| + |out_buf_offset| is returned in |
||||
* |out_available_bytes|. Note that this function might report fewer bytes |
||||
* available than |BIO_pending|, if the internal ring buffer is wrapped. It |
||||
* returns one on success. In case of error it returns zero and pushes to the |
||||
* error stack. |
||||
* |
||||
* The zero copy read operation is completed by calling |
||||
* |BIO_zero_copy_get_read_buf_done|. Neither |BIO_zero_copy_get_read_buf| nor |
||||
* any other I/O read operation may be called while a zero copy read operation |
||||
* is active. */ |
||||
OPENSSL_EXPORT int BIO_zero_copy_get_read_buf(BIO* bio, |
||||
uint8_t** out_read_buf, |
||||
size_t* out_buf_offset, |
||||
size_t* out_available_bytes); |
||||
|
||||
/* BIO_zero_copy_get_read_buf_done must be called after reading from a BIO using
|
||||
* |BIO_zero_copy_get_read_buf| to finish the read operation. The |bytes_read| |
||||
* argument is the number of bytes read. |
||||
* |
||||
* It returns one on success. In case of error it returns zero and pushes to the |
||||
* error stack. */ |
||||
OPENSSL_EXPORT int BIO_zero_copy_get_read_buf_done(BIO* bio, size_t bytes_read); |
||||
|
||||
/* BIO_zero_copy_get_write_buf_done initiates a zero copy write operation.
|
||||
* |out_write_buf| is set to to the internal write buffer, and |out_buf_offset| |
||||
* is set to the current write position of |out_write_buf|. |
||||
* The number of bytes available for write from |out_write_buf| + |
||||
* |out_buf_offset| is returned in |out_available_bytes|. Note that this |
||||
* function might report fewer bytes available than |
||||
* |BIO_ctrl_get_write_guarantee|, if the internal buffer is wrapped. It returns |
||||
* one on success. In case of error it returns zero and pushes to the error |
||||
* stack. |
||||
* |
||||
* The zero copy write operation is completed by calling |
||||
* |BIO_zero_copy_write_buf_done|. Neither |BIO_zero_copy_get_write_buf| |
||||
* nor any other I/O write operation may be called while a zero copy write |
||||
* operation is active. */ |
||||
OPENSSL_EXPORT int BIO_zero_copy_get_write_buf(BIO* bio, |
||||
uint8_t** out_write_buf, |
||||
size_t* out_buf_offset, |
||||
size_t* out_available_bytes); |
||||
|
||||
/* BIO_zero_copy_write_buf_done must be called after writing to a BIO using
|
||||
* |BIO_zero_copy_get_write_buf_done| to finish the write operation. The |
||||
* |bytes_written| argument gives the number of bytes written. |
||||
* |
||||
* It returns one on success. In case of error it returns zero and pushes to the |
||||
* error stack. */ |
||||
OPENSSL_EXPORT int BIO_zero_copy_get_write_buf_done(BIO* bio, |
||||
size_t bytes_written); |
||||
|
||||
|
||||
/* BIO_NOCLOSE and |BIO_CLOSE| can be used as symbolic arguments when a "close
|
||||
* flag" is passed to a BIO function. */ |
||||
#define BIO_NOCLOSE 0 |
||||
#define BIO_CLOSE 1 |
||||
|
||||
/* These are passed to the BIO callback */ |
||||
#define BIO_CB_FREE 0x01 |
||||
#define BIO_CB_READ 0x02 |
||||
#define BIO_CB_WRITE 0x03 |
||||
#define BIO_CB_PUTS 0x04 |
||||
#define BIO_CB_GETS 0x05 |
||||
#define BIO_CB_CTRL 0x06 |
||||
|
||||
/* The callback is called before and after the underling operation,
|
||||
* The BIO_CB_RETURN flag indicates if it is after the call */ |
||||
#define BIO_CB_RETURN 0x80 |
||||
|
||||
/* These are values of the |cmd| argument to |BIO_ctrl|. */ |
||||
#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ |
||||
#define BIO_CTRL_EOF 2 /* opt - are we at the eof */ |
||||
#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ |
||||
#define BIO_CTRL_SET 4 /* man - set the 'IO' type */ |
||||
#define BIO_CTRL_GET 5 /* man - get the 'IO' type */ |
||||
#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ |
||||
#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ |
||||
#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ |
||||
#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ |
||||
#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ |
||||
/* callback is int cb(BIO *bio,state,ret); */ |
||||
#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ |
||||
#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ |
||||
#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ |
||||
|
||||
|
||||
/* Android compatibility section.
|
||||
* |
||||
* A previous version of BoringSSL used in Android renamed ERR_print_errors_fp |
||||
* to BIO_print_errors_fp. It has subsequently been renamed back to |
||||
* ERR_print_errors_fp. */ |
||||
#define BIO_print_errors_fp ERR_print_errors_fp |
||||
|
||||
|
||||
/* Private functions */ |
||||
|
||||
#define BIO_FLAGS_READ 0x01 |
||||
#define BIO_FLAGS_WRITE 0x02 |
||||
#define BIO_FLAGS_IO_SPECIAL 0x04 |
||||
#define BIO_FLAGS_RWS (BIO_FLAGS_READ | BIO_FLAGS_WRITE | BIO_FLAGS_IO_SPECIAL) |
||||
#define BIO_FLAGS_SHOULD_RETRY 0x08 |
||||
#define BIO_FLAGS_BASE64_NO_NL 0x100 |
||||
/* This is used with memory BIOs: it means we shouldn't free up or change the
|
||||
* data in any way. */ |
||||
#define BIO_FLAGS_MEM_RDONLY 0x200 |
||||
|
||||
/* These are the 'types' of BIOs */ |
||||
#define BIO_TYPE_NONE 0 |
||||
#define BIO_TYPE_MEM (1 | 0x0400) |
||||
#define BIO_TYPE_FILE (2 | 0x0400) |
||||
#define BIO_TYPE_FD (4 | 0x0400 | 0x0100) |
||||
#define BIO_TYPE_SOCKET (5 | 0x0400 | 0x0100) |
||||
#define BIO_TYPE_NULL (6 | 0x0400) |
||||
#define BIO_TYPE_SSL (7 | 0x0200) |
||||
#define BIO_TYPE_MD (8 | 0x0200) /* passive filter */ |
||||
#define BIO_TYPE_BUFFER (9 | 0x0200) /* filter */ |
||||
#define BIO_TYPE_CIPHER (10 | 0x0200) /* filter */ |
||||
#define BIO_TYPE_BASE64 (11 | 0x0200) /* filter */ |
||||
#define BIO_TYPE_CONNECT (12 | 0x0400 | 0x0100) /* socket - connect */ |
||||
#define BIO_TYPE_ACCEPT (13 | 0x0400 | 0x0100) /* socket for accept */ |
||||
#define BIO_TYPE_PROXY_CLIENT (14 | 0x0200) /* client proxy BIO */ |
||||
#define BIO_TYPE_PROXY_SERVER (15 | 0x0200) /* server proxy BIO */ |
||||
#define BIO_TYPE_NBIO_TEST (16 | 0x0200) /* server proxy BIO */ |
||||
#define BIO_TYPE_NULL_FILTER (17 | 0x0200) |
||||
#define BIO_TYPE_BER (18 | 0x0200) /* BER -> bin filter */ |
||||
#define BIO_TYPE_BIO (19 | 0x0400) /* (half a) BIO pair */ |
||||
#define BIO_TYPE_LINEBUFFER (20 | 0x0200) /* filter */ |
||||
#define BIO_TYPE_DGRAM (21 | 0x0400 | 0x0100) |
||||
#define BIO_TYPE_ASN1 (22 | 0x0200) /* filter */ |
||||
#define BIO_TYPE_COMP (23 | 0x0200) /* filter */ |
||||
|
||||
#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ |
||||
#define BIO_TYPE_FILTER 0x0200 |
||||
#define BIO_TYPE_SOURCE_SINK 0x0400 |
||||
|
||||
struct bio_method_st { |
||||
int type; |
||||
const char *name; |
||||
int (*bwrite)(BIO *, const char *, int); |
||||
int (*bread)(BIO *, char *, int); |
||||
/* TODO(fork): remove bputs. */ |
||||
int (*bputs)(BIO *, const char *); |
||||
int (*bgets)(BIO *, char *, int); |
||||
long (*ctrl)(BIO *, int, long, void *); |
||||
int (*create)(BIO *); |
||||
int (*destroy)(BIO *); |
||||
long (*callback_ctrl)(BIO *, int, bio_info_cb); |
||||
}; |
||||
|
||||
struct bio_st { |
||||
const BIO_METHOD *method; |
||||
/* bio, mode, argp, argi, argl, ret */ |
||||
long (*callback)(struct bio_st *, int, const char *, int, long, long); |
||||
char *cb_arg; /* first argument for the callback */ |
||||
|
||||
/* init is non-zero if this |BIO| has been initialised. */ |
||||
int init; |
||||
/* shutdown is often used by specific |BIO_METHOD|s to determine whether
|
||||
* they own some underlying resource. This flag can often by controlled by |
||||
* |BIO_set_close|. For example, whether an fd BIO closes the underlying fd |
||||
* when it, itself, is closed. */ |
||||
int shutdown; |
||||
int flags; |
||||
int retry_reason; |
||||
/* num is a BIO-specific value. For example, in fd BIOs it's used to store a
|
||||
* file descriptor. */ |
||||
int num; |
||||
CRYPTO_refcount_t references; |
||||
void *ptr; |
||||
/* next_bio points to the next |BIO| in a chain. This |BIO| owns a reference
|
||||
* to |next_bio|. */ |
||||
struct bio_st *next_bio; /* used by filter BIOs */ |
||||
size_t num_read, num_write; |
||||
}; |
||||
|
||||
#define BIO_C_SET_CONNECT 100 |
||||
#define BIO_C_DO_STATE_MACHINE 101 |
||||
#define BIO_C_SET_NBIO 102 |
||||
#define BIO_C_SET_PROXY_PARAM 103 |
||||
#define BIO_C_SET_FD 104 |
||||
#define BIO_C_GET_FD 105 |
||||
#define BIO_C_SET_FILE_PTR 106 |
||||
#define BIO_C_GET_FILE_PTR 107 |
||||
#define BIO_C_SET_FILENAME 108 |
||||
#define BIO_C_SET_SSL 109 |
||||
#define BIO_C_GET_SSL 110 |
||||
#define BIO_C_SET_MD 111 |
||||
#define BIO_C_GET_MD 112 |
||||
#define BIO_C_GET_CIPHER_STATUS 113 |
||||
#define BIO_C_SET_BUF_MEM 114 |
||||
#define BIO_C_GET_BUF_MEM_PTR 115 |
||||
#define BIO_C_GET_BUFF_NUM_LINES 116 |
||||
#define BIO_C_SET_BUFF_SIZE 117 |
||||
#define BIO_C_SET_ACCEPT 118 |
||||
#define BIO_C_SSL_MODE 119 |
||||
#define BIO_C_GET_MD_CTX 120 |
||||
#define BIO_C_GET_PROXY_PARAM 121 |
||||
#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ |
||||
#define BIO_C_GET_CONNECT 123 |
||||
#define BIO_C_GET_ACCEPT 124 |
||||
#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 |
||||
#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 |
||||
#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 |
||||
#define BIO_C_FILE_SEEK 128 |
||||
#define BIO_C_GET_CIPHER_CTX 129 |
||||
#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ |
||||
#define BIO_C_SET_BIND_MODE 131 |
||||
#define BIO_C_GET_BIND_MODE 132 |
||||
#define BIO_C_FILE_TELL 133 |
||||
#define BIO_C_GET_SOCKS 134 |
||||
#define BIO_C_SET_SOCKS 135 |
||||
|
||||
#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ |
||||
#define BIO_C_GET_WRITE_BUF_SIZE 137 |
||||
#define BIO_C_GET_WRITE_GUARANTEE 140 |
||||
#define BIO_C_GET_READ_REQUEST 141 |
||||
#define BIO_C_SHUTDOWN_WR 142 |
||||
#define BIO_C_NREAD0 143 |
||||
#define BIO_C_NREAD 144 |
||||
#define BIO_C_NWRITE0 145 |
||||
#define BIO_C_NWRITE 146 |
||||
#define BIO_C_RESET_READ_REQUEST 147 |
||||
#define BIO_C_SET_MD_CTX 148 |
||||
|
||||
#define BIO_C_SET_PREFIX 149 |
||||
#define BIO_C_GET_PREFIX 150 |
||||
#define BIO_C_SET_SUFFIX 151 |
||||
#define BIO_C_GET_SUFFIX 152 |
||||
|
||||
#define BIO_C_SET_EX_ARG 153 |
||||
#define BIO_C_GET_EX_ARG 154 |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#define BIO_F_BIO_callback_ctrl 100 |
||||
#define BIO_F_BIO_ctrl 101 |
||||
#define BIO_F_BIO_new 102 |
||||
#define BIO_F_BIO_new_file 103 |
||||
#define BIO_F_BIO_new_mem_buf 104 |
||||
#define BIO_F_BIO_zero_copy_get_read_buf 105 |
||||
#define BIO_F_BIO_zero_copy_get_read_buf_done 106 |
||||
#define BIO_F_BIO_zero_copy_get_write_buf 107 |
||||
#define BIO_F_BIO_zero_copy_get_write_buf_done 108 |
||||
#define BIO_F_bio_io 109 |
||||
#define BIO_F_bio_make_pair 110 |
||||
#define BIO_F_bio_write 111 |
||||
#define BIO_F_buffer_ctrl 112 |
||||
#define BIO_F_conn_ctrl 113 |
||||
#define BIO_F_conn_state 114 |
||||
#define BIO_F_file_ctrl 115 |
||||
#define BIO_F_file_read 116 |
||||
#define BIO_F_mem_write 117 |
||||
#define BIO_F_BIO_printf 118 |
||||
#define BIO_R_BAD_FOPEN_MODE 100 |
||||
#define BIO_R_BROKEN_PIPE 101 |
||||
#define BIO_R_CONNECT_ERROR 102 |
||||
#define BIO_R_ERROR_SETTING_NBIO 103 |
||||
#define BIO_R_INVALID_ARGUMENT 104 |
||||
#define BIO_R_IN_USE 105 |
||||
#define BIO_R_KEEPALIVE 106 |
||||
#define BIO_R_NBIO_CONNECT_ERROR 107 |
||||
#define BIO_R_NO_HOSTNAME_SPECIFIED 108 |
||||
#define BIO_R_NO_PORT_SPECIFIED 109 |
||||
#define BIO_R_NO_SUCH_FILE 110 |
||||
#define BIO_R_NULL_PARAMETER 111 |
||||
#define BIO_R_SYS_LIB 112 |
||||
#define BIO_R_UNABLE_TO_CREATE_SOCKET 113 |
||||
#define BIO_R_UNINITIALIZED 114 |
||||
#define BIO_R_UNSUPPORTED_METHOD 115 |
||||
#define BIO_R_WRITE_TO_READ_ONLY_BIO 116 |
||||
|
||||
#endif /* OPENSSL_HEADER_BIO_H */ |
@ -1,93 +0,0 @@ |
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] */ |
||||
|
||||
#ifndef OPENSSL_HEADER_BLOWFISH_H |
||||
#define OPENSSL_HEADER_BLOWFISH_H |
||||
|
||||
#include <openssl/base.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
#define BF_ENCRYPT 1 |
||||
#define BF_DECRYPT 0 |
||||
|
||||
#define BF_ROUNDS 16 |
||||
#define BF_BLOCK 8 |
||||
|
||||
typedef struct bf_key_st { |
||||
uint32_t P[BF_ROUNDS + 2]; |
||||
uint32_t S[4 * 256]; |
||||
} BF_KEY; |
||||
|
||||
OPENSSL_EXPORT void BF_set_key(BF_KEY *key, size_t len, const uint8_t *data); |
||||
OPENSSL_EXPORT void BF_encrypt(uint32_t *data, const BF_KEY *key); |
||||
OPENSSL_EXPORT void BF_decrypt(uint32_t *data, const BF_KEY *key); |
||||
|
||||
OPENSSL_EXPORT void BF_ecb_encrypt(const uint8_t *in, uint8_t *out, |
||||
const BF_KEY *key, int enc); |
||||
OPENSSL_EXPORT void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, |
||||
const BF_KEY *schedule, uint8_t *ivec, |
||||
int enc); |
||||
|
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* OPENSSL_HEADER_BLOWFISH_H */ |
@ -1,875 +0,0 @@ |
||||
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] |
||||
*/ |
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* 3. All advertising materials mentioning features or use of this |
||||
* software must display the following acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
* |
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
||||
* endorse or promote products derived from this software without |
||||
* prior written permission. For written permission, please contact |
||||
* openssl-core@openssl.org. |
||||
* |
||||
* 5. Products derived from this software may not be called "OpenSSL" |
||||
* nor may "OpenSSL" appear in their names without prior written |
||||
* permission of the OpenSSL Project. |
||||
* |
||||
* 6. Redistributions of any form whatsoever must retain the following |
||||
* acknowledgment: |
||||
* "This product includes software developed by the OpenSSL Project |
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
||||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* ==================================================================== |
||||
* |
||||
* This product includes cryptographic software written by Eric Young |
||||
* (eay@cryptsoft.com). This product includes software written by Tim |
||||
* Hudson (tjh@cryptsoft.com). |
||||
* |
||||
*/ |
||||
/* ====================================================================
|
||||
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
||||
* |
||||
* Portions of the attached software ("Contribution") are developed by |
||||
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. |
||||
* |
||||
* The Contribution is licensed pursuant to the Eric Young open source |
||||
* license provided above. |
||||
* |
||||
* The binary polynomial arithmetic software is originally written by |
||||
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems |
||||
* Laboratories. */ |
||||
|
||||
#ifndef OPENSSL_HEADER_BN_H |
||||
#define OPENSSL_HEADER_BN_H |
||||
|
||||
#include <openssl/base.h> |
||||
#include <openssl/thread.h> |
||||
|
||||
#include <inttypes.h> /* for PRIu64 and friends */ |
||||
#include <stdio.h> /* for FILE* */ |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* BN provides support for working with arbitary sized integers. For example,
|
||||
* although the largest integer supported by the compiler might be 64 bits, BN |
||||
* will allow you to work with numbers until you run out of memory. */ |
||||
|
||||
|
||||
/* BN_ULONG is the native word size when working with big integers.
|
||||
* |
||||
* Note: on some platforms, inttypes.h does not define print format macros in |
||||
* C++ unless |__STDC_FORMAT_MACROS| defined. As this is a public header, bn.h |
||||
* does not define |__STDC_FORMAT_MACROS| itself. C++ source files which use the |
||||
* FMT macros must define it externally. */ |
||||
#if defined(OPENSSL_64_BIT) |
||||
#define BN_ULONG uint64_t |
||||
#define BN_BITS2 64 |
||||
#define BN_DEC_FMT1 "%" PRIu64 |
||||
#define BN_DEC_FMT2 "%019" PRIu64 |
||||
#define BN_HEX_FMT1 "%" PRIx64 |
||||
#elif defined(OPENSSL_32_BIT) |
||||
#define BN_ULONG uint32_t |
||||
#define BN_BITS2 32 |
||||
#define BN_DEC_FMT1 "%" PRIu32 |
||||
#define BN_DEC_FMT2 "%09" PRIu32 |
||||
#define BN_HEX_FMT1 "%" PRIx32 |
||||
#else |
||||
#error "Must define either OPENSSL_32_BIT or OPENSSL_64_BIT" |
||||
#endif |
||||
|
||||
|
||||
/* Allocation and freeing. */ |
||||
|
||||
/* BN_new creates a new, allocated BIGNUM and initialises it. */ |
||||
OPENSSL_EXPORT BIGNUM *BN_new(void); |
||||
|
||||
/* BN_init initialises a stack allocated |BIGNUM|. */ |
||||
OPENSSL_EXPORT void BN_init(BIGNUM *bn); |
||||
|
||||
/* BN_free frees the data referenced by |bn| and, if |bn| was originally
|
||||
* allocated on the heap, frees |bn| also. */ |
||||
OPENSSL_EXPORT void BN_free(BIGNUM *bn); |
||||
|
||||
/* BN_clear_free erases and frees the data referenced by |bn| and, if |bn| was
|
||||
* originally allocated on the heap, frees |bn| also. */ |
||||
OPENSSL_EXPORT void BN_clear_free(BIGNUM *bn); |
||||
|
||||
/* BN_dup allocates a new BIGNUM and sets it equal to |src|. It returns the
|
||||
* allocated BIGNUM on success or NULL otherwise. */ |
||||
OPENSSL_EXPORT BIGNUM *BN_dup(const BIGNUM *src); |
||||
|
||||
/* BN_copy sets |dest| equal to |src| and returns |dest|. */ |
||||
OPENSSL_EXPORT BIGNUM *BN_copy(BIGNUM *dest, const BIGNUM *src); |
||||
|
||||
/* BN_clear sets |bn| to zero and erases the old data. */ |
||||
OPENSSL_EXPORT void BN_clear(BIGNUM *bn); |
||||
|
||||
/* BN_value_one returns a static BIGNUM with value 1. */ |
||||
OPENSSL_EXPORT const BIGNUM *BN_value_one(void); |
||||
|
||||
/* BN_with_flags initialises a stack allocated |BIGNUM| with pointers to the
|
||||
* contents of |in| but with |flags| ORed into the flags field. |
||||
* |
||||
* Note: the two BIGNUMs share state and so |out| should /not/ be passed to |
||||
* |BN_free|. */ |
||||
OPENSSL_EXPORT void BN_with_flags(BIGNUM *out, const BIGNUM *in, int flags); |
||||
|
||||
|
||||
/* Basic functions. */ |
||||
|
||||
/* BN_num_bits returns the minimum number of bits needed to represent the
|
||||
* absolute value of |bn|. */ |
||||
OPENSSL_EXPORT unsigned BN_num_bits(const BIGNUM *bn); |
||||
|
||||
/* BN_num_bytes returns the minimum number of bytes needed to represent the
|
||||
* absolute value of |bn|. */ |
||||
OPENSSL_EXPORT unsigned BN_num_bytes(const BIGNUM *bn); |
||||
|
||||
/* BN_zero sets |bn| to zero. */ |
||||
OPENSSL_EXPORT void BN_zero(BIGNUM *bn); |
||||
|
||||
/* BN_one sets |bn| to one. It returns one on success or zero on allocation
|
||||
* failure. */ |
||||
OPENSSL_EXPORT int BN_one(BIGNUM *bn); |
||||
|
||||
/* BN_set_word sets |bn| to |value|. It returns one on success or zero on
|
||||
* allocation failure. */ |
||||
OPENSSL_EXPORT int BN_set_word(BIGNUM *bn, BN_ULONG value); |
||||
|
||||
/* BN_set_negative sets the sign of |bn|. */ |
||||
OPENSSL_EXPORT void BN_set_negative(BIGNUM *bn, int sign); |
||||
|
||||
/* BN_is_negative returns one if |bn| is negative and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_is_negative(const BIGNUM *bn); |
||||
|
||||
/* BN_get_flags returns |bn->flags| & |flags|. */ |
||||
OPENSSL_EXPORT int BN_get_flags(const BIGNUM *bn, int flags); |
||||
|
||||
/* BN_set_flags sets |flags| on |bn|. */ |
||||
OPENSSL_EXPORT void BN_set_flags(BIGNUM *bn, int flags); |
||||
|
||||
|
||||
/* Conversion functions. */ |
||||
|
||||
/* BN_bin2bn sets |*ret| to the value of |len| bytes from |in|, interpreted as
|
||||
* a big-endian number, and returns |ret|. If |ret| is NULL then a fresh |
||||
* |BIGNUM| is allocated and returned. It returns NULL on allocation |
||||
* failure. */ |
||||
OPENSSL_EXPORT BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret); |
||||
|
||||
/* BN_bn2bin serialises the absolute value of |in| to |out| as a big-endian
|
||||
* integer, which must have |BN_num_bytes| of space available. It returns the |
||||
* number of bytes written. */ |
||||
OPENSSL_EXPORT size_t BN_bn2bin(const BIGNUM *in, uint8_t *out); |
||||
|
||||
/* BN_bn2bin_padded serialises the absolute value of |in| to |out| as a
|
||||
* big-endian integer. The integer is padded with leading zeros up to size |
||||
* |len|. If |len| is smaller than |BN_num_bytes|, the function fails and |
||||
* returns 0. Otherwise, it returns 1. */ |
||||
OPENSSL_EXPORT int BN_bn2bin_padded(uint8_t *out, size_t len, const BIGNUM *in); |
||||
|
||||
/* BN_bn2hex returns an allocated string that contains a NUL-terminated, hex
|
||||
* representation of |bn|. If |bn| is negative, the first char in the resulting |
||||
* string will be '-'. Returns NULL on allocation failure. */ |
||||
OPENSSL_EXPORT char *BN_bn2hex(const BIGNUM *bn); |
||||
|
||||
/* BN_hex2bn parses the leading hex number from |in|, which may be proceeded by
|
||||
* a '-' to indicate a negative number and may contain trailing, non-hex data. |
||||
* If |outp| is not NULL, it constructs a BIGNUM equal to the hex number and |
||||
* stores it in |*outp|. If |*outp| is NULL then it allocates a new BIGNUM and |
||||
* updates |*outp|. It returns the number of bytes of |in| processed or zero on |
||||
* error. */ |
||||
OPENSSL_EXPORT int BN_hex2bn(BIGNUM **outp, const char *in); |
||||
|
||||
/* BN_bn2dec returns an allocated string that contains a NUL-terminated,
|
||||
* decimal representation of |bn|. If |bn| is negative, the first char in the |
||||
* resulting string will be '-'. Returns NULL on allocation failure. */ |
||||
OPENSSL_EXPORT char *BN_bn2dec(const BIGNUM *a); |
||||
|
||||
/* BN_dec2bn parses the leading decimal number from |in|, which may be
|
||||
* proceeded by a '-' to indicate a negative number and may contain trailing, |
||||
* non-decimal data. If |outp| is not NULL, it constructs a BIGNUM equal to the |
||||
* decimal number and stores it in |*outp|. If |*outp| is NULL then it |
||||
* allocates a new BIGNUM and updates |*outp|. It returns the number of bytes |
||||
* of |in| processed or zero on error. */ |
||||
OPENSSL_EXPORT int BN_dec2bn(BIGNUM **outp, const char *in); |
||||
|
||||
/* BN_asc2bn acts like |BN_dec2bn| or |BN_hex2bn| depending on whether |in|
|
||||
* begins with "0X" or "0x" (indicating hex) or not (indicating decimal). A |
||||
* leading '-' is still permitted and comes before the optional 0X/0x. It |
||||
* returns one on success or zero on error. */ |
||||
OPENSSL_EXPORT int BN_asc2bn(BIGNUM **outp, const char *in); |
||||
|
||||
/* BN_print writes a hex encoding of |a| to |bio|. It returns one on success
|
||||
* and zero on error. */ |
||||
OPENSSL_EXPORT int BN_print(BIO *bio, const BIGNUM *a); |
||||
|
||||
/* BN_print_fp acts like |BIO_print|, but wraps |fp| in a |BIO| first. */ |
||||
OPENSSL_EXPORT int BN_print_fp(FILE *fp, const BIGNUM *a); |
||||
|
||||
/* BN_get_word returns the absolute value of |bn| as a single word. If |bn| is
|
||||
* too large to be represented as a single word, the maximum possible value |
||||
* will be returned. */ |
||||
OPENSSL_EXPORT BN_ULONG BN_get_word(const BIGNUM *bn); |
||||
|
||||
|
||||
/* Internal functions.
|
||||
* |
||||
* These functions are useful for code that is doing low-level manipulations of |
||||
* BIGNUM values. However, be sure that no other function in this file does |
||||
* what you want before turning to these. */ |
||||
|
||||
/* bn_correct_top decrements |bn->top| until |bn->d[top-1]| is non-zero or
|
||||
* until |top| is zero. */ |
||||
OPENSSL_EXPORT void bn_correct_top(BIGNUM *bn); |
||||
|
||||
/* bn_wexpand ensures that |bn| has at least |words| works of space without
|
||||
* altering its value. It returns one on success or zero on allocation |
||||
* failure. */ |
||||
OPENSSL_EXPORT BIGNUM *bn_wexpand(BIGNUM *bn, unsigned words); |
||||
|
||||
|
||||
/* BIGNUM pools.
|
||||
* |
||||
* Certain BIGNUM operations need to use many temporary variables and |
||||
* allocating and freeing them can be quite slow. Thus such opertions typically |
||||
* take a |BN_CTX| parameter, which contains a pool of |BIGNUMs|. The |ctx| |
||||
* argument to a public function may be NULL, in which case a local |BN_CTX| |
||||
* will be created just for the lifetime of that call. |
||||
* |
||||
* A function must call |BN_CTX_start| first. Then, |BN_CTX_get| may be called |
||||
* repeatedly to obtain temporary |BIGNUM|s. All |BN_CTX_get| calls must be made |
||||
* before calling any other functions that use the |ctx| as an argument. |
||||
* |
||||
* Finally, |BN_CTX_end| must be called before returning from the function. |
||||
* When |BN_CTX_end| is called, the |BIGNUM| pointers obtained from |
||||
* |BN_CTX_get| become invalid. */ |
||||
|
||||
/* BN_CTX_new returns a new, empty BN_CTX or NULL on allocation failure. */ |
||||
OPENSSL_EXPORT BN_CTX *BN_CTX_new(void); |
||||
|
||||
/* BN_CTX_free frees all BIGNUMs contained in |ctx| and then frees |ctx|
|
||||
* itself. */ |
||||
OPENSSL_EXPORT void BN_CTX_free(BN_CTX *ctx); |
||||
|
||||
/* BN_CTX_start "pushes" a new entry onto the |ctx| stack and allows future
|
||||
* calls to |BN_CTX_get|. */ |
||||
OPENSSL_EXPORT void BN_CTX_start(BN_CTX *ctx); |
||||
|
||||
/* BN_CTX_get returns a new |BIGNUM|, or NULL on allocation failure. Once
|
||||
* |BN_CTX_get| has returned NULL, all future calls will also return NULL until |
||||
* |BN_CTX_end| is called. */ |
||||
OPENSSL_EXPORT BIGNUM *BN_CTX_get(BN_CTX *ctx); |
||||
|
||||
/* BN_CTX_end invalidates all |BIGNUM|s returned from |BN_CTX_get| since the
|
||||
* matching |BN_CTX_start| call. */ |
||||
OPENSSL_EXPORT void BN_CTX_end(BN_CTX *ctx); |
||||
|
||||
|
||||
/* Simple arithmetic */ |
||||
|
||||
/* BN_add sets |r| = |a| + |b|, where |r| may be the same pointer as either |a|
|
||||
* or |b|. It returns one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
||||
|
||||
/* BN_uadd sets |r| = |a| + |b|, where |a| and |b| are non-negative and |r| may
|
||||
* be the same pointer as either |a| or |b|. It returns one on success and zero |
||||
* on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
||||
|
||||
/* BN_add_word adds |w| to |a|. It returns one on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_add_word(BIGNUM *a, BN_ULONG w); |
||||
|
||||
/* BN_sub sets |r| = |a| - |b|, where |r| must be a distinct pointer from |a|
|
||||
* and |b|. It returns one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
||||
|
||||
/* BN_usub sets |r| = |a| - |b|, where |a| and |b| are non-negative integers,
|
||||
* |b| < |a| and |r| must be a distinct pointer from |a| and |b|. It returns |
||||
* one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
||||
|
||||
/* BN_sub_word subtracts |w| from |a|. It returns one on success and zero on
|
||||
* allocation failure. */ |
||||
OPENSSL_EXPORT int BN_sub_word(BIGNUM *a, BN_ULONG w); |
||||
|
||||
/* BN_mul sets |r| = |a| * |b|, where |r| may be the same pointer as |a| or
|
||||
* |b|. Returns one on success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_mul_word sets |bn| = |bn| * |w|. It returns one on success or zero on
|
||||
* allocation failure. */ |
||||
OPENSSL_EXPORT int BN_mul_word(BIGNUM *bn, BN_ULONG w); |
||||
|
||||
/* BN_sqr sets |r| = |a|^2 (i.e. squares), where |r| may be the same pointer as
|
||||
* |a|. Returns one on success and zero otherwise. This is more efficient than |
||||
* BN_mul(r, a, a, ctx). */ |
||||
OPENSSL_EXPORT int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); |
||||
|
||||
/* BN_div divides |numerator| by |divisor| and places the result in |quotient|
|
||||
* and the remainder in |rem|. Either of |quotient| or |rem| may be NULL, in |
||||
* which case the respective value is not returned. The result is rounded |
||||
* towards zero; thus if |numerator| is negative, the remainder will be zero or |
||||
* negative. It returns one on success or zero on error. */ |
||||
OPENSSL_EXPORT int BN_div(BIGNUM *quotient, BIGNUM *rem, |
||||
const BIGNUM *numerator, const BIGNUM *divisor, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_div_word sets |numerator| = |numerator|/|divisor| and returns the
|
||||
* remainder or (BN_ULONG)-1 on error. */ |
||||
OPENSSL_EXPORT BN_ULONG BN_div_word(BIGNUM *numerator, BN_ULONG divisor); |
||||
|
||||
/* BN_sqrt sets |*out_sqrt| (which may be the same |BIGNUM| as |in|) to the
|
||||
* square root of |in|, using |ctx|. It returns one on success or zero on |
||||
* error. Negative numbers and non-square numbers will result in an error with |
||||
* appropriate errors on the error queue. */ |
||||
OPENSSL_EXPORT int BN_sqrt(BIGNUM *out_sqrt, const BIGNUM *in, BN_CTX *ctx); |
||||
|
||||
|
||||
/* Comparison functions */ |
||||
|
||||
/* BN_cmp returns a value less than, equal to or greater than zero if |a| is
|
||||
* less than, equal to or greater than |b|, respectively. */ |
||||
OPENSSL_EXPORT int BN_cmp(const BIGNUM *a, const BIGNUM *b); |
||||
|
||||
/* BN_ucmp returns a value less than, equal to or greater than zero if the
|
||||
* absolute value of |a| is less than, equal to or greater than the absolute |
||||
* value of |b|, respectively. */ |
||||
OPENSSL_EXPORT int BN_ucmp(const BIGNUM *a, const BIGNUM *b); |
||||
|
||||
/* BN_abs_is_word returns one if the absolute value of |bn| equals |w| and zero
|
||||
* otherwise. */ |
||||
OPENSSL_EXPORT int BN_abs_is_word(const BIGNUM *bn, BN_ULONG w); |
||||
|
||||
/* BN_is_zero returns one if |bn| is zero and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_is_zero(const BIGNUM *bn); |
||||
|
||||
/* BN_is_one returns one if |bn| equals one and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_is_one(const BIGNUM *bn); |
||||
|
||||
/* BN_is_word returns one if |bn| is exactly |w| and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_is_word(const BIGNUM *bn, BN_ULONG w); |
||||
|
||||
/* BN_is_odd returns one if |bn| is odd and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_is_odd(const BIGNUM *bn); |
||||
|
||||
|
||||
/* Bitwise operations. */ |
||||
|
||||
/* BN_lshift sets |r| equal to |a| << n. The |a| and |r| arguments may be the
|
||||
* same |BIGNUM|. It returns one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); |
||||
|
||||
/* BN_lshift1 sets |r| equal to |a| << 1, where |r| and |a| may be the same
|
||||
* pointer. It returns one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_lshift1(BIGNUM *r, const BIGNUM *a); |
||||
|
||||
/* BN_rshift sets |r| equal to |a| >> n, where |r| and |a| may be the same
|
||||
* pointer. It returns one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); |
||||
|
||||
/* BN_rshift1 sets |r| equal to |a| >> 1, where |r| and |a| may be the same
|
||||
* pointer. It returns one on success and zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_rshift1(BIGNUM *r, const BIGNUM *a); |
||||
|
||||
/* BN_set_bit sets the |n|th, least-significant bit in |a|. For example, if |a|
|
||||
* is 2 then setting bit zero will make it 3. It returns one on success or zero |
||||
* on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_set_bit(BIGNUM *a, int n); |
||||
|
||||
/* BN_clear_bit clears the |n|th, least-significant bit in |a|. For example, if
|
||||
* |a| is 3, clearing bit zero will make it two. It returns one on success or |
||||
* zero on allocation failure. */ |
||||
OPENSSL_EXPORT int BN_clear_bit(BIGNUM *a, int n); |
||||
|
||||
/* BN_is_bit_set returns the value of the |n|th, least-significant bit in |a|,
|
||||
* or zero if the bit doesn't exist. */ |
||||
OPENSSL_EXPORT int BN_is_bit_set(const BIGNUM *a, int n); |
||||
|
||||
/* BN_mask_bits truncates |a| so that it is only |n| bits long. It returns one
|
||||
* on success or zero if |n| is greater than the length of |a| already. */ |
||||
OPENSSL_EXPORT int BN_mask_bits(BIGNUM *a, int n); |
||||
|
||||
|
||||
/* Modulo arithmetic. */ |
||||
|
||||
/* BN_mod_word returns |a| mod |w|. */ |
||||
OPENSSL_EXPORT BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); |
||||
|
||||
/* BN_mod is a helper macro that calls |BN_div| and discards the quotient. */ |
||||
#define BN_mod(rem, numerator, divisor, ctx) \ |
||||
BN_div(NULL, (rem), (numerator), (divisor), (ctx)) |
||||
|
||||
/* BN_nnmod is a non-negative modulo function. It acts like |BN_mod|, but 0 <=
|
||||
* |rem| < |divisor| is always true. It returns one on success and zero on |
||||
* error. */ |
||||
OPENSSL_EXPORT int BN_nnmod(BIGNUM *rem, const BIGNUM *numerator, |
||||
const BIGNUM *divisor, BN_CTX *ctx); |
||||
|
||||
/* BN_mod_add sets |r| = |a| + |b| mod |m|. It returns one on success and zero
|
||||
* on error. */ |
||||
OPENSSL_EXPORT int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
const BIGNUM *m, BN_CTX *ctx); |
||||
|
||||
/* BN_mod_add_quick acts like |BN_mod_add| but requires that |a| and |b| be
|
||||
* non-negative and less than |m|. */ |
||||
OPENSSL_EXPORT int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
const BIGNUM *m); |
||||
|
||||
/* BN_mod_sub sets |r| = |a| - |b| mod |m|. It returns one on success and zero
|
||||
* on error. */ |
||||
OPENSSL_EXPORT int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
const BIGNUM *m, BN_CTX *ctx); |
||||
|
||||
/* BN_mod_sub_quick acts like |BN_mod_sub| but requires that |a| and |b| be
|
||||
* non-negative and less than |m|. */ |
||||
OPENSSL_EXPORT int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
const BIGNUM *m); |
||||
|
||||
/* BN_mod_mul sets |r| = |a|*|b| mod |m|. It returns one on success and zero
|
||||
* on error. */ |
||||
OPENSSL_EXPORT int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
const BIGNUM *m, BN_CTX *ctx); |
||||
|
||||
/* BN_mod_mul sets |r| = |a|^2 mod |m|. It returns one on success and zero
|
||||
* on error. */ |
||||
OPENSSL_EXPORT int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_mod_lshift sets |r| = (|a| << n) mod |m|, where |r| and |a| may be the
|
||||
* same pointer. It returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, |
||||
const BIGNUM *m, BN_CTX *ctx); |
||||
|
||||
/* BN_mod_lshift_quick acts like |BN_mod_lshift| but requires that |a| be
|
||||
* non-negative and less than |m|. */ |
||||
OPENSSL_EXPORT int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, |
||||
const BIGNUM *m); |
||||
|
||||
/* BN_mod_lshift1 sets |r| = (|a| << 1) mod |m|, where |r| and |a| may be the
|
||||
* same pointer. It returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_mod_lshift1_quick acts like |BN_mod_lshift1| but requires that |a| be
|
||||
* non-negative and less than |m|. */ |
||||
OPENSSL_EXPORT int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, |
||||
const BIGNUM *m); |
||||
|
||||
/* BN_mod_sqrt returns a |BIGNUM|, r, such that r^2 == a (mod p). */ |
||||
OPENSSL_EXPORT BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, |
||||
BN_CTX *ctx); |
||||
|
||||
|
||||
/* Random and prime number generation. */ |
||||
|
||||
/* BN_rand sets |rnd| to a random number of length |bits|. If |top| is zero, the
|
||||
* most-significant bit, if any, will be set. If |top| is one, the two most |
||||
* significant bits, if any, will be set. |
||||
* |
||||
* If |top| is -1 then no extra action will be taken and |BN_num_bits(rnd)| may |
||||
* not equal |bits| if the most significant bits randomly ended up as zeros. |
||||
* |
||||
* If |bottom| is non-zero, the least-significant bit, if any, will be set. The |
||||
* function returns one on success or zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); |
||||
|
||||
/* BN_pseudo_rand is an alias for |BN_rand|. */ |
||||
OPENSSL_EXPORT int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); |
||||
|
||||
/* BN_rand_range sets |rnd| to a random value [0..range). It returns one on
|
||||
* success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_rand_range(BIGNUM *rnd, const BIGNUM *range); |
||||
|
||||
/* BN_pseudo_rand_range is an alias for BN_rand_range. */ |
||||
OPENSSL_EXPORT int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range); |
||||
|
||||
/* BN_generate_dsa_nonce generates a random number 0 <= out < range. Unlike
|
||||
* BN_rand_range, it also includes the contents of |priv| and |message| in the |
||||
* generation so that an RNG failure isn't fatal as long as |priv| remains |
||||
* secret. This is intended for use in DSA and ECDSA where an RNG weakness |
||||
* leads directly to private key exposure unless this function is used. |
||||
* It returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range, |
||||
const BIGNUM *priv, |
||||
const uint8_t *message, |
||||
size_t message_len, BN_CTX *ctx); |
||||
|
||||
/* BN_GENCB holds a callback function that is used by generation functions that
|
||||
* can take a very long time to complete. Use |BN_GENCB_set| to initialise a |
||||
* |BN_GENCB| structure. |
||||
* |
||||
* The callback receives the address of that |BN_GENCB| structure as its last |
||||
* argument and the user is free to put an arbitary pointer in |arg|. The other |
||||
* arguments are set as follows: |
||||
* event=BN_GENCB_GENERATED, n=i: after generating the i'th possible prime |
||||
* number. |
||||
* event=BN_GENCB_PRIME_TEST, n=-1: when finished trial division primality |
||||
* checks. |
||||
* event=BN_GENCB_PRIME_TEST, n=i: when the i'th primality test has finished. |
||||
* |
||||
* The callback can return zero to abort the generation progress or one to |
||||
* allow it to continue. |
||||
* |
||||
* When other code needs to call a BN generation function it will often take a |
||||
* BN_GENCB argument and may call the function with other argument values. */ |
||||
#define BN_GENCB_GENERATED 0 |
||||
#define BN_GENCB_PRIME_TEST 1 |
||||
|
||||
struct bn_gencb_st { |
||||
void *arg; /* callback-specific data */ |
||||
int (*callback)(int event, int n, struct bn_gencb_st *); |
||||
}; |
||||
|
||||
/* BN_GENCB_set configures |callback| to call |f| and sets |callout->arg| to
|
||||
* |arg|. */ |
||||
OPENSSL_EXPORT void BN_GENCB_set(BN_GENCB *callback, |
||||
int (*f)(int event, int n, |
||||
struct bn_gencb_st *), |
||||
void *arg); |
||||
|
||||
/* BN_GENCB_call calls |callback|, if not NULL, and returns the return value of
|
||||
* the callback, or 1 if |callback| is NULL. */ |
||||
OPENSSL_EXPORT int BN_GENCB_call(BN_GENCB *callback, int event, int n); |
||||
|
||||
/* BN_generate_prime_ex sets |ret| to a prime number of |bits| length. If safe
|
||||
* is non-zero then the prime will be such that (ret-1)/2 is also a prime. |
||||
* (This is needed for Diffie-Hellman groups to ensure that the only subgroups |
||||
* are of size 2 and (p-1)/2.). |
||||
* |
||||
* If |add| is not NULL, the prime will fulfill the condition |ret| % |add| == |
||||
* |rem| in order to suit a given generator. (If |rem| is NULL then |ret| % |
||||
* |add| == 1.) |
||||
* |
||||
* If |cb| is not NULL, it will be called during processing to give an |
||||
* indication of progress. See the comments for |BN_GENCB|. It returns one on |
||||
* success and zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, |
||||
const BIGNUM *add, const BIGNUM *rem, |
||||
BN_GENCB *cb); |
||||
|
||||
/* BN_prime_checks is magic value that can be used as the |checks| argument to
|
||||
* the primality testing functions in order to automatically select a number of |
||||
* Miller-Rabin checks that gives a false positive rate of ~2^{-80}. */ |
||||
#define BN_prime_checks 0 |
||||
|
||||
/* BN_primality_test sets |*is_probably_prime| to one if |candidate| is
|
||||
* probably a prime number by the Miller-Rabin test or zero if it's certainly |
||||
* not. |
||||
* |
||||
* If |do_trial_division| is non-zero then |candidate| will be tested against a |
||||
* list of small primes before Miller-Rabin tests. The probability of this |
||||
* function returning a false positive is 2^{2*checks}. If |checks| is |
||||
* |BN_prime_checks| then a value that results in approximately 2^{-80} false |
||||
* positive probability is used. If |cb| is not NULL then it is called during |
||||
* the checking process. See the comment above |BN_GENCB|. |
||||
* |
||||
* The function returns one on success and zero on error. |
||||
* |
||||
* (If you are unsure whether you want |do_trial_division|, don't set it.) */ |
||||
OPENSSL_EXPORT int BN_primality_test(int *is_probably_prime, |
||||
const BIGNUM *candidate, int checks, |
||||
BN_CTX *ctx, int do_trial_division, |
||||
BN_GENCB *cb); |
||||
|
||||
/* BN_is_prime_fasttest_ex returns one if |candidate| is probably a prime
|
||||
* number by the Miller-Rabin test, zero if it's certainly not and -1 on error. |
||||
* |
||||
* If |do_trial_division| is non-zero then |candidate| will be tested against a |
||||
* list of small primes before Miller-Rabin tests. The probability of this |
||||
* function returning one when |candidate| is composite is 2^{2*checks}. If |
||||
* |checks| is |BN_prime_checks| then a value that results in approximately |
||||
* 2^{-80} false positive probability is used. If |cb| is not NULL then it is |
||||
* called during the checking process. See the comment above |BN_GENCB|. |
||||
* |
||||
* WARNING: deprecated. Use |BN_primality_test|. */ |
||||
OPENSSL_EXPORT int BN_is_prime_fasttest_ex(const BIGNUM *candidate, int checks, |
||||
BN_CTX *ctx, int do_trial_division, |
||||
BN_GENCB *cb); |
||||
|
||||
/* BN_is_prime_ex acts the same as |BN_is_prime_fasttest_ex| with
|
||||
* |do_trial_division| set to zero. |
||||
* |
||||
* WARNING: deprecated: Use |BN_primality_test|. */ |
||||
OPENSSL_EXPORT int BN_is_prime_ex(const BIGNUM *candidate, int checks, |
||||
BN_CTX *ctx, BN_GENCB *cb); |
||||
|
||||
|
||||
/* Number theory functions */ |
||||
|
||||
/* BN_gcd sets |r| = gcd(|a|, |b|). It returns one on success and zero
|
||||
* otherwise. */ |
||||
OPENSSL_EXPORT int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_mod_inverse sets |out| equal to |a|^-1, mod |n|. If either of |a| or |n|
|
||||
* have |BN_FLG_CONSTTIME| set then the operation is performed in constant |
||||
* time. If |out| is NULL, a fresh BIGNUM is allocated. It returns the result |
||||
* or NULL on error. */ |
||||
OPENSSL_EXPORT BIGNUM *BN_mod_inverse(BIGNUM *out, const BIGNUM *a, |
||||
const BIGNUM *n, BN_CTX *ctx); |
||||
|
||||
/* BN_kronecker returns the Kronecker symbol of |a| and |b| (which is -1, 0 or
|
||||
* 1), or -2 on error. */ |
||||
OPENSSL_EXPORT int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); |
||||
|
||||
|
||||
/* Montgomery arithmetic. */ |
||||
|
||||
/* BN_MONT_CTX contains the precomputed values needed to work in a specific
|
||||
* Montgomery domain. */ |
||||
|
||||
/* BN_MONT_CTX_new returns a fresh BN_MONT_CTX or NULL on allocation failure. */ |
||||
OPENSSL_EXPORT BN_MONT_CTX *BN_MONT_CTX_new(void); |
||||
|
||||
/* BN_MONT_CTX_init initialises a stack allocated |BN_MONT_CTX|. */ |
||||
OPENSSL_EXPORT void BN_MONT_CTX_init(BN_MONT_CTX *mont); |
||||
|
||||
/* BN_MONT_CTX_free frees the contexts of |mont| and, if it was originally
|
||||
* allocated with |BN_MONT_CTX_new|, |mont| itself. */ |
||||
OPENSSL_EXPORT void BN_MONT_CTX_free(BN_MONT_CTX *mont); |
||||
|
||||
/* BN_MONT_CTX_copy sets |to| equal to |from|. It returns |to| on success or
|
||||
* NULL on error. */ |
||||
OPENSSL_EXPORT BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, |
||||
BN_MONT_CTX *from); |
||||
|
||||
/* BN_MONT_CTX_set sets up a Montgomery context given the modulus, |mod|. It
|
||||
* returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_MONT_CTX_set_locked takes |lock| and checks whether |*pmont| is NULL. If
|
||||
* so, it creates a new |BN_MONT_CTX| and sets the modulus for it to |mod|. It |
||||
* then stores it as |*pmont| and returns it, or NULL on error. |
||||
* |
||||
* If |*pmont| is already non-NULL then the existing value is returned. */ |
||||
BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_MUTEX *lock, |
||||
const BIGNUM *mod, BN_CTX *bn_ctx); |
||||
|
||||
/* BN_to_montgomery sets |ret| equal to |a| in the Montgomery domain. It
|
||||
* returns one on success and zero on error. */ |
||||
OPENSSL_EXPORT int BN_to_montgomery(BIGNUM *ret, const BIGNUM *a, |
||||
const BN_MONT_CTX *mont, BN_CTX *ctx); |
||||
|
||||
/* BN_from_montgomery sets |ret| equal to |a| * R^-1, i.e. translates values
|
||||
* out of the Montgomery domain. It returns one on success or zero on error. */ |
||||
OPENSSL_EXPORT int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, |
||||
const BN_MONT_CTX *mont, BN_CTX *ctx); |
||||
|
||||
/* BN_mod_mul_montgomery set |r| equal to |a| * |b|, in the Montgomery domain.
|
||||
* Both |a| and |b| must already be in the Montgomery domain (by |
||||
* |BN_to_montgomery|). It returns one on success or zero on error. */ |
||||
OPENSSL_EXPORT int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, |
||||
const BIGNUM *b, |
||||
const BN_MONT_CTX *mont, BN_CTX *ctx); |
||||
|
||||
|
||||
/* Exponentiation. */ |
||||
|
||||
/* BN_exp sets |r| equal to |a|^{|p|}. It does so with a square-and-multiply
|
||||
* algorithm that leaks side-channel information. It returns one on success or |
||||
* zero otherwise. */ |
||||
OPENSSL_EXPORT int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
||||
BN_CTX *ctx); |
||||
|
||||
/* BN_mod_exp sets |r| equal to |a|^{|p|} mod |m|. It does so with the best
|
||||
* algorithm for the values provided and can run in constant time if |
||||
* |BN_FLG_CONSTTIME| is set for |p|. It returns one on success or zero |
||||
* otherwise. */ |
||||
OPENSSL_EXPORT int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
||||
const BIGNUM *m, BN_CTX *ctx); |
||||
|
||||
OPENSSL_EXPORT int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
||||
const BIGNUM *m, BN_CTX *ctx, |
||||
BN_MONT_CTX *m_ctx); |
||||
|
||||
OPENSSL_EXPORT int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, |
||||
const BIGNUM *p, const BIGNUM *m, |
||||
BN_CTX *ctx, BN_MONT_CTX *in_mont); |
||||
|
||||
OPENSSL_EXPORT int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p, |
||||
const BIGNUM *m, BN_CTX *ctx, |
||||
BN_MONT_CTX *m_ctx); |
||||
OPENSSL_EXPORT int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, |
||||
const BIGNUM *p1, const BIGNUM *a2, |
||||
const BIGNUM *p2, const BIGNUM *m, |
||||
BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
||||
|
||||
|
||||
/* Private functions */ |
||||
|
||||
struct bignum_st { |
||||
BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks in little-endian
|
||||
order. */ |
||||
int top; /* Index of last used element in |d|, plus one. */ |
||||
int dmax; /* Size of |d|, in words. */ |
||||
int neg; /* one if the number is negative */ |
||||
int flags; /* bitmask of BN_FLG_* values */ |
||||
}; |
||||
|
||||
struct bn_mont_ctx_st { |
||||
BIGNUM RR; /* used to convert to montgomery form */ |
||||
BIGNUM N; /* The modulus */ |
||||
BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
|
||||
* (Ni is only stored for bignum algorithm) */ |
||||
BN_ULONG n0[2]; /* least significant word(s) of Ni;
|
||||
(type changed with 0.9.9, was "BN_ULONG n0;" before) */ |
||||
int flags; |
||||
int ri; /* number of bits in R */ |
||||
}; |
||||
|
||||
OPENSSL_EXPORT unsigned BN_num_bits_word(BN_ULONG l); |
||||
|
||||
#define BN_FLG_MALLOCED 0x01 |
||||
#define BN_FLG_STATIC_DATA 0x02 |
||||
/* avoid leaking exponent information through timing, BN_mod_exp_mont() will
|
||||
* call BN_mod_exp_mont_consttime, BN_div() will call BN_div_no_branch, |
||||
* BN_mod_inverse() will call BN_mod_inverse_no_branch. */ |
||||
#define BN_FLG_CONSTTIME 0x04 |
||||
|
||||
|
||||
/* Android compatibility section.
|
||||
* |
||||
* These functions are declared, temporarily, for Android because |
||||
* wpa_supplicant will take a little time to sync with upstream. Outside of |
||||
* Android they'll have no definition. */ |
||||
|
||||
OPENSSL_EXPORT BIGNUM *get_rfc3526_prime_1536(BIGNUM *bn); |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#define BN_F_BN_CTX_get 100 |
||||
#define BN_F_BN_CTX_new 101 |
||||
#define BN_F_BN_CTX_start 102 |
||||
#define BN_F_BN_bn2dec 103 |
||||
#define BN_F_BN_bn2hex 104 |
||||
#define BN_F_BN_div 105 |
||||
#define BN_F_BN_div_recp 106 |
||||
#define BN_F_BN_exp 107 |
||||
#define BN_F_BN_generate_dsa_nonce 108 |
||||
#define BN_F_BN_generate_prime_ex 109 |
||||
#define BN_F_BN_mod_exp2_mont 110 |
||||
#define BN_F_BN_mod_exp_mont 111 |
||||
#define BN_F_BN_mod_exp_mont_consttime 112 |
||||
#define BN_F_BN_mod_exp_mont_word 113 |
||||
#define BN_F_BN_mod_inverse 114 |
||||
#define BN_F_BN_mod_inverse_no_branch 115 |
||||
#define BN_F_BN_mod_lshift_quick 116 |
||||
#define BN_F_BN_mod_sqrt 117 |
||||
#define BN_F_BN_new 118 |
||||
#define BN_F_BN_rand 119 |
||||
#define BN_F_BN_rand_range 120 |
||||
#define BN_F_BN_sqrt 121 |
||||
#define BN_F_BN_usub 122 |
||||
#define BN_F_bn_wexpand 123 |
||||
#define BN_F_mod_exp_recp 124 |
||||
#define BN_F_BN_lshift 125 |
||||
#define BN_F_BN_rshift 126 |
||||
#define BN_R_ARG2_LT_ARG3 100 |
||||
#define BN_R_BAD_RECIPROCAL 101 |
||||
#define BN_R_BIGNUM_TOO_LONG 102 |
||||
#define BN_R_BITS_TOO_SMALL 103 |
||||
#define BN_R_CALLED_WITH_EVEN_MODULUS 104 |
||||
#define BN_R_DIV_BY_ZERO 105 |
||||
#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 106 |
||||
#define BN_R_INPUT_NOT_REDUCED 107 |
||||
#define BN_R_INVALID_RANGE 108 |
||||
#define BN_R_NEGATIVE_NUMBER 109 |
||||
#define BN_R_NOT_A_SQUARE 110 |
||||
#define BN_R_NOT_INITIALIZED 111 |
||||
#define BN_R_NO_INVERSE 112 |
||||
#define BN_R_PRIVATE_KEY_TOO_LARGE 113 |
||||
#define BN_R_P_IS_NOT_PRIME 114 |
||||
#define BN_R_TOO_MANY_ITERATIONS 115 |
||||
#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 116 |
||||
|
||||
#endif /* OPENSSL_HEADER_BN_H */ |
@ -1,123 +0,0 @@ |
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved. |
||||
* |
||||
* This package is an SSL implementation written |
||||
* by Eric Young (eay@cryptsoft.com). |
||||
* The implementation was written so as to conform with Netscapes SSL. |
||||
* |
||||
* This library is free for commercial and non-commercial use as long as |
||||
* the following conditions are aheared to. The following conditions |
||||
* apply to all code found in this distribution, be it the RC4, RSA, |
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation |
||||
* included with this distribution is covered by the same copyright terms |
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com). |
||||
* |
||||
* Copyright remains Eric Young's, and as such any Copyright notices in |
||||
* the code are not to be removed. |
||||
* If this package is used in a product, Eric Young should be given attribution |
||||
* as the author of the parts of the library used. |
||||
* This can be in the form of a textual message at program startup or |
||||
* in documentation (online or textual) provided with the package. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* "This product includes cryptographic software written by |
||||
* Eric Young (eay@cryptsoft.com)" |
||||
* The word 'cryptographic' can be left out if the rouines from the library |
||||
* being used are not cryptographic related :-). |
||||
* 4. If you include any Windows specific code (or a derivative thereof) from |
||||
* the apps directory (application code) you must include an acknowledgement: |
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* The licence and distribution terms for any publically available version or |
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be |
||||
* copied and put under another distribution licence |
||||
* [including the GNU Public Licence.] */ |
||||
|
||||
#ifndef OPENSSL_HEADER_BUFFER_H |
||||
#define OPENSSL_HEADER_BUFFER_H |
||||
|
||||
#include <openssl/base.h> |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* Memory and string functions, see also mem.h. */ |
||||
|
||||
|
||||
/* BUF_MEM is a generic buffer object used by OpenSSL. */ |
||||
struct buf_mem_st { |
||||
size_t length; /* current number of bytes */ |
||||
char *data; |
||||
size_t max; /* size of buffer */ |
||||
}; |
||||
|
||||
/* BUF_MEM_new creates a new BUF_MEM which has no allocated data buffer. */ |
||||
OPENSSL_EXPORT BUF_MEM *BUF_MEM_new(void); |
||||
|
||||
/* BUF_MEM_free frees |buf->data| if needed and then frees |buf| itself. */ |
||||
OPENSSL_EXPORT void BUF_MEM_free(BUF_MEM *buf); |
||||
|
||||
/* BUF_MEM_grow ensures that |buf| has length |len| and allocates memory if
|
||||
* needed. If the length of |buf| increased, the new bytes are filled with |
||||
* zeros. It returns the length of |buf|, or zero if there's an error. */ |
||||
OPENSSL_EXPORT size_t BUF_MEM_grow(BUF_MEM *buf, size_t len); |
||||
|
||||
/* BUF_MEM_grow_clean acts the same as |BUF_MEM_grow|, but clears the previous
|
||||
* contents of memory if reallocing. */ |
||||
OPENSSL_EXPORT size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len); |
||||
|
||||
/* BUF_strdup returns an allocated, duplicate of |str|. */ |
||||
OPENSSL_EXPORT char *BUF_strdup(const char *str); |
||||
|
||||
/* BUF_strnlen returns the number of characters in |str|, excluding the NUL
|
||||
* byte, but at most |max_len|. This function never reads more than |max_len| |
||||
* bytes from |str|. */ |
||||
OPENSSL_EXPORT size_t BUF_strnlen(const char *str, size_t max_len); |
||||
|
||||
/* BUF_strndup returns an allocated, duplicate of |str|, which is, at most,
|
||||
* |size| bytes. The result is always NUL terminated. */ |
||||
OPENSSL_EXPORT char *BUF_strndup(const char *str, size_t size); |
||||
|
||||
/* BUF_memdup returns an allocated, duplicate of |size| bytes from |data|. */ |
||||
OPENSSL_EXPORT void *BUF_memdup(const void *data, size_t size); |
||||
|
||||
/* BUF_strlcpy acts like strlcpy(3). */ |
||||
OPENSSL_EXPORT size_t BUF_strlcpy(char *dst, const char *src, size_t dst_size); |
||||
|
||||
/* BUF_strlcat acts like strlcat(3). */ |
||||
OPENSSL_EXPORT size_t BUF_strlcat(char *dst, const char *src, size_t size); |
||||
|
||||
|
||||
#if defined(__cplusplus) |
||||
} /* extern C */ |
||||
#endif |
||||
|
||||
#define BUF_F_BUF_MEM_new 100 |
||||
#define BUF_F_BUF_memdup 101 |
||||
#define BUF_F_BUF_strndup 102 |
||||
#define BUF_F_buf_mem_grow 103 |
||||
|
||||
#endif /* OPENSSL_HEADER_BUFFER_H */ |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue