hexsha
stringlengths
40
40
size
int64
5
1.05M
ext
stringclasses
588 values
lang
stringclasses
305 values
max_stars_repo_path
stringlengths
3
363
max_stars_repo_name
stringlengths
5
118
max_stars_repo_head_hexsha
stringlengths
40
40
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringdate
2015-01-01 00:00:35
2022-03-31 23:43:49
max_stars_repo_stars_event_max_datetime
stringdate
2015-01-01 12:37:38
2022-03-31 23:59:52
max_issues_repo_path
stringlengths
3
363
max_issues_repo_name
stringlengths
5
118
max_issues_repo_head_hexsha
stringlengths
40
40
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
134k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
363
max_forks_repo_name
stringlengths
5
135
max_forks_repo_head_hexsha
stringlengths
40
40
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringdate
2015-01-01 00:01:02
2022-03-31 23:27:27
max_forks_repo_forks_event_max_datetime
stringdate
2015-01-03 08:55:07
2022-03-31 23:59:24
content
stringlengths
5
1.05M
avg_line_length
float64
1.13
1.04M
max_line_length
int64
1
1.05M
alphanum_fraction
float64
0
1
229bc73911c8f55bdc6b56620073e512488ff10e
1,939
h
C
py/gc_long_lived.h
MakeItZone/circuitpython
7f803c0b51c333210ed267502422ed7bb28b9be7
[ "Unlicense", "BSD-3-Clause", "MIT-0", "MIT" ]
3,010
2017-01-07T23:43:33.000Z
2022-03-31T06:02:59.000Z
py/gc_long_lived.h
MakeItZone/circuitpython
7f803c0b51c333210ed267502422ed7bb28b9be7
[ "Unlicense", "BSD-3-Clause", "MIT-0", "MIT" ]
4,478
2017-01-06T01:35:02.000Z
2022-03-31T23:03:27.000Z
py/gc_long_lived.h
MakeItZone/circuitpython
7f803c0b51c333210ed267502422ed7bb28b9be7
[ "Unlicense", "BSD-3-Clause", "MIT-0", "MIT" ]
1,149
2017-01-09T00:35:23.000Z
2022-03-31T21:24:29.000Z
/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC * * 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. */ // These helpers move MicroPython objects and their sub-objects to the long lived portion of the // heap. #ifndef MICROPY_INCLUDED_PY_GC_LONG_LIVED_H #define MICROPY_INCLUDED_PY_GC_LONG_LIVED_H #include "py/objfun.h" #include "py/objproperty.h" #include "py/objstr.h" mp_obj_fun_bc_t *make_fun_bc_long_lived(mp_obj_fun_bc_t *fun_bc, uint8_t max_depth); mp_obj_property_t *make_property_long_lived(mp_obj_property_t *prop, uint8_t max_depth); mp_obj_dict_t *make_dict_long_lived(mp_obj_dict_t *dict, uint8_t max_depth); mp_obj_str_t *make_str_long_lived(mp_obj_str_t *str); mp_obj_t make_obj_long_lived(mp_obj_t obj, uint8_t max_depth); #endif // MICROPY_INCLUDED_PY_GC_LONG_LIVED_H
44.068182
96
0.785972
61c42ed55419c8b16784ed6cca10fdec0fc390e6
1,337
c
C
lib/src/tests/testing-plugins/testing_clock.c
luzidl/Machinebeat
358e52b555a15972f47dc3543660ab7c633a12b6
[ "Apache-2.0" ]
null
null
null
lib/src/tests/testing-plugins/testing_clock.c
luzidl/Machinebeat
358e52b555a15972f47dc3543660ab7c633a12b6
[ "Apache-2.0" ]
null
null
null
lib/src/tests/testing-plugins/testing_clock.c
luzidl/Machinebeat
358e52b555a15972f47dc3543660ab7c633a12b6
[ "Apache-2.0" ]
null
null
null
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Enable POSIX features */ #if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL) # define _XOPEN_SOURCE 600 #endif #ifndef _DEFAULT_SOURCE # define _DEFAULT_SOURCE #endif /* On older systems we need to define _BSD_SOURCE. * _DEFAULT_SOURCE is an alias for that. */ #ifndef _BSD_SOURCE # define _BSD_SOURCE #endif #include <time.h> #ifdef _WIN32 # include <windows.h> #endif #include "testing_clock.h" UA_DateTime testingClock = 0; UA_DateTime UA_DateTime_now(void) { return testingClock; } UA_DateTime UA_DateTime_nowMonotonic(void) { return testingClock; } UA_DateTime UA_DateTime_localTimeUtcOffset(void) { return 0; } void UA_fakeSleep(UA_UInt32 duration) { testingClock += duration * UA_DATETIME_MSEC; } /* 1 millisecond = 1,000,000 Nanoseconds */ #define NANO_SECOND_MULTIPLIER 1000000 void UA_realSleep(UA_UInt32 duration) { #ifdef _WIN32 Sleep(duration); #else UA_UInt32 sec = duration / 1000; UA_UInt32 ns = (duration % 1000) * NANO_SECOND_MULTIPLIER; struct timespec sleepValue; sleepValue.tv_sec = sec; sleepValue.tv_nsec = ns; nanosleep(&sleepValue, NULL); #endif }
22.283333
70
0.737472
b2b346f0882c63480e33990e63ad29a3c8372a35
867
h
C
engine/core/editor/qt/QComboBox.h
johndpope/echo
e9ce2f4037e8a5d49b74cc7a9d9ee09f296e7fa7
[ "MIT" ]
null
null
null
engine/core/editor/qt/QComboBox.h
johndpope/echo
e9ce2f4037e8a5d49b74cc7a9d9ee09f296e7fa7
[ "MIT" ]
null
null
null
engine/core/editor/qt/QComboBox.h
johndpope/echo
e9ce2f4037e8a5d49b74cc7a9d9ee09f296e7fa7
[ "MIT" ]
null
null
null
#pragma once #include "engine/core/base/echo_def.h" #ifdef ECHO_EDITOR_MODE class QWidget; namespace Echo { // QComboBox->addItem(const QIcon &icon, const QString &text) void qComboBoxAddItem(QWidget* widget, const char* icon, const char* text); // int QComboBox->currentIndex() const; int qComboBoxCurrentIndex(QWidget* widget); // QString QComboBox->currentText() const; String qComboBoxCurrentText(QWidget* widget); // QComboBox->setCurrentIndex(int index); void qComboBoxSetCurrentIndex(QWidget* widget, int index); // QComboBox->setCurrentText(const QString &text); void qComboBoxSetCurrentText(QWidget* widget, const char* text); // void QComboBox->setItemText(int index, const QString &text); void qComboBoxSetItemText(QWidget* widget, int index, const char* text); // QComboBox->clear(); void qComboBoxClear(QWidget* widget); } #endif
26.272727
76
0.757785
e5c91ecdfa0ce00248dfc2bef54bf66c09ee9020
74,206
h
C
src/TroykaOLED/utility/defaultFonts.h
funvit/toilet-fan-control.atmega328pb
197743fabfb3a7fbbf4f9119099fa387a26fd995
[ "Unlicense" ]
null
null
null
src/TroykaOLED/utility/defaultFonts.h
funvit/toilet-fan-control.atmega328pb
197743fabfb3a7fbbf4f9119099fa387a26fd995
[ "Unlicense" ]
null
null
null
src/TroykaOLED/utility/defaultFonts.h
funvit/toilet-fan-control.atmega328pb
197743fabfb3a7fbbf4f9119099fa387a26fd995
[ "Unlicense" ]
null
null
null
// ширина символов, высота символов, код первого символа и количество символов const uint8_t font6x8[] PROGMEM = { 0x06, 0x08, 0x20, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // пробел 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, // ! 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, // " 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, // # 0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, // $ 0x00, 0x23, 0x13, 0x08, 0x64, 0x62, // % 0x00, 0x36, 0x49, 0x55, 0x22, 0x50, // & 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, // ' 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, // ( 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, // ) 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, // * 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, // + 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00, // , 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, // - 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, // . 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, // / 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, // 0 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, // 1 0x00, 0x42, 0x61, 0x51, 0x49, 0x46, // 2 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31, // 3 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, // 4 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, // 5 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, // 6 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, // 7 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, // 8 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, // 9 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, // : 0x00, 0x00, 0x56, 0x36, 0x00, 0x00, // ; 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, // < 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, // = 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, // > 0x00, 0x02, 0x01, 0x51, 0x09, 0x06, // ? 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E, // @ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, // A 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, // B 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, // C 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, // D 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, // E 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, // F 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, // G 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, // H 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, // I 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, // J 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, // K 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, // L 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, // M 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, // N 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, // O 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, // P 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, // Q 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, // R 0x00, 0x46, 0x49, 0x49, 0x49, 0x31, // S 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, // T 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, // U 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, // V 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, // W 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, // X 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, // Y 0x00, 0x61, 0x51, 0x49, 0x45, 0x43, // Z 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, // [ 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, // обратный слеш 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, // ] 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, // ^ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, // _ 0x00, 0x00, 0x03, 0x05, 0x00, 0x00, // ` 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, // a 0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, // b 0x00, 0x38, 0x44, 0x44, 0x44, 0x20, // c 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, // d 0x00, 0x38, 0x54, 0x54, 0x54, 0x18, // e 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02, // f 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // g 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, // h 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, // i 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, // j 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, // k 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, // l 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, // m 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, // n 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, // o 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18, // p 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, // q 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, // r 0x00, 0x48, 0x54, 0x54, 0x54, 0x20, // s 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20, // t 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, // u 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, // v 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, // w 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, // x 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C, // y 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, // z 0x00, 0x00, 0x10, 0x7C, 0x82, 0x00, // { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, // | 0x00, 0x00, 0x82, 0x7C, 0x10, 0x00, // } 0x00, 0x00, 0x06, 0x09, 0x09, 0x06, // ~ 0 }; // ширина символов, высота символов, код первого символа и количество символов const uint8_t fontRus6x8[] PROGMEM = { 0x06, 0x08, 0x20, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // пробел 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, // ! 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, // " 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, // # 0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, // $ 0x00, 0x23, 0x13, 0x08, 0x64, 0x62, // % 0x00, 0x36, 0x49, 0x55, 0x22, 0x50, // & 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, // ' 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, // ( 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, // ) 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, // * 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, // + 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00, // , 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, // - 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, // . 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, // / 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, // 0 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, // 1 0x00, 0x42, 0x61, 0x51, 0x49, 0x46, // 2 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31, // 3 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, // 4 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, // 5 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, // 6 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, // 7 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, // 8 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, // 9 0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00, // : 0x00, 0x00, 0xac, 0x5c, 0x00, 0x00, // ; 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, // < 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, // = 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, // > 0x00, 0x02, 0x01, 0x51, 0x09, 0x06, // ? 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E, // @ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, // A 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, // B 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, // C 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, // D 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, // E 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, // F 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, // G 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, // H 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, // I 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, // J 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, // K 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, // L 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, // M 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, // N 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, // O 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, // P 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, // Q 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, // R 0x00, 0x46, 0x49, 0x49, 0x49, 0x31, // S 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, // T 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, // U 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, // V 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, // W 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, // X 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, // Y 0x00, 0x61, 0x51, 0x49, 0x45, 0x43, // Z 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, // [ 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, // обратный слеш 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, // ] 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, // ^ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, // _ 0x00, 0x00, 0x03, 0x05, 0x00, 0x00, // ` 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, // a 0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, // b 0x00, 0x38, 0x44, 0x44, 0x44, 0x20, // c 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, // d 0x00, 0x38, 0x54, 0x54, 0x54, 0x18, // e 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02, // f 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // g 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, // h 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, // i 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, // j 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, // k 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, // l 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, // m 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, // n 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, // o 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18, // p 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, // q 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, // r 0x00, 0x48, 0x54, 0x54, 0x54, 0x20, // s 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20, // t 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, // u 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, // v 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, // w 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, // x 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C, // y 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, // z 0x00, 0x00, 0x10, 0x7C, 0x82, 0x00, // { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, // | 0x00, 0x00, 0x82, 0x7C, 0x10, 0x00, // } 0x00, 0x10, 0x08, 0x10, 0x20, 0x10, // ~ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ⌂ 0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e, // А 0x00, 0x7F, 0x49, 0x49, 0x49, 0x31, // Б 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, // В 0x00, 0x7f, 0x01, 0x01, 0x01, 0x01, // Г 0x00, 0xc0, 0x7e, 0x41, 0x7f, 0xc0, // Д 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, // Е 0x00, 0x73, 0x0C, 0x7F, 0x0C, 0x73, // Ж 0x00, 0x41, 0x49, 0x49, 0x49, 0x36, // З 0x00, 0x7F, 0x10, 0x08, 0x04, 0x7F, // И 0x00, 0x7E, 0x20, 0x11, 0x08, 0x7E, // Й 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, // К 0x00, 0x40, 0x3F, 0x01, 0x01, 0x7F, // Л 0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f, // М 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, // Н 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, // О 0x00, 0x7F, 0x01, 0x01, 0x01, 0x7F, // П 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, // Р 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, // С 0x00, 0x01, 0x01, 0x7f, 0x01, 0x01, // Т 0x00, 0x07, 0x48, 0x48, 0x48, 0x3f, // У 0x00, 0x1C, 0x22, 0x7F, 0x22, 0x1C, // Ф 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, // Х 0x00, 0x7f, 0x40, 0x40, 0x7f, 0xc0, // Ц 0x00, 0x07, 0x08, 0x08, 0x08, 0x7F, // Ч 0x00, 0x7F, 0x40, 0x7F, 0x40, 0x7F, // Ш 0x00, 0x7f, 0x40, 0x7f, 0x40, 0xff, // Щ 0x00, 0x01, 0x7F, 0x48, 0x48, 0x30, // Ъ 0x00, 0x7f, 0x48, 0x48, 0x30, 0x7f, // Ы 0x00, 0x7f, 0x48, 0x48, 0x48, 0x30, // Ь 0x00, 0x22, 0x41, 0x49, 0x49, 0x3e, // Э 0x00, 0x7F, 0x10, 0x3E, 0x41, 0x3E, // Ю 0x00, 0x46, 0x29, 0x19, 0x09, 0x7f, // Я 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, // а 0x00, 0x3c, 0x4a, 0x4a, 0x49, 0x31, // б 0x00, 0x7c, 0x54, 0x54, 0x54, 0x28, // в 0x00, 0x7c, 0x04, 0x04, 0x04, 0x04, // г 0x00, 0xc0, 0x78, 0x44, 0x7c, 0xc0, // д 0x00, 0x38, 0x54, 0x54, 0x54, 0x18, // е 0x00, 0x6c, 0x10, 0x7c, 0x10, 0x6c, // ж 0x00, 0x44, 0x54, 0x54, 0x54, 0x28, // з 0x00, 0x7c, 0x20, 0x10, 0x08, 0x7c, // и 0x00, 0x7c, 0x40, 0x26, 0x10, 0x7c, // й 0x00, 0x7c, 0x10, 0x10, 0x28, 0x44, // к 0x00, 0x40, 0x3C, 0x04, 0x04, 0x7C, // л 0x00, 0x7C, 0x08, 0x10, 0x08, 0x7C, // м 0x00, 0x7C, 0x10, 0x10, 0x7C, 0x00, // н 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, // о 0x00, 0x7c, 0x04, 0x04, 0x04, 0x7c, // п 0x00, 0x7c, 0x24, 0x24, 0x24, 0x18, // р 0x00, 0x38, 0x44, 0x44, 0x44, 0x48, // с 0x00, 0x04, 0x04, 0x7C, 0x04, 0x04, // т 0x00, 0x4C, 0x50, 0x50, 0x50, 0x3C, // у 0x00, 0x38, 0x44, 0xFE, 0x44, 0x38, // ф 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, // х 0x00, 0x7C, 0x40, 0x40, 0x7C, 0xC0, // ц 0x00, 0x0c, 0x10, 0x10, 0x10, 0x7c, // ч 0x00, 0x7C, 0x40, 0x7C, 0x40, 0x7C, // ш 0x00, 0x7C, 0x40, 0x7C, 0x40, 0xFC, // щ 0x00, 0x04, 0x7c, 0x50, 0x50, 0x20, // ъ 0x00, 0x7c, 0x50, 0x50, 0x20, 0x7c, // ы 0x00, 0x7c, 0x50, 0x50, 0x50, 0x20, // ь 0x00, 0x28, 0x44, 0x54, 0x54, 0x38, // э 0x00, 0x7C, 0x10, 0x38, 0x44, 0x38, // ю 0x00, 0x48, 0x34, 0x14, 0x14, 0x7c, // я 0x00, 0x7E, 0x4B, 0x4A, 0x4B, 0x42, // Ё 0x00, 0x38, 0x55, 0x54, 0x55, 0x18, // ё 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Є 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // є 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ї 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ї 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ў 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ў 0x00, 0x00, 0x06, 0x09, 0x09, 0x06, // ° 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ∙ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // · 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // √ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // № 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ¤ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ■ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x01, 0xAF, 0x30 }; // ширина символов, высота символов, код первого символа и количество символов const uint8_t font12x10[] PROGMEM = { 0x0C,0x10,0x20,0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // пробел 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, // ! 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " 0x00, 0x00, 0x60, 0xE0, 0xF8, 0x7E, 0x6E, 0xE0, 0xF8, 0x7E, 0x6E, 0x00, 0x00, 0x76, 0x7E, 0x1F, 0x07, 0x76, 0x7E, 0x1F, 0x07, 0x06, 0x00, 0x00, // # 0x00, 0x78, 0xFC, 0xCE, 0x86, 0xFF, 0xFF, 0x86, 0x9E, 0x1C, 0x18, 0x00, 0x00, 0x18, 0x38, 0x79, 0x61, 0xFF, 0xFF, 0x61, 0x73, 0x3F, 0x1E, 0x00, // $ 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0xBC, 0xE0, 0x78, 0x1E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x1E, 0x07, 0x3D, 0x7E, 0x66, 0x7E, 0x3C, 0x00, // % 0x00, 0x00, 0x00, 0x80, 0x80, 0xFC, 0xFE, 0xE6, 0xE6, 0x7E, 0x3C, 0x00, 0x00, 0x1E, 0x3F, 0x73, 0x61, 0x61, 0x71, 0x7F, 0x3F, 0x7C, 0x6C, 0x00, // & 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ' 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFC, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x3F, 0x70, 0xC0, 0x00, 0x00, 0x00, 0x00, // ( 0x00, 0x00, 0x00, 0x00, 0x03, 0x0E, 0xFC, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x3F, 0x0F, 0x00, 0x00, 0x00, 0x00, // ) 0x00, 0x00, 0x00, 0x08, 0x78, 0x3C, 0x3C, 0x78, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // * 0x00, 0x00, 0x80, 0x80, 0x80, 0xF0, 0xF0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x01, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, // , 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, // . 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // / 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // 0 0x00, 0x00, 0x00, 0x30, 0x38, 0x1C, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, // 1 0x00, 0x18, 0x1C, 0x1E, 0x06, 0x06, 0x06, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x78, 0x7C, 0x7E, 0x66, 0x67, 0x63, 0x63, 0x61, 0x70, 0x70, 0x00, // 2 0x00, 0x0E, 0x0E, 0x06, 0x06, 0xC6, 0xE6, 0xF6, 0xFE, 0x9E, 0x0E, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3F, 0x1F, 0x00, // 3 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x70, 0x38, 0x1C, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x66, 0x7F, 0x7F, 0x66, 0x00, // 4 0x00, 0xFE, 0xFE, 0xE6, 0x66, 0x66, 0x66, 0x66, 0xE6, 0xCE, 0x8E, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // 5 0x00, 0xF8, 0xFC, 0xCE, 0xC6, 0xC6, 0xC6, 0xC6, 0xDE, 0x9C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x71, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3F, 0x1F, 0x00, // 6 0x00, 0x1E, 0x1E, 0x06, 0x06, 0x06, 0x06, 0x86, 0xE6, 0x7E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, // 7 0x00, 0x78, 0xFC, 0xCE, 0x86, 0x86, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x1E, 0x3F, 0x73, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // 8 0x00, 0xF8, 0xFC, 0x8E, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x18, 0x39, 0x7B, 0x63, 0x63, 0x63, 0x63, 0x73, 0x3F, 0x1F, 0x00, // 9 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, // : 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, // ; 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0x60, 0x70, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x06, 0x0E, 0x0C, 0x0C, 0x00, 0x00, // < 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, // = 0x00, 0x00, 0x30, 0x30, 0x70, 0x60, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x0E, 0x06, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, // > 0x00, 0x18, 0x1C, 0x1E, 0x06, 0x06, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6E, 0x6F, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, // ? 0x00, 0xF8, 0xFC, 0x0E, 0xE6, 0xF6, 0x36, 0xF6, 0xF6, 0x0E, 0xFC, 0xF8, 0x00, 0x1F, 0x3F, 0x70, 0x67, 0x6F, 0x6C, 0x6F, 0x67, 0x6C, 0x2F, 0x07, //@ 0x00, 0x00, 0xF0, 0xFC, 0x1E, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x63, 0x7F, 0x7F, 0x60, 0x00, //A 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, //B 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x1C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x78, 0x38, 0x18, 0x00, //C 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, //D 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0x86, 0xC6, 0xC6, 0x0E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x63, 0x63, 0x70, 0x70, 0x00, //E 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0xC6, 0xC6, 0x06, 0x0E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, //F 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x1C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x63, 0x63, 0x73, 0x3F, 0x1F, 0x00, //G 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0x80, 0x86, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x01, 0x61, 0x7F, 0x7F, 0x60, 0x00, //H 0x00, 0x00, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, //I 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, 0x00, //J 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x03, 0x6F, 0x7E, 0x78, 0x60, 0x00, //K 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x00, //L 0x00, 0x06, 0xFE, 0xFE, 0x78, 0xE0, 0xE0, 0x78, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x01, 0x01, 0x60, 0x7F, 0x7F, 0x60, 0x00, //M 0x00, 0x06, 0xFE, 0xFE, 0x78, 0xE0, 0x80, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x01, 0x07, 0x1E, 0x7F, 0x7F, 0x60, 0x00, //N 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, //O 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, // P 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x6C, 0x7C, 0x38, 0x7F, 0x6F, 0x00, // Q 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x6F, 0x7F, 0x79, 0x60, 0x00, // R 0x00, 0x78, 0xFC, 0xCE, 0x86, 0x86, 0x86, 0x86, 0x9E, 0x1C, 0x18, 0x00, 0x00, 0x18, 0x38, 0x79, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // S 0x00, 0x0E, 0x0E, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // T 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, 0x00, // U 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x3E, 0x78, 0x78, 0x3E, 0x0F, 0x03, 0x00, 0x00, // V 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x80, 0x80, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x7F, 0x78, 0x1F, 0x1F, 0x78, 0x7F, 0x1F, 0x00, 0x00, // W 0x00, 0x06, 0x1E, 0x7E, 0xF6, 0xC0, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x78, 0x7E, 0x6F, 0x03, 0x03, 0x6F, 0x7E, 0x78, 0x60, 0x00, // X 0x00, 0x06, 0x7E, 0xFE, 0xC6, 0x00, 0x00, 0xC6, 0xFE, 0x7E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x63, 0x7F, 0x7F, 0x63, 0x01, 0x00, 0x00, 0x00, // Y 0x00, 0x0E, 0x0E, 0x06, 0x06, 0x86, 0xC6, 0xE6, 0x76, 0x3E, 0x1E, 0x00, 0x00, 0x78, 0x7C, 0x6E, 0x67, 0x63, 0x61, 0x60, 0x60, 0x70, 0x70, 0x00, // Z 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, // [ 0x00, 0x00, 0x06, 0x1E, 0x78, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x1E, 0x78, 0x60, 0x00, 0x00, // обратный слеш 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // ] 0x00, 0x00, 0x00, 0x30, 0x3C, 0x1E, 0x1E, 0x3C, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, // _ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x1C, 0x3E, 0x77, 0x63, 0x63, 0x63, 0x33, 0x7F, 0x7F, 0x60, 0x00, // a 0x00, 0x06, 0xFE, 0xFE, 0x66, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x30, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // b 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x78, 0x38, 0x18, 0x00, // c 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x66, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x30, 0x7F, 0x7F, 0x60, 0x00, // d 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x76, 0x66, 0x66, 0x66, 0x66, 0x76, 0x37, 0x17, 0x00, // e 0x00, 0x00, 0x00, 0x60, 0xFC, 0xFE, 0x66, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // f 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x60, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x33, 0x77, 0xEE, 0xCC, 0xCC, 0xCC, 0xEE, 0x7F, 0x3F, 0x00, 0x00, // g 0x00, 0x06, 0xFE, 0xFE, 0x66, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // h 0x00, 0x00, 0x00, 0x00, 0x30, 0xF6, 0xF6, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // i 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xF6, 0xF6, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x7F, 0x3F, 0x00, 0x00, 0x00, 0x00, // j 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x80, 0xF0, 0xF0, 0x70, 0x30, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x07, 0x0F, 0x7C, 0x78, 0x70, 0x60, 0x00, // k 0x00, 0x00, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // l 0x30, 0xF0, 0xE0, 0x30, 0x30, 0xF0, 0xE0, 0x30, 0x30, 0xF0, 0xE0, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x7F, 0x7F, 0x00, 0x60, 0x7F, 0x7F, 0x60, // m 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // n 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // o 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xD8, 0x30, 0x30, 0x30, 0x38, 0x1F, 0x0F, 0x00, // p 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x60, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x0F, 0x1F, 0x38, 0x30, 0x30, 0x30, 0xD8, 0xFF, 0xFF, 0xC0, 0x00, // q 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x70, 0x60, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // r 0x00, 0xE0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0x30, 0x70, 0x70, 0x60, 0x00, 0x00, 0x19, 0x3B, 0x7B, 0x63, 0x63, 0x63, 0x63, 0x77, 0x3E, 0x1C, 0x00, // s 0x00, 0x00, 0x00, 0x30, 0xFE, 0xFE, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, // t 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x30, 0x7F, 0x7F, 0x60, 0x00, // u 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x78, 0x78, 0x1F, 0x07, 0x00, 0x00, 0x00, // v 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x03, 0x1F, 0x7C, 0x70, 0x1E, 0x1E, 0x70, 0x7C, 0x1F, 0x03, 0x00, // w 0x00, 0x00, 0x30, 0x70, 0xF0, 0x80, 0x80, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x70, 0x7D, 0x0F, 0x0F, 0x7D, 0x70, 0x60, 0x00, 0x00, // x 0x00, 0x00, 0x30, 0xF0, 0xC0, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x73, 0x3F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, // y 0x00, 0x00, 0x70, 0x70, 0x30, 0x30, 0xB0, 0xF0, 0xF0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x78, 0x7C, 0x6E, 0x67, 0x63, 0x61, 0x70, 0x70, 0x00, 0x00, // z 0x00, 0x00, 0x80, 0xC0, 0xFC, 0x7E, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x3F, 0x7E, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, // { 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, // | 0x00, 0x00, 0x00, 0x03, 0x03, 0x07, 0x7E, 0xFC, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xE0, 0x7E, 0x3F, 0x03, 0x01, 0x00, 0x00, // } 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, // ~ 0 }; // ширина символов, высота символов, код первого символа и количество символов const uint8_t fontRus12x10[] PROGMEM = { 0x0C, 0x10, 0x20,0xB0, // | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // пробел 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, // ! 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " 0x00, 0x00, 0x60, 0xE0, 0xF8, 0x7E, 0x6E, 0xE0, 0xF8, 0x7E, 0x6E, 0x00, 0x00, 0x76, 0x7E, 0x1F, 0x07, 0x76, 0x7E, 0x1F, 0x07, 0x06, 0x00, 0x00, // # 0x00, 0x78, 0xFC, 0xCE, 0x86, 0xFF, 0xFF, 0x86, 0x9E, 0x1C, 0x18, 0x00, 0x00, 0x18, 0x38, 0x79, 0x61, 0xFF, 0xFF, 0x61, 0x73, 0x3F, 0x1E, 0x00, // $ 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0xBC, 0xE0, 0x78, 0x1E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x1E, 0x07, 0x3D, 0x7E, 0x66, 0x7E, 0x3C, 0x00, // % 0x00, 0x00, 0x00, 0x80, 0x80, 0xFC, 0xFE, 0xE6, 0xE6, 0x7E, 0x3C, 0x00, 0x00, 0x1E, 0x3F, 0x73, 0x61, 0x61, 0x71, 0x7F, 0x3F, 0x7C, 0x6C, 0x00, // & 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ' 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFC, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x3F, 0x70, 0xC0, 0x00, 0x00, 0x00, 0x00, // ( 0x00, 0x00, 0x00, 0x00, 0x03, 0x0E, 0xFC, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x3F, 0x0F, 0x00, 0x00, 0x00, 0x00, // ) 0x00, 0x00, 0x00, 0x08, 0x78, 0x3C, 0x3C, 0x78, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // * 0x00, 0x00, 0x80, 0x80, 0x80, 0xF0, 0xF0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x01, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, // , 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, // . 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // / 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // 0 0x00, 0x00, 0x00, 0x30, 0x38, 0x1C, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, // 1 0x00, 0x18, 0x1C, 0x1E, 0x06, 0x06, 0x06, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x78, 0x7C, 0x7E, 0x66, 0x67, 0x63, 0x63, 0x61, 0x70, 0x70, 0x00, // 2 0x00, 0x0E, 0x0E, 0x06, 0x06, 0xC6, 0xE6, 0xF6, 0xFE, 0x9E, 0x0E, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3F, 0x1F, 0x00, // 3 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x70, 0x38, 0x1C, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x66, 0x7F, 0x7F, 0x66, 0x00, // 4 0x00, 0xFE, 0xFE, 0xE6, 0x66, 0x66, 0x66, 0x66, 0xE6, 0xCE, 0x8E, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // 5 0x00, 0xF8, 0xFC, 0xCE, 0xC6, 0xC6, 0xC6, 0xC6, 0xDE, 0x9C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x71, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3F, 0x1F, 0x00, // 6 0x00, 0x1E, 0x1E, 0x06, 0x06, 0x06, 0x06, 0x86, 0xE6, 0x7E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, // 7 0x00, 0x78, 0xFC, 0xCE, 0x86, 0x86, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x1E, 0x3F, 0x73, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // 8 0x00, 0xF8, 0xFC, 0x8E, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x18, 0x39, 0x7B, 0x63, 0x63, 0x63, 0x63, 0x73, 0x3F, 0x1F, 0x00, // 9 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, // : 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, // ; 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0x60, 0x70, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x06, 0x0E, 0x0C, 0x0C, 0x00, 0x00, // < 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, // = 0x00, 0x00, 0x30, 0x30, 0x70, 0x60, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x0E, 0x06, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, // > 0x00, 0x18, 0x1C, 0x1E, 0x06, 0x06, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6E, 0x6F, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, // ? 0x00, 0xF8, 0xFC, 0x0E, 0xE6, 0xF6, 0x36, 0xF6, 0xF6, 0x0E, 0xFC, 0xF8, 0x00, 0x1F, 0x3F, 0x70, 0x67, 0x6F, 0x6C, 0x6F, 0x67, 0x6C, 0x2F, 0x07, // @ 0x00, 0x00, 0xF0, 0xFC, 0x1E, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x63, 0x7F, 0x7F, 0x60, 0x00, // A 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // B 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x1C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x78, 0x38, 0x18, 0x00, // C 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // D 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0x86, 0xC6, 0xC6, 0x0E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x63, 0x63, 0x70, 0x70, 0x00, // E 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0xC6, 0xC6, 0x06, 0x0E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, // F 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x1C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x63, 0x63, 0x73, 0x3F, 0x1F, 0x00, // G 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0x80, 0x86, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x01, 0x61, 0x7F, 0x7F, 0x60, 0x00, // H 0x00, 0x00, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // I 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, 0x00, // J 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x03, 0x6F, 0x7E, 0x78, 0x60, 0x00, // K 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x00, // L 0x00, 0x06, 0xFE, 0xFE, 0x78, 0xE0, 0xE0, 0x78, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x01, 0x01, 0x60, 0x7F, 0x7F, 0x60, 0x00, // M 0x00, 0x06, 0xFE, 0xFE, 0x78, 0xE0, 0x80, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x01, 0x07, 0x1E, 0x7F, 0x7F, 0x60, 0x00, // N 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // O 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, // P 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x6C, 0x7C, 0x38, 0x7F, 0x6F, 0x00, // Q 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x6F, 0x7F, 0x79, 0x60, 0x00, // R 0x00, 0x78, 0xFC, 0xCE, 0x86, 0x86, 0x86, 0x86, 0x9E, 0x1C, 0x18, 0x00, 0x00, 0x18, 0x38, 0x79, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // S 0x00, 0x0E, 0x0E, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // T 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, 0x00, // U 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x3E, 0x78, 0x78, 0x3E, 0x0F, 0x03, 0x00, 0x00, // V 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x80, 0x80, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x7F, 0x78, 0x1F, 0x1F, 0x78, 0x7F, 0x1F, 0x00, 0x00, // W 0x00, 0x06, 0x1E, 0x7E, 0xF6, 0xC0, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x78, 0x7E, 0x6F, 0x03, 0x03, 0x6F, 0x7E, 0x78, 0x60, 0x00, // X 0x00, 0x06, 0x7E, 0xFE, 0xC6, 0x00, 0x00, 0xC6, 0xFE, 0x7E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x63, 0x7F, 0x7F, 0x63, 0x01, 0x00, 0x00, 0x00, // Y 0x00, 0x0E, 0x0E, 0x06, 0x06, 0x86, 0xC6, 0xE6, 0x76, 0x3E, 0x1E, 0x00, 0x00, 0x78, 0x7C, 0x6E, 0x67, 0x63, 0x61, 0x60, 0x60, 0x70, 0x70, 0x00, // Z 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, // [ 0x00, 0x00, 0x06, 0x1E, 0x78, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x1E, 0x78, 0x60, 0x00, 0x00, // обратный слеш 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // ] 0x00, 0x00, 0x00, 0x30, 0x3C, 0x1E, 0x1E, 0x3C, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, // _ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x1C, 0x3E, 0x77, 0x63, 0x63, 0x63, 0x33, 0x7F, 0x7F, 0x60, 0x00, // a 0x00, 0x06, 0xFE, 0xFE, 0x66, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x30, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // b 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x78, 0x38, 0x18, 0x00, // c 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x66, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x30, 0x7F, 0x7F, 0x60, 0x00, // d 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x76, 0x66, 0x66, 0x66, 0x66, 0x76, 0x37, 0x17, 0x00, // e 0x00, 0x00, 0x00, 0x60, 0xFC, 0xFE, 0x66, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // f 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x60, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x33, 0x77, 0xEE, 0xCC, 0xCC, 0xCC, 0xEE, 0x7F, 0x3F, 0x00, 0x00, // g 0x00, 0x06, 0xFE, 0xFE, 0x66, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // h 0x00, 0x00, 0x00, 0x00, 0x30, 0xF6, 0xF6, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // i 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xF6, 0xF6, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x7F, 0x3F, 0x00, 0x00, 0x00, 0x00, // j 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x80, 0xF0, 0xF0, 0x70, 0x30, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x07, 0x0F, 0x7C, 0x78, 0x70, 0x60, 0x00, // k 0x00, 0x00, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // l 0x30, 0xF0, 0xE0, 0x30, 0x30, 0xF0, 0xE0, 0x30, 0x30, 0xF0, 0xE0, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x7F, 0x7F, 0x00, 0x60, 0x7F, 0x7F, 0x60, // m 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // n 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // o 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xD8, 0x30, 0x30, 0x30, 0x38, 0x1F, 0x0F, 0x00, // p 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x60, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x0F, 0x1F, 0x38, 0x30, 0x30, 0x30, 0xD8, 0xFF, 0xFF, 0xC0, 0x00, // q 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x70, 0x60, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // r 0x00, 0xE0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0x30, 0x70, 0x70, 0x60, 0x00, 0x00, 0x19, 0x3B, 0x7B, 0x63, 0x63, 0x63, 0x63, 0x77, 0x3E, 0x1C, 0x00, // s 0x00, 0x00, 0x00, 0x30, 0xFE, 0xFE, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, // t 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x30, 0x7F, 0x7F, 0x60, 0x00, // u 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x78, 0x78, 0x1F, 0x07, 0x00, 0x00, 0x00, // v 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x03, 0x1F, 0x7C, 0x70, 0x1E, 0x1E, 0x70, 0x7C, 0x1F, 0x03, 0x00, // w 0x00, 0x00, 0x30, 0x70, 0xF0, 0x80, 0x80, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x70, 0x7D, 0x0F, 0x0F, 0x7D, 0x70, 0x60, 0x00, 0x00, // x 0x00, 0x00, 0x30, 0xF0, 0xC0, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x73, 0x3F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, // y 0x00, 0x00, 0x70, 0x70, 0x30, 0x30, 0xB0, 0xF0, 0xF0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x78, 0x7C, 0x6E, 0x67, 0x63, 0x61, 0x70, 0x70, 0x00, 0x00, // z 0x00, 0x00, 0x80, 0xC0, 0xFC, 0x7E, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x3F, 0x7E, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, // { 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, // | 0x00, 0x00, 0x00, 0x03, 0x03, 0x07, 0x7E, 0xFC, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xE0, 0x7E, 0x3F, 0x03, 0x01, 0x00, 0x00, // } 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, // ~ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ⌂ 0x00, 0x00, 0xF0, 0xFC, 0x1E, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x63, 0x7F, 0x7F, 0x60, 0x00, // А 0x00, 0x06, 0xFE, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x8E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3F, 0x1F, 0x00, // Б 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0x86, 0x86, 0xCE, 0xFC, 0x78, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // В 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x06, 0x0E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Г 0x00, 0x00, 0xF0, 0xFC, 0x1E, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x78, 0x7F, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x7F, 0x78, 0x00, // Д 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x86, 0x86, 0xC6, 0xC6, 0x0E, 0x0E, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x63, 0x63, 0x70, 0x70, 0x00, // Е 0x00, 0x06, 0x7E, 0xFE, 0xC0, 0xFE, 0xFE, 0xC0, 0xFE, 0x7E, 0x06, 0x00, 0x00, 0x60, 0x7E, 0x7F, 0x03, 0x7F, 0x7F, 0x03, 0x7F, 0x7E, 0x60, 0x00, // Ж 0x00, 0x18, 0x1C, 0x1E, 0x06, 0x06, 0xC6, 0xC6, 0xEE, 0xFC, 0x38, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3F, 0x1F, 0x00, // З 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x80, 0xE0, 0x78, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x1E, 0x07, 0x01, 0x60, 0x7F, 0x7F, 0x60, 0x00, // И 0x00, 0x06, 0xFE, 0xFE, 0x01, 0x83, 0xE3, 0x79, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x1E, 0x07, 0x01, 0x60, 0x7F, 0x7F, 0x60, 0x00, // Й 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x03, 0x6F, 0x7E, 0x78, 0x60, 0x00, // К 0x00, 0x00, 0xF0, 0xFC, 0x1E, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x3F, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // Л 0x00, 0x06, 0xFE, 0xFE, 0x78, 0xE0, 0xE0, 0x78, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x01, 0x01, 0x60, 0x7F, 0x7F, 0x60, 0x00, // М 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0x80, 0x86, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x01, 0x01, 0x61, 0x7F, 0x7F, 0x60, 0x00, // Н 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // О 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // П 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, // Р 0x00, 0xF8, 0xFC, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x1C, 0x18, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x78, 0x38, 0x18, 0x00, // С 0x00, 0x0E, 0x0E, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // Т 0x00, 0x06, 0x1E, 0x7E, 0xF6, 0xC0, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x60, 0x70, 0x7D, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, // У 0x00, 0xF0, 0xF8, 0x1C, 0x0C, 0xFE, 0xFE, 0x0C, 0x1C, 0xF8, 0xF0, 0x00, 0x00, 0x0F, 0x1F, 0x38, 0x30, 0x7F, 0x7F, 0x30, 0x38, 0x1F, 0x0F, 0x00, // Ф 0x00, 0x06, 0x1E, 0x7E, 0xF6, 0xC0, 0xC0, 0xF6, 0x7E, 0x1E, 0x06, 0x00, 0x00, 0x60, 0x78, 0x7E, 0x6F, 0x03, 0x03, 0x6F, 0x7E, 0x78, 0x60, 0x00, // Х 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x7F, 0x7F, 0xE0, 0xE0, // Ц 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x00, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x63, 0x7F, 0x7F, 0x60, 0x00, // Ч 0x00, 0x06, 0xFE, 0xFE, 0x06, 0xF0, 0xF0, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0x60, 0x00, // Ш 0x00, 0x06, 0xFE, 0xFE, 0x06, 0xF0, 0xF0, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0xE0, 0xE0, // Щ 0x06, 0x06, 0xFE, 0xFE, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // Ъ 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0x00, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x7F, 0x1F, 0x60, 0x7F, 0x7F, 0x60, 0x00, // Ы 0x00, 0x06, 0xFE, 0xFE, 0x86, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x61, 0x73, 0x3F, 0x1E, 0x00, // Ь 0x00, 0x18, 0x1C, 0x1E, 0x06, 0x06, 0x86, 0x86, 0x8E, 0xFC, 0xF8, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x61, 0x61, 0x71, 0x3F, 0x1F, 0x00, // Э 0x00, 0x06, 0xFE, 0xFE, 0x86, 0xF8, 0xFC, 0x0E, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x1F, 0x3F, 0x70, 0x60, 0x70, 0x3F, 0x1F, // Ю 0x00, 0xF8, 0xFC, 0x8E, 0x06, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x00, 0x00, 0x60, 0x79, 0x7F, 0x6F, 0x03, 0x03, 0x63, 0x7F, 0x7F, 0x60, 0x00, // Я 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x1C, 0x3E, 0x77, 0x63, 0x63, 0x63, 0x33, 0x7F, 0x7F, 0x60, 0x00, // а 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0x30, 0x70, 0x70, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x63, 0x63, 0x63, 0x77, 0x3E, 0x1C, 0x00, // б 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x63, 0x63, 0x63, 0x77, 0x3F, 0x1C, 0x00, // в 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0x30, 0x70, 0x70, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // г 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0xF0, 0xFF, 0x3F, 0x30, 0x30, 0x30, 0x30, 0x3F, 0xFF, 0xF0, 0x00, // д 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x76, 0x66, 0x66, 0x66, 0x66, 0x76, 0x37, 0x17, 0x00, // е 0x00, 0x30, 0x70, 0xF0, 0x80, 0xF0, 0xF0, 0x80, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x60, 0x70, 0x7D, 0x0F, 0x7F, 0x7F, 0x0F, 0x7D, 0x70, 0x60, 0x00, // ж 0x00, 0xC0, 0xE0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x63, 0x63, 0x63, 0x77, 0x3F, 0x1C, 0x00, // з 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0xB0, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x7C, 0x0E, 0x07, 0x63, 0x7F, 0x7F, 0x60, 0x00, // и 0x00, 0x30, 0xF0, 0xF3, 0x37, 0x06, 0x06, 0xB7, 0xF3, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x7C, 0x0E, 0x07, 0x63, 0x7F, 0x7F, 0x60, 0x00, // й 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x80, 0xF0, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x07, 0x0F, 0x7D, 0x78, 0x70, 0x60, 0x00, // к 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x3F, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // л 0x00, 0x30, 0xF0, 0xF0, 0xC0, 0x80, 0x80, 0xC0, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x07, 0x07, 0x61, 0x7F, 0x7F, 0x60, 0x00, // м 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x03, 0x03, 0x63, 0x7F, 0x7F, 0x60, 0x00, // н 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x70, 0x3F, 0x1F, 0x00, // о 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, // п 0x00, 0x30, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xD8, 0x30, 0x30, 0x30, 0x38, 0x1F, 0x0F, 0x00, // р 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, 0x60, 0x78, 0x38, 0x18, 0x00, // с 0x00, 0x70, 0x70, 0x30, 0x30, 0xF0, 0xF0, 0x30, 0x30, 0x70, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x00, 0x00, 0x00, 0x00, // т 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x00, 0x00, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x73, 0x3F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, // у 0x00, 0xC0, 0xE0, 0x70, 0x30, 0xF8, 0xF8, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0x60, 0xFF, 0xFF, 0x60, 0x70, 0x3F, 0x1F, 0x00, // ф 0x00, 0x00, 0x30, 0x70, 0xF0, 0x80, 0x80, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x70, 0x7D, 0x0F, 0x0F, 0x7D, 0x70, 0x60, 0x00, 0x00, // х 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x7F, 0x7F, 0xE0, 0xE0, // ц 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x03, 0x07, 0x06, 0x06, 0x06, 0x66, 0x7F, 0x7F, 0x60, 0x00, // ч 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x80, 0x80, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0x60, 0x00, // ш 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x80, 0x80, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0x60, 0x7F, 0x7F, 0xE0, 0xE0, // щ 0x30, 0x30, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x63, 0x63, 0x63, 0x77, 0x3E, 0x1C, 0x00, // ъ 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x60, 0x7F, 0x7F, 0x63, 0x63, 0x77, 0x3E, 0x1C, 0x60, 0x7F, 0x7F, 0x60, // ы 0x00, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x63, 0x63, 0x63, 0x63, 0x77, 0x3E, 0x1C, 0x00, // ь 0x00, 0xC0, 0xE0, 0xF0, 0x30, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x18, 0x38, 0x78, 0x60, 0x60, 0x63, 0x63, 0x73, 0x3F, 0x1F, 0x00, // э 0x30, 0xF0, 0xF0, 0x30, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x60, 0x7F, 0x7F, 0x63, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x70, 0x3F, 0x1F, // ю 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x30, 0x30, 0xF0, 0xF0, 0x30, 0x00, 0x00, 0x61, 0x73, 0x7F, 0x6E, 0x06, 0x06, 0x66, 0x7F, 0x7F, 0x60, 0x00, // я 0x00, 0x0C, 0xFC, 0xFF, 0x8F, 0x8C, 0x8C, 0xCF, 0xCF, 0x1C, 0x1C, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x61, 0x61, 0x61, 0x63, 0x63, 0x70, 0x70, 0x00, // Ё 0x00, 0xC0, 0xE0, 0x76, 0x36, 0x30, 0x30, 0x36, 0x76, 0xE0, 0xC0, 0x00, 0x00, 0x1F, 0x3F, 0x76, 0x66, 0x66, 0x66, 0x66, 0x76, 0x37, 0x17, 0x00, // ё 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Є 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // є 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ї 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ї 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ў 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ў 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ° 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ∙ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // · 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // √ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // № 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ¤ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ■ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //   0x01, 0xAF, 0x30 }; // ширина символов, высота символов, код первого символа и количество символов const uint8_t mediumNumbers[] PROGMEM = { 0x0C, 0x10, 0x2D, 0x0D, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, // . 0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x81, 0x00, 0x00, // / 0x00, 0xFC, 0x7A, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7A, 0xFC, 0x00, 0x00, 0x7E, 0xBC, 0xC0, 0xC0, 0xc0, 0xC0, 0xC0, 0xC0, 0xBC, 0x7E, 0x00, // 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x00, // 1 0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7A, 0xFC, 0x00, 0x00, 0x7E, 0xBD, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x81, 0x00, 0x00, // 2 0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7A, 0xFC, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xBD, 0x7E, 0x00, // 3 0x00, 0xFC, 0x78, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x78, 0xFC, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3D, 0x7E, 0x00, // 4 0x00, 0xFC, 0x7A, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xBD, 0x7E, 0x00, // 5 0x00, 0xFC, 0x7A, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 0x00, 0x00, 0x7E, 0xBD, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xBD, 0x7E, 0x00, // 6 0x00, 0x00, 0x02, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7A, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x00, // 7 0x00, 0xFC, 0x7A, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7A, 0xFC, 0x00, 0x00, 0x7E, 0xBD, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xBD, 0x7E, 0x00, // 8 0x00, 0xFC, 0x7A, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7A, 0xFC, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xBD, 0x7E, 0x00, // 9 0 }; // ширина символов, высота символов, код первого символа и количество символов const uint8_t bigNumbers[] PROGMEM = { 0x0E, 0x18, 0x2D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, // . 0x00, 0x00, 0x02, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, // / 0x00, 0xFC, 0xFA, 0xF6, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0xF6, 0xFA, 0xFC, 0x00, 0x00, 0xEF, 0xC7, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xC7, 0xEF, 0x00, 0x00, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xbf, 0x7F, 0x00, // 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF8, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xC7, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x00, // 1 0x00, 0x00, 0x02, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0xF6, 0xFA, 0xFC, 0x00, 0x00, 0xE0, 0xD0, 0xB8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x3B, 0x17, 0x0f, 0x00, 0x00, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, // 2 0x00, 0x00, 0x02, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0e, 0xF6, 0xFA, 0xFC, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xBB, 0xD7, 0xEF, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x00, // 3 0x00, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF8, 0xFC, 0x00, 0x00, 0x0F, 0x17, 0x3B, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xBB, 0xD7, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x00, // 4 0x00, 0xFC, 0xFA, 0xF6, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x0F, 0x17, 0x3B, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xB8, 0xD0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x00, // 5 0x00, 0xFC, 0xFA, 0xF6, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0xEF, 0xD7, 0xBB, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xB8, 0xD0, 0xE0, 0x00, 0x00, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x00, // 6 0x00, 0x00, 0x02, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0xF6, 0xFA, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xC7, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x00, // 7 0x00, 0xFC, 0xFA, 0xF6, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0xF6, 0xFA, 0xFC, 0x00, 0x00, 0xEF, 0xD7, 0xBB, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xBB, 0xD7, 0xEF, 0x00, 0x00, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x00, // 8 0x00, 0xFC, 0xFA, 0xF6, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0xF6, 0xFA, 0xFC, 0x00, 0x00, 0x0F, 0x17, 0x3B, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xBB, 0xD7, 0xEF, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x00, // 9 0 }; // ширина символов, высота символов, код первого символа и количество символов const uint8_t megaNumbers[] PROGMEM = { 0x18, 0x28, 0x2D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xF8, 0xFC, 0xFE, 0xFE, 0xFC, 0xF8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // . 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0F, 0x1F, 0x3F, 0x3F, 0x1F, 0x0F, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x7C, 0xFE, 0xFF, 0xFF, 0xFE, 0x7C, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // / 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xFC, 0xFE, 0x3F, 0x07, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xE0, 0xF8, 0xFF, 0x3F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, 0x1F, 0x1F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x0F, 0x1F, 0x3F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // 1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x83, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF8, 0xFC, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF8, 0xFE, 0xDF, 0xEF, 0xEF, 0xE7, 0xE3, 0xE1, 0xE1, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x1F, 0x1F, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x00, // 2 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xF0, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x81, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFF, 0xF9, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0xC1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 3 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF8, 0xF8, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF8, 0x3C, 0x1F, 0x07, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFC, 0xFF, 0xE7, 0xE3, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0x83, 0xC3, 0xC3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x0F, 0x0F, 0x07, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, // 4 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x07, 0x01, 0x81, 0xC1, 0xC1, 0xE1, 0xF1, 0xE1, 0xE1, 0xC1, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x1F, 0x0E, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xF0, 0xFC, 0xFC, 0xFC, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0xC0, 0x80, 0x80, 0xE0, 0xFF, 0xFF, 0x7F, 0x3F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 5 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0xFC, 0xFE, 0x7F, 0x0F, 0x01, 0x01, 0x03, 0x83, 0x87, 0xCF, 0xCF, 0xDF, 0x8F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xB8, 0x1C, 0x1E, 0x0E, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x80, 0xE0, 0xFF, 0xFF, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0x78, 0x38, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1E, 0x1F, 0x07, 0x03, 0x03, 0x01, 0x01, 0x01, 0x81, 0xC1, 0xF1, 0xF9, 0xFD, 0x3F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0x3F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 7 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFC, 0xFF, 0xFF, 0xE7, 0xC1, 0xC1, 0x81, 0x81, 0x81, 0x81, 0x83, 0xC3, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xCF, 0xFF, 0xFF, 0x7F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xFB, 0x7F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 8 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xF8, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xFE, 0xFF, 0xFF, 0x87, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0x70, 0x38, 0x3C, 0x1E, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0, 0xF9, 0xFD, 0xFB, 0xF1, 0xF0, 0xE0, 0xC0, 0xC0, 0xE0, 0xFC, 0xFF, 0x7F, 0x1F, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 9 0 };
112.603945
728
0.58599
ba66a427d6b946faa208a3eaaa0ba915ef04bfba
3,781
h
C
Dmf/Modules.Library/Dmf_GpioTarget.h
mr-yamraj01/DMF
e4f24eadf4975e931946cdaaed4c6e300b7c6fca
[ "MIT" ]
1
2019-03-23T18:32:05.000Z
2019-03-23T18:32:05.000Z
Dmf/Modules.Library/Dmf_GpioTarget.h
Gotham13121997/DMF
86b3a8bce364e811cbd084171149fdf3562b8201
[ "MIT" ]
null
null
null
Dmf/Modules.Library/Dmf_GpioTarget.h
Gotham13121997/DMF
86b3a8bce364e811cbd084171149fdf3562b8201
[ "MIT" ]
null
null
null
/*++ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. Module Name: Dmf_GpioTarget.h Abstract: Companion file to Dmf_GpioTarget.c. Environment: Kernel-mode Driver Framework User-mode Driver Framework --*/ #pragma once typedef enum { // Sentinel for validity checking. // GpioTarget_QueuedWorkItem_Invalid, // ISR/DPC has no additional work to do. // GpioTarget_QueuedWorkItem_Nothing, // ISR has more work to do at DISPATCH_LEVEL. // GpioTarget_QueuedWorkItem_Dpc, // DPC has more work to do at PASSIVE_LEVEL. // GpioTarget_QueuedWorkItem_WorkItem } GpioTarget_QueuedWorkItem_Type; // Client Driver DIRQL_LEVEL Callback. // typedef _Function_class_(EVT_DMF_GpioTarget_InterruptIsr) _IRQL_requires_max_(DISPATCH_LEVEL) _IRQL_requires_same_ BOOLEAN EVT_DMF_GpioTarget_InterruptIsr(_In_ DMFMODULE DmfModule, _In_ ULONG MessageId, _Out_ GpioTarget_QueuedWorkItem_Type* QueuedWorkItem); // Client Driver DPC_LEVEL Callback. // typedef _Function_class_(EVT_DMF_GpioTarget_InterruptDpc) _IRQL_requires_max_(DISPATCH_LEVEL) _IRQL_requires_same_ VOID EVT_DMF_GpioTarget_InterruptDpc(_In_ DMFMODULE DmfModule, _Out_ GpioTarget_QueuedWorkItem_Type* QueuedWorkItem); // Client Driver PASSIVE_LEVEL Callback. // typedef _Function_class_(EVT_DMF_GpioTarget_InterruptPassive) _IRQL_requires_max_(PASSIVE_LEVEL) _IRQL_requires_same_ VOID EVT_DMF_GpioTarget_InterruptPassive(_In_ DMFMODULE DmfModule); // Client uses this structure to configure the Module specific parameters. // typedef struct { // Module will not load if Gpio Connection not found. // BOOLEAN GpioConnectionMandatory; // Module will not load if Interrupt not found. // BOOLEAN InterruptMandatory; // GPIO Connection index for this instance. // ULONG GpioConnectionIndex; // Interrupt index for this instance. // ULONG InterruptIndex; // Open in Read or Write mode. // ULONG OpenMode; // Share Access. // ULONG ShareAccess; // Passive handling. // BOOLEAN PassiveHandling; // Can GPIO wake the device. // BOOLEAN CanWakeDevice; // Optional Callback from ISR (with Interrupt Spin Lock held). // EVT_DMF_GpioTarget_InterruptIsr* EvtGpioTargetInterruptIsr; // Optional Callback at DPC_LEVEL Level. // EVT_DMF_GpioTarget_InterruptDpc* EvtGpioTargetInterruptDpc; // Optional Callback at PASSIVE_LEVEL Level. // EVT_DMF_GpioTarget_InterruptPassive* EvtGpioTargetInterruptPassive; } DMF_CONFIG_GpioTarget; // This macro declares the following functions: // DMF_GpioTarget_ATTRIBUTES_INIT() // DMF_CONFIG_GpioTarget_AND_ATTRIBUTES_INIT() // DMF_GpioTarget_Create() // DECLARE_DMF_MODULE(GpioTarget) // Module Methods // _IRQL_requires_max_(DISPATCH_LEVEL) VOID DMF_GpioTarget_InterruptAcquireLock( _In_ DMFMODULE DmfModule ); _IRQL_requires_max_(DISPATCH_LEVEL) VOID DMF_GpioTarget_InterruptReleaseLock( _In_ DMFMODULE DmfModule ); _Must_inspect_result_ _IRQL_requires_max_(PASSIVE_LEVEL) BOOLEAN DMF_GpioTarget_InterruptTryToAcquireLock( _In_ DMFMODULE DmfModule ); _IRQL_requires_max_(PASSIVE_LEVEL) VOID DMF_GpioTarget_IsResourceAssigned( _In_ DMFMODULE DmfModule, _Out_opt_ BOOLEAN* GpioConnectionAssigned, _Out_opt_ BOOLEAN* InterruptAssigned ); _IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS DMF_GpioTarget_Read( _In_ DMFMODULE DmfModule, _Out_ BOOLEAN* PinValue ); _IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS DMF_GpioTarget_Write( _In_ DMFMODULE DmfModule, _In_ BOOLEAN Value ); // eof: Dmf_GpioTarget.h //
23.484472
86
0.749008
0fc2b27d01f58e3a774f0a432988d73795096959
1,312
c
C
three-bits.c
crithead/problems
9d339babe3ebb70b28db3b9efa53b2c9c6717ca9
[ "BSD-2-Clause" ]
null
null
null
three-bits.c
crithead/problems
9d339babe3ebb70b28db3b9efa53b2c9c6717ca9
[ "BSD-2-Clause" ]
null
null
null
three-bits.c
crithead/problems
9d339babe3ebb70b28db3b9efa53b2c9c6717ca9
[ "BSD-2-Clause" ]
null
null
null
/** * @file three_bits.c * @brief Print the sum of numbers from 1 to 100 that have only three bits on. * * This is a solution program to an interview test question. The Problem * statement is "Write a program that prints the sum of the numbers from 1 * to 100 that have only three bits set to 1." This tests the applicant's * understanding of binary data structure and ability to write a small C * program. */ #include <stdio.h> /** * @def DEBUG * @brief Enable/Disable debug print messages. */ #define DEBUG if(0) static int number_of_bits_on(int); /** * @brief Print sum of digits in [1,100] with 3 bits on. * @param argc Ignored. * @param argv Ignored. */ int main(int argc, char *argv[]) { int sum = 0; int i; for (i = 1; i <= 100; i++) { if (number_of_bits_on(i) == 3) sum += i; DEBUG printf("%4d, bits on %4d\n", i, number_of_bits_on(i)); } printf("sum %d\n", sum); return 0; } /** * @brief Count the number of 1 bits in a number. * @param n The number whose 1 bits are to be counted. * @return The number of 1 bits in the input number. */ static int number_of_bits_on(int n) { unsigned int count = 0; unsigned int n_bits = 8 * sizeof(int); unsigned int i; for (i = 0; i < n_bits; i++) { if (((unsigned int)n >> i) & 1) count++; } return count; }
23.854545
78
0.647104
b5f278057366f04d73cfe4ba6ca7f1d358304e0c
6,888
h
C
LeomaCore/Utils/LeomaSystem.h
humphrywang/LeomaFramework
b5ea04117627f41c79c804f4e4a2d75a5325529b
[ "Apache-2.0" ]
null
null
null
LeomaCore/Utils/LeomaSystem.h
humphrywang/LeomaFramework
b5ea04117627f41c79c804f4e4a2d75a5325529b
[ "Apache-2.0" ]
null
null
null
LeomaCore/Utils/LeomaSystem.h
humphrywang/LeomaFramework
b5ea04117627f41c79c804f4e4a2d75a5325529b
[ "Apache-2.0" ]
1
2018-03-03T15:47:28.000Z
2018-03-03T15:47:28.000Z
// // LeomaSystem.h // LeomaFramework // // Created by CorpDev on 14-3-21. // // 系统和app信息 /**buildIn Model Version与具体设备的对照关系 * iPhone1,1 iPhone 1G"; * iPhone1,2 iPhone 3G"; * iPhone2,1 iPhone 3GS"; * iPhone3,1 iPhone 4 * iPhone3,2 iPhone 4 * iPhone3,3 iPhone 4 * iPhone4,1 iPhone 4S * iPhone5,1 iPhone 5 * iPhone5,2 iPhone 5 (GSM+CDMA) * iPhone5,3 iPhone 5c (GSM) * iPhone5,4 iPhone 5c (GSM+CDMA) * iPhone6,1 iPhone 5s (GSM) * iPhone6,2 iPhone 5s (GSM+CDMA) * iPhone7,1 iPhone 6 Plus * iPhone7,2 iPhone 6 * iPhone8,1 iPhone 6s * iPhone8,2 iPhone 6s Plus * iPhone8,4 iPhone SE * iPhone9,1 国行、日版、港行iPhone 7 * iPhone9,2 港行、国行iPhone 7 Plus * iPhone9,3 美版、台版iPhone 7 * iPhone9,4 美版、台版iPhone 7 Plus * iPhone10,1 iPhone 8 * iPhone10,2 iPhone 8 Plus * iPhone11,1 iPhone X * * iPod1,1 iPod Touch 1G * iPod2,1 iPod Touch 2G * iPod3,1 iPod Touch 3G * iPod4,1 iPod Touch 4G * iPod5,1 iPod Touch (5 Gen) * iPad1,1 iPad * iPad1,2 iPad 3G * iPad2,1 iPad 2 (WiFi) * iPad2,2 iPad 2 * iPad2,3 iPad 2 (CDMA) * iPad2,4 iPad 2 * iPad2,5 iPad Mini (WiFi) * iPad2,6 iPad Mini * iPad2,7 iPad Mini (GSM+CDMA) * iPad3,1 iPad 3 (WiFi) * iPad3,2 iPad 3 (GSM+CDMA) * iPad3,3 iPad 3 * iPad3,4 iPad 4 (WiFi) * iPad3,5 iPad 4 * iPad3,6 iPad 4 (GSM+CDMA) * iPad4,1 iPad Air (WiFi) * iPad4,2 iPad Air (Cellular) * iPad4,4 iPad Mini 2 (WiFi) * iPad4,5 iPad Mini 2 (Cellular) * iPad4,6 iPad Mini 2 * iPad4,7 iPad Mini 3 * iPad4,8 iPad Mini 3 * iPad4,9 iPad Mini 3 * iPad5,1 iPad Mini 4 (WiFi) * iPad5,2 iPad Mini 4 (LTE) * iPad5,3 iPad Air 2 * iPad5,4 iPad Air 2 * iPad6,3 iPad Pro 9.7 * iPad6,4 iPad Pro 9.7 * iPad6,7 iPad Pro 12.9 * iPad6,8 iPad Pro 12.9 * * AppleTV2,1 Apple TV 2 * AppleTV3,1 Apple TV 3 * AppleTV3,2 Apple TV 3 * AppleTV5,3 Apple TV 4 * * i386 Simulator * x86_64 Simulator */ #ifndef LeomaSystem_h #define LeomaSystem_h #define Screen_Width [LeomaSystem screenBounds].size.width #define Screen_Height [LeomaSystem screenBounds].size.height #define Screen_Scale [UIScreen mainScreen].scale #define Platform_iPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define Platform_iPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IOS_6_OR_LATER ([[[UIDevice currentDevice] systemVersion] intValue] >= 6) #define IOS_7_OR_LATER ([[[UIDevice currentDevice] systemVersion] intValue] >= 7) #define IOS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] intValue] >= 8) #define IOS_9_OR_LATER ([[[UIDevice currentDevice] systemVersion] intValue] >= 9) #define IOS_10_OR_LATER ([[[UIDevice currentDevice] systemVersion] intValue] >= 10) #define IOS_11_OR_LATER ([[[UIDevice currentDevice] systemVersion] intValue] >= 11) #define IOS_6_OR_EARLIER ([[[UIDevice currentDevice] systemVersion] intValue] <= 6) #define IOS_7_OR_EARLIER ([[[UIDevice currentDevice] systemVersion] intValue] <= 7) #define IOS_8_OR_EARLIER ([[[UIDevice currentDevice] systemVersion] intValue] <= 8) #define IOS_9_OR_EARLIER ([[[UIDevice currentDevice] systemVersion] intValue] <= 9) #define IOS_10_OR_EARLIER ([[[UIDevice currentDevice] systemVersion] intValue] <= 10) #define IOS_11_OR_EARLIER ([[[UIDevice currentDevice] systemVersion] intValue] <= 11) #define IS_IOS_6 ([[[UIDevice currentDevice] systemVersion] intValue] == 6) #define IS_IOS_7 ([[[UIDevice currentDevice] systemVersion] intValue] == 7) #define IS_IOS_8 ([[[UIDevice currentDevice] systemVersion] intValue] == 8) #define IS_IOS_9 ([[[UIDevice currentDevice] systemVersion] intValue] == 9) #define IS_IOS_10 ([[[UIDevice currentDevice] systemVersion] intValue] == 10) #define IS_IOS_11 ([[[UIDevice currentDevice] systemVersion] intValue] == 11) #define Device_Is_Screen_Size(__width, __height) ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(__width, __height), [[UIScreen mainScreen] currentMode].size) : NO) #define Is_iPhone_4inch (Device_Is_Screen_Size(640, 1136))//iphone 5 #define Is_iPhone_Non_Retina (Device_Is_Screen_Size(320, 640))//iphone 4 & - #define Is_iPhone_Retina (Device_Is_Screen_Size(640, 960))//iphone 4s #define Is_iPhone_4_7inch (Device_Is_Screen_Size(750, 1334))//iphone 6 & 7 #define Is_iPhone_5_5inch (Device_Is_Screen_Size(1242, 2208)||Corp_Device_Is_Screen_Size(1125, 2001))//iphone XP 放大模式下分辨率为2001*1125// #define Is_iPhone_5_8inch (Device_Is_Screen_Size(1125, 2436))//iphone x #define Is_iPad_Non_Retina (Device_Is_Screen_Size(768, 1024)) #define Is_iPad_Retina (Device_Is_Screen_Size(1536, 2048)) #define Is_iPad_Pro (Device_Is_Screen_Size(2048, 2732))//iPad Pro #define IOS_JSCore IOS_7_OR_LATER//7.0开始支持JSCore #define IOS_ImmersiveStatusBar IOS_JSCore//7.0开始使用沉浸式状态栏 #define IOS_WebKit IOS_8_OR_LATER//8.0开始支持WKWebView #define IOS_FileRequest IOS_9_OR_LATER//9.0开始WKWebView支持加载本地文件夹中的文件 #define __High_Effect_Model if([LeomaSystem modelVersion] >= 5 + (Platform_iPhone ? 1 : 0)) #define __Low_Effect_Model if([LeomaSystem modelVersion] < 5 + (Platform_iPhone ? 1 : 0)) #define DECGeneric(name) +(Class)GenericClassOf##name; #define RELGeneric(name, clazz) +(Class)GenericClassOf##name { return clazz;} #endif @interface LeomaSystem : NSObject #pragma mark - system + (NSString *) macAddress API_DEPRECATED("iOS 7.0+ Deprecated", ios(7.0, 7.0)); + (NSString *) deviceUID; + (NSString *) systemVersion; + (NSString *) deviceModel; + (NSString *) machine; + (NSString *) modelDetail; + (float) modelVersion; + (NSString *) uniqueDeviceIdentifier; + (NSString *) uniqueGlobalDeviceIdentifier; + (NSString *) idfa; + (CGSize) screenSizeInPixel; + (CGRect) screenBounds; #pragma mark - app + (NSString *) appVersion; + (NSString *) appBuildVersion; + (NSString *) appIdentifier; + (NSString *) appURLScheme; + (NSString *) documentsDirectory; + (NSString *) documentsContentPath:(NSString *)virtulaPath; @end //GCD #define leoma_dispatch_once(block) {\ static dispatch_once_t onceToken;\ dispatch_once(&onceToken, block);\ } void leoma_dispatch_back(void(^block)()); void leoma_dispatch_main(void(^block)()); void leoma_dispatch_back_delay(void(^block)(), NSTimeInterval delay); void leoma_dispatch_main_delay(void(^block)(), NSTimeInterval delay);
39.136364
209
0.664199
db3f366adefb1885161bf527fce2bf0ec3560e83
1,764
h
C
include/sesstype/node/continue.h
pabble-lang/libsesstype
ca10bc19c0477538c9cb265746f971a00f6dd445
[ "MIT" ]
null
null
null
include/sesstype/node/continue.h
pabble-lang/libsesstype
ca10bc19c0477538c9cb265746f971a00f6dd445
[ "MIT" ]
null
null
null
include/sesstype/node/continue.h
pabble-lang/libsesstype
ca10bc19c0477538c9cb265746f971a00f6dd445
[ "MIT" ]
null
null
null
#ifndef SESSTYPE__NODE__CONTINUE_H__ #define SESSTYPE__NODE__CONTINUE_H__ #ifdef __cplusplus #include <string> #endif #include "sesstype/msg.h" #include "sesstype/role.h" #include "sesstype/node.h" #include "sesstype/node/block.h" #ifdef __cplusplus namespace sesstype { #endif #ifdef __cplusplus /** * \brief Continue statements. */ template <class BaseNode, class RoleType, class MessageType, class VisitorType> class ContinueNodeTmpl : public BaseNode { std::string label_; public: /// \brief ContinueNode constructor. /// \param[in] label of Choice Node. ContinueNodeTmpl(std::string label) : BaseNode(ST_NODE_CONTINUE), label_(label) { } /// \brief ContinueNode copy constructor. ContinueNodeTmpl(const ContinueNodeTmpl &node) : BaseNode(ST_NODE_CONTINUE), label_(node.label_) { } /// \brief clone a ContinueNode. ContinueNodeTmpl *clone() const override { return new ContinueNodeTmpl(*this); } /// \brief Repalce label of ContinueNode. /// \param[in] label of ContinueNode to replace with. void set_label(std::string label) { label_ = label; } /// \returns label of ContinueNode. std::string label() const { return label_; } void accept(VisitorType &v) override; }; using ContinueNode = ContinueNodeTmpl<Node, Role, MsgSig, util::NodeVisitor>; #endif // __cplusplus #ifdef __cplusplus extern "C" { #endif st_node *st_mk_continue_node(char *label); st_node *st_continue_node_set_label(st_node *node, char *label); const char *st_continue_node_get_label(st_node *node); #ifdef __cplusplus } // extern "C" #endif #ifdef __cplusplus } // namspace sesstype #endif #endif//SESSTYPE__NODE__CONTINUE_H__
21.777778
79
0.699546
80bf6631974543b1c01f3f46cb9fe07193923a8f
64
h
C
code/stc.h
LEEVINSEN/rfid
9a236d10a7bc66dc8ad91a7ef4224f946cacc148
[ "Apache-2.0" ]
null
null
null
code/stc.h
LEEVINSEN/rfid
9a236d10a7bc66dc8ad91a7ef4224f946cacc148
[ "Apache-2.0" ]
null
null
null
code/stc.h
LEEVINSEN/rfid
9a236d10a7bc66dc8ad91a7ef4224f946cacc148
[ "Apache-2.0" ]
null
null
null
#ifndef __stc_h__ #define __stc_h__ sfr P4 = 0xE8; #endif
10.666667
18
0.6875
84df26148ee06252a339c287811b0e94f0e0a9b5
186
h
C
iosdemo/iosdemo/ComponentCtl.h
wm20000/iosdemo
2bd928867ffa445bdba33fcb5675d988b45921d5
[ "Apache-2.0" ]
1
2015-12-16T13:58:22.000Z
2015-12-16T13:58:22.000Z
iosdemo/iosdemo/ComponentCtl.h
wm20000/iosdemo
2bd928867ffa445bdba33fcb5675d988b45921d5
[ "Apache-2.0" ]
null
null
null
iosdemo/iosdemo/ComponentCtl.h
wm20000/iosdemo
2bd928867ffa445bdba33fcb5675d988b45921d5
[ "Apache-2.0" ]
null
null
null
// // ComponentCtl.h // iosdemo // // Created by wangmo on 11/13/15. // Copyright © 2015 wmios. All rights reserved. // #import "MainCtl.h" @interface ComponentCtl : MainCtl @end
13.285714
48
0.66129
7ead77af91e7364681b715ff6d1710f7cf4b7665
417
h
C
FootNews/FootNews/Classes/Main/Tool/FTDataTool.h
one2shine/footballNews
a949189efb4302657d6bee3f01c5bc8f08bea816
[ "MIT" ]
null
null
null
FootNews/FootNews/Classes/Main/Tool/FTDataTool.h
one2shine/footballNews
a949189efb4302657d6bee3f01c5bc8f08bea816
[ "MIT" ]
null
null
null
FootNews/FootNews/Classes/Main/Tool/FTDataTool.h
one2shine/footballNews
a949189efb4302657d6bee3f01c5bc8f08bea816
[ "MIT" ]
null
null
null
// // FTDataTool.h // FootNews // // Created by mac on 16/3/7. // Copyright © 2016年 mac. All rights reserved. // #import <Foundation/Foundation.h> @class FTFootBallNews; @interface FTDataTool : NSObject + (void)saveNewsVideo:(FTFootBallNews *)newsVideo; + (NSArray *)collectionNewsVideoes; + (void)removeNewsFromDatabase:(FTFootBallNews *)newsVideo; + (BOOL)existNewsVideo:(FTFootBallNews *)newsVideo; @end
18.954545
59
0.731415
b4299a7f2e3a8d04d1eca706dc3267c70ef475fa
735
h
C
Engine/Monkey/Common/Common.h
BobLChen/VulkanDemos
78abfef10ff0138ed88c23ddfed4d98ce956e38e
[ "MIT" ]
596
2019-07-30T03:07:57.000Z
2022-03-31T07:45:20.000Z
Engine/Monkey/Common/Common.h
BobLChen/VulkanSamples
78abfef10ff0138ed88c23ddfed4d98ce956e38e
[ "MIT" ]
9
2019-07-28T08:48:41.000Z
2022-03-31T07:53:50.000Z
Engine/Monkey/Common/Common.h
BobLChen/VulkanSamples
78abfef10ff0138ed88c23ddfed4d98ce956e38e
[ "MIT" ]
79
2019-08-05T03:05:01.000Z
2022-03-31T07:45:22.000Z
#pragma once #include "Configuration/Platform.h" typedef unsigned char uint8; typedef unsigned short int uint16; typedef unsigned int uint32; typedef unsigned long long uint64; typedef signed char int8; typedef signed short int int16; typedef signed int int32; typedef signed long long int64; #ifdef _WIN64 typedef unsigned __int64 SIZE_T; typedef __int64 SSIZE_T; #else typedef unsigned long SIZE_T; typedef long SSIZE_T; #endif #define ENGINE_NAME "MONKEY" #if PLATFORM_WINDOWS #define FORCE_INLINE __inline #define CONSTEXPR constexpr #else #define FORCE_INLINE inline #define CONSTEXPR constexpr #endif
22.96875
37
0.678912
b443fd3306f7f036fe48cef20a5e268da4a0b281
1,514
c
C
c/hardsigmoid.c
erikedwards4/nn
c4b8317a38a72a16fd0bf905791b6c19e49c0aa7
[ "BSD-3-Clause" ]
1
2020-08-26T09:28:40.000Z
2020-08-26T09:28:40.000Z
c/hardsigmoid.c
erikedwards4/nn
c4b8317a38a72a16fd0bf905791b6c19e49c0aa7
[ "BSD-3-Clause" ]
null
null
null
c/hardsigmoid.c
erikedwards4/nn
c4b8317a38a72a16fd0bf905791b6c19e49c0aa7
[ "BSD-3-Clause" ]
null
null
null
//Gets the hardsigmoid function for each element in X. //For each element: y = 0, if x < -3 // y = 1, if x > +3 // y = (x+3)/6, otherwise #include <stdio.h> #ifdef __cplusplus namespace codee { extern "C" { #endif int hardsigmoid_s (float *Y, const float *X, const size_t N); int hardsigmoid_d (double *Y, const double *X, const size_t N); int hardsigmoid_inplace_s (float *X, const size_t N); int hardsigmoid_inplace_d (double *X, const size_t N); int hardsigmoid_s (float *Y, const float *X, const size_t N) { for (size_t n=N; n>0u; --n, ++X, ++Y) { if (*X>3.0f) { *Y = 1.0f; } else if (*X<-3.0f) { *Y = 0.0f; } else { *Y = (*X+3.0f)/6.0f; } } return 0; } int hardsigmoid_d (double *Y, const double *X, const size_t N) { for (size_t n=N; n>0u; --n, ++X, ++Y) { if (*X>3.0) { *Y = 1.0; } else if (*X<-3.0) { *Y = 0.0; } else { *Y = (*X+3.0)/6.0; } } return 0; } int hardsigmoid_inplace_s (float *X, const size_t N) { for (size_t n=N; n>0u; --n, ++X) { if (*X>3.0f) { *X = 1.0f; } else if (*X<-3.0f) { *X = 0.0f; } else { *X = (*X+3.0f)/6.0f; } } return 0; } int hardsigmoid_inplace_d (double *X, const size_t N) { for (size_t n=N; n>0u; --n, ++X) { if (*X>3.0) { *X = 1.0; } else if (*X<-3.0) { *X = 0.0; } else { *X = (*X+3.0)/6.0; } } return 0; } #ifdef __cplusplus } } #endif
19.921053
63
0.48745
f1e410b1d05d25c24445619444464c4715ebf14e
5,205
h
C
include/stc/cbox.h
clayne/STC
161622453ad44a29dc52f496c2d721d41255e45f
[ "MIT" ]
23
2020-08-17T07:58:50.000Z
2020-12-03T14:16:32.000Z
include/stc/cbox.h
clayne/STC
161622453ad44a29dc52f496c2d721d41255e45f
[ "MIT" ]
1
2020-11-26T10:44:29.000Z
2020-11-26T15:19:17.000Z
include/stc/cbox.h
clayne/STC
161622453ad44a29dc52f496c2d721d41255e45f
[ "MIT" ]
5
2020-08-17T07:59:03.000Z
2020-12-27T21:30:14.000Z
/* MIT License * * Copyright (c) 2022 Tyge Løvset, NORCE, www.norceresearch.no * * 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. */ /* cbox: heap allocated boxed type #include <stc/cstr.h> typedef struct { cstr name, email; } Person; Person Person_from(const char* name, const char* email) { return (Person){.name = cstr_from(name), .email = cstr_from(email)}; } Person Person_clone(Person p) { p.name = cstr_clone(p.name); p.email = cstr_clone(p.email); return p; } void Person_drop(Person* p) { printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->email)); c_drop(cstr, &p->name, &p->email); } #define i_key_bind Person // bind Person clone+drop fn's #define i_opt c_no_cmp // compare by .get addresses only #define i_type PBox #include <stc/cbox.h> int main() { c_auto (PBox, p, q) { p = PBox_make(Person_from("John Smiths", "josmiths@gmail.com")); q = PBox_clone(p); cstr_assign(&q.get->name, "Joe Smiths"); printf("%s %s.\n", cstr_str(&p.get->name), cstr_str(&p.get->email)); printf("%s %s.\n", cstr_str(&q.get->name), cstr_str(&q.get->email)); } } */ #include "ccommon.h" #ifndef CBOX_H_INCLUDED #define CBOX_H_INCLUDED #include "forward.h" #include <stdlib.h> #include <string.h> #define cbox_null {NULL} #endif // CBOX_H_INCLUDED #ifndef _i_prefix #define _i_prefix cbox_ #endif #include "template.h" typedef i_keyraw _cx_raw; #if !c_option(c_is_fwd) _cx_deftypes(_c_cbox_types, _cx_self, i_key); #endif // constructors (takes ownsership) STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; } STC_INLINE long _cx_memb(_use_count)(_cx_self box) { return (long)(box.get != NULL); } STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) { return c_make(_cx_self){p}; } // c++: std::make_unique<i_key>(val) STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { _cx_self ptr = {c_alloc(_cx_value)}; *ptr.get = val; return ptr; } STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) { return i_keyto(self->get); } STC_INLINE _cx_value _cx_memb(_toval)(const _cx_self* self) { return *self->get; } // destructor STC_INLINE void _cx_memb(_drop)(_cx_self* self) { if (self->get) { i_keydrop(self->get); c_free(self->get); } } STC_INLINE _cx_self _cx_memb(_move)(_cx_self* self) { _cx_self ptr = *self; self->get = NULL; return ptr; } STC_INLINE void _cx_memb(_reset)(_cx_self* self) { _cx_memb(_drop)(self); self->get = NULL; } // take ownership of p STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) { if (self->get) i_keydrop(self->get); self->get = p; } #if !defined _i_no_clone #if !defined _i_no_emplace STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw) { return _cx_memb(_make)(i_keyfrom(raw)); } #endif STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) { if (!other.get) return other; _cx_self out = {c_alloc(i_key)}; *out.get = i_keyclone(*other.get); return out; } STC_INLINE void _cx_memb(_copy)(_cx_self* self, _cx_self other) { if (self->get == other.get) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } #endif // !_i_no_clone STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self other) { if (other.get != self->get) _cx_memb(_drop)(self); *self = other; } STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) { #if c_option(c_no_cmp) return c_default_hash(&x); #else _cx_raw rx = i_keyto(x); return i_hash((&rx)); #endif } STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { #if c_option(c_no_cmp) return c_default_cmp(&x, &y); #else _cx_raw rx = i_keyto(x), ry = i_keyto(y); return i_cmp((&rx), (&ry)); #endif } STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { #if c_option(c_no_cmp) return x == y; #else _cx_raw rx = i_keyto(x), ry = i_keyto(y); return i_eq((&rx), (&ry)); #endif } #include "template.h"
28.442623
81
0.669741
e0b173bd94001a5580c2237323a3f97de8adc425
522
h
C
PrivateFrameworks/CloudPhotoLibrary/CPLBucketFileStorageItem.h
phatblat/macOSPrivateFrameworks
9047371eb80f925642c8a7c4f1e00095aec66044
[ "MIT" ]
17
2018-11-13T04:02:58.000Z
2022-01-20T09:27:13.000Z
PrivateFrameworks/CloudPhotoLibrary/CPLBucketFileStorageItem.h
phatblat/macOSPrivateFrameworks
9047371eb80f925642c8a7c4f1e00095aec66044
[ "MIT" ]
3
2018-04-06T02:02:27.000Z
2018-10-02T01:12:10.000Z
PrivateFrameworks/CloudPhotoLibrary/CPLBucketFileStorageItem.h
phatblat/macOSPrivateFrameworks
9047371eb80f925642c8a7c4f1e00095aec66044
[ "MIT" ]
1
2018-09-28T13:54:23.000Z
2018-09-28T13:54:23.000Z
// // Generated by class-dump 3.5 (64 bit). // // class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard. // #import <CloudPhotoLibrary/CPLFileStorageItem.h> @class NSURL; @interface CPLBucketFileStorageItem : CPLFileStorageItem { NSURL *_url; BOOL _attributesAreCached; BOOL _cachedOriginal; BOOL _cachedMarkedForDelete; } - (void).cxx_destruct; - (BOOL)isMarkedForDelete; - (BOOL)isOriginal; - (void)_cacheAttributes; - (id)initWithIdentity:(id)arg1 url:(id)arg2; @end
19.333333
83
0.714559
7d44933ea77aba1cc2ccc92c186a1e6d810be3d1
668
c
C
lib/posixcompat/setrlimit.c
lambdaxymox/barrelfish
06a9f54721a8d96874a8939d8973178a562c342f
[ "MIT" ]
111
2015-02-03T02:57:27.000Z
2022-03-01T23:57:09.000Z
lib/posixcompat/setrlimit.c
lambdaxymox/barrelfish
06a9f54721a8d96874a8939d8973178a562c342f
[ "MIT" ]
12
2016-03-22T14:44:32.000Z
2020-03-18T13:30:29.000Z
lib/posixcompat/setrlimit.c
lambdaxymox/barrelfish
06a9f54721a8d96874a8939d8973178a562c342f
[ "MIT" ]
55
2015-02-03T05:28:12.000Z
2022-03-31T05:00:03.000Z
#include <sys/resource.h> #include <assert.h> #include <string.h> #include "posixcompat.h" int setrlimit(int resource, const struct rlimit *rlim) { POSIXCOMPAT_DEBUG("setrlimit(%d, %p) ignored.\n", resource, rlim); return 0; } int getrlimit(int resource, struct rlimit *rlim) { static struct rlimit infty = { .rlim_cur = RLIM_INFINITY, .rlim_max = RLIM_INFINITY, }; POSIXCOMPAT_DEBUG("getrlimit(%d, %p) always returns infinity.\n", resource, rlim); *rlim = infty; return 0; } int getrusage(int who, struct rusage *usage) { // XXX: No fields are supported memset(usage, 0, sizeof(struct rusage)); return 0; }
22.266667
86
0.661677
9a126b9e2d7c99d261f91a1ac616d5dece962a1b
185
h
C
arch/arm64/include/asm/kvm_types.h
jainsakshi2395/linux
7ccb860232bb83fb60cd6bcf5aaf0c008d903acb
[ "Linux-OpenIB" ]
44
2022-03-16T08:32:31.000Z
2022-03-31T16:02:35.000Z
arch/arm64/include/asm/kvm_types.h
jainsakshi2395/linux
7ccb860232bb83fb60cd6bcf5aaf0c008d903acb
[ "Linux-OpenIB" ]
13
2021-07-10T04:36:17.000Z
2022-03-03T10:50:05.000Z
arch/arm64/include/asm/kvm_types.h
jainsakshi2395/linux
7ccb860232bb83fb60cd6bcf5aaf0c008d903acb
[ "Linux-OpenIB" ]
18
2022-03-19T04:41:04.000Z
2022-03-31T03:32:12.000Z
/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _ASM_ARM64_KVM_TYPES_H #define _ASM_ARM64_KVM_TYPES_H #define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 #endif /* _ASM_ARM64_KVM_TYPES_H */
20.555556
44
0.810811
ccb3678bee042d19ea8d246457bfc30aafe58d6d
473
h
C
hazel/coreten/memory/Storage.h
jasmcaus/adorad
949aba02c85863544d3ded85bc52d31716650f2b
[ "MIT" ]
25
2020-12-17T12:50:04.000Z
2021-02-23T03:03:39.000Z
hazel/coreten/memory/Storage.h
jasmcaus/hazel
949aba02c85863544d3ded85bc52d31716650f2b
[ "MIT" ]
null
null
null
hazel/coreten/memory/Storage.h
jasmcaus/hazel
949aba02c85863544d3ded85bc52d31716650f2b
[ "MIT" ]
30
2020-12-31T13:31:56.000Z
2021-01-31T07:12:24.000Z
#include <coreten/memory/intrusive_ptr.h> // The Storage class holds the intrusive pointer to the actual Storage of coreten::Tensor // One or more tensors may point to the same underlying storage (and thus we ensure that if one tensor is // destroyed, the other tensors will still be able to point to the storage (for this reason, we employ reference // counting class Storage { private: intrusive_ptr __data; // Holds the actual data };
31.533333
113
0.718816
f2de45b4b95a26dbc1abe116c678f74ee5e34e45
348
h
C
Smart_power_outlet/SPO_v1.0.0/global.h
YordanYordanovGIT/Smart-power-socket
a52ef6ea75624d320cabfa3744903c12074535bd
[ "MIT" ]
null
null
null
Smart_power_outlet/SPO_v1.0.0/global.h
YordanYordanovGIT/Smart-power-socket
a52ef6ea75624d320cabfa3744903c12074535bd
[ "MIT" ]
null
null
null
Smart_power_outlet/SPO_v1.0.0/global.h
YordanYordanovGIT/Smart-power-socket
a52ef6ea75624d320cabfa3744903c12074535bd
[ "MIT" ]
null
null
null
#ifndef global_h #define global_h #include "WiFimy.h" #include "Externalmy.h" #include "HTTPmy.h" #include "EEPROMmy.h" #include "MQTTmy.h" //#define MQTT_ON class global { private: public: WiFimy wifi; HTTPmy http; Externalmy ext; EEPROMmy mem; #ifdef MQTT_ON MQTTmy mqtt; #endif void init(); }; #endif
13.384615
23
0.646552
2ba2d3986c72a1eba63c39fa3d70585208361ad6
7,038
h
C
soap4/dependencies.h
HKU-BAL/MegaPath
b81796024f864af5fd44deb5812f34704c570160
[ "BSD-3-Clause" ]
6
2021-10-06T07:47:04.000Z
2022-01-25T05:09:08.000Z
soap4/dependencies.h
edwwlui/MegaPath
b81796024f864af5fd44deb5812f34704c570160
[ "BSD-3-Clause" ]
null
null
null
soap4/dependencies.h
edwwlui/MegaPath
b81796024f864af5fd44deb5812f34704c570160
[ "BSD-3-Clause" ]
null
null
null
/* * * dependencies.h * Soap3(gpu) * * Copyright (C) 2011, HKU * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifndef __DEPENDENCIES_H__ #define __DEPENDENCIES_H__ // #define BGS_OUTPUT_KERNEL_DEBUG_MESSAGE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "2bwt-flex/OCC.h" #include "2bwt-flex/SRAArguments.h" #include "PEAlgnmt.h" #include "AlgnResult.h" #include "definitions.h" static void getSeedPositions ( int stage, int readLength, int * seedLength, int * seedPositions, int * seedNum ) { if ( stage == STAGE_SINGLE_DP || stage == STAGE_NEW_DEFAULT_DP ) { if ( readLength > 300 ) { ( *seedLength ) = SEED_LEN_SINGLE_DP_FOR_V_LONG_READ; } else if ( readLength > 80 ) { ( *seedLength ) = SEED_LEN_SINGLE_DP_FOR_LONG_READ; } else if ( readLength > 60 ) { ( *seedLength ) = SEED_LEN_SINGLE_DP_FOR_MEDIAN_READ; } else if ( readLength > 40 ) { ( *seedLength ) = SEED_LEN_SINGLE_DP_FOR_SHORT_READ; } else { ( *seedLength ) = SEED_LEN_SINGLE_DP_FOR_V_SHORT_READ; } // update: for reads longer than 120, one more seed for every extra 100 bases if ( readLength > 120 ) { ( *seedNum ) = SEED_NUM_SINGLE_DP + readLength / 100; } else { ( *seedNum ) = SEED_NUM_SINGLE_DP; } int H = 0; if ( readLength > 300 ) { H = readLength * 0.15; } int X; if ( readLength > 300 ) { X = readLength * 0.15; } else if ( readLength > 80 ) { X = TAIL_TRIM_SEEDING_SINGLE_DP_FOR_LONG_READ; } else if ( readLength > 60 ) { X = TAIL_TRIM_SEEDING_SINGLE_DP_FOR_MEDIAN_READ; } else if ( readLength > 40 ) { X = TAIL_TRIM_SEEDING_SINGLE_DP_FOR_SHORT_READ; } else { X = TAIL_TRIM_SEEDING_SINGLE_DP_FOR_V_SHORT_READ; } int seed_apart = ( readLength - X - H ) / ( *seedNum ); int i; for ( i = 0; i < ( *seedNum ); i++ ) { seedPositions[i] = H + i * seed_apart; } if ( seedPositions[ ( *seedNum ) - 1] > readLength - ( *seedLength ) - X ) { seedPositions[ ( *seedNum ) - 1] = readLength - ( *seedLength ) - X; } } else if ( stage == STAGE_DEEP_DP_ROUND1 ) { (*seedNum) = NUMBER_OF_SEED; (*seedLength) = HALF_SEED_SIZE_FOR_V_LONG_READ_UB * 2; seedPositions[0] = SEED_POS_DEEP_DP_FOR_V_LONG_READ_1; seedPositions[1] = SEED_POS_DEEP_DP_FOR_V_LONG_READ_2; seedPositions[2] = SEED_POS_DEEP_DP_FOR_V_LONG_READ_3; seedPositions[3] = SEED_POS_DEEP_DP_FOR_V_LONG_READ_4; seedPositions[4] = SEED_POS_DEEP_DP_FOR_V_LONG_READ_5; seedPositions[5] = SEED_POS_DEEP_DP_FOR_V_LONG_READ_6; // seedPositions[1]=40; } else if ( stage == STAGE_DEEP_DP_ROUND2A ) { /* int seed_size_lb, seed_size_ub; if ( readLength > 150 ) { seed_size_lb = HALF_SEED_SIZE_FOR_V_LONG_READ_LB; seed_size_ub = HALF_SEED_SIZE_FOR_V_LONG_READ_UB; ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_V_LONG_READ; } else if ( readLength > 80 ) { seed_size_lb = HALF_SEED_SIZE_FOR_LONG_READ_LB; seed_size_ub = HALF_SEED_SIZE_FOR_LONG_READ_UB; ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_LONG_READ; } int idx = static_cast <int> (floor( (readLength-1) / seed_size_lb )) - 1; int * pos = (int *)malloc( idx * sizeof( idx ) ); pos[idx-1] = readLength - ( *seedLength ) + ( seed_size_ub - seed_size_lb ); int i; for ( i=idx-1 ; i>0 ;--i) pos[i-1] = pos[i]-seed_size_lb; ( *seedNum ) = 0; // seedPositions[ (*seedNum)++ ] = pos[1]; for ( i=0; i<idx; i+=2, ++ (*seedNum) ) seedPositions[( *seedNum ) ] = pos[i]; if ( seedPositions[0] < 0 ) seedPositions[0] = 0; */ /* if ( readLength > 150 ) { ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_V_LONG_READ_2; } else if ( readLength > 80 ) { ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_LONG_READ_2; } else if ( readLength > 60 ) { ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_MEDIAN_READ_2; } else if ( readLength > 40 ) { ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_SHORT_READ_2; } else { ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_V_SHORT_READ_2; } int H = 0; int T = 0; if ( readLength > 150 ) { H = readLength * 0.1; T = readLength * 0.2; } ( *seedNum ) = 0; for ( int i = readLength - ( *seedLength ) - T; i >= H; i -= ( *seedLength ) / 2 ) { seedPositions[ ( *seedNum ) ++] = i; } if ( seedPositions[ ( *seedNum ) - 1] > H ) { seedPositions[ ( *seedNum ) ++] = H; } */ } else if ( stage == STAGE_DEEP_DP_ROUND2B ) { int seed_size_lb, seed_size_ub; if ( readLength > 150 ) { seed_size_lb = HALF_SEED_SIZE_FOR_V_LONG_READ_LB; seed_size_ub = HALF_SEED_SIZE_FOR_V_LONG_READ_UB; ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_V_LONG_READ; } else if ( readLength > 80 ) { seed_size_lb = HALF_SEED_SIZE_FOR_LONG_READ_LB; seed_size_ub = HALF_SEED_SIZE_FOR_LONG_READ_UB; ( *seedLength ) = SEED_LEN_DEEP_DP_FOR_LONG_READ; } int idx = static_cast <int> (floor( (readLength-1) / seed_size_lb )) - 1; int * pos = (int *)malloc( idx * sizeof( idx ) ); pos[idx-1] = readLength - ( seed_size_lb * 2 ) - ( seed_size_ub - seed_size_lb ); int i; for ( i=idx-1 ; i>0 ;--i) pos[i-1] = pos[i]-seed_size_lb; ( *seedNum ) = 0; // seedPositions[ (*seedNum)++ ] = pos[1]; for ( i=0; i<idx; i+=2, ++ (*seedNum) ) seedPositions[( *seedNum ) ] = pos[i]; if ( seedPositions[0] < 0 ) seedPositions[0] = 0; } } static unsigned int getWordPerQuery ( unsigned int maxReadLength ) { return (maxReadLength + CHAR_PER_WORD - 1) / CHAR_PER_WORD; } #endif
33.514286
112
0.575874
92061a0458902d19ba40b7abe96d05977f833309
13,370
h
C
src/js/frontend/SwitchEmitter.h
fengjixuchui/blazefox
d5c732ac7305a79fe20704c2d134c130f14eca83
[ "MIT" ]
149
2018-12-23T09:08:00.000Z
2022-02-02T09:18:38.000Z
src/js/frontend/SwitchEmitter.h
fengjixuchui/blazefox
d5c732ac7305a79fe20704c2d134c130f14eca83
[ "MIT" ]
null
null
null
src/js/frontend/SwitchEmitter.h
fengjixuchui/blazefox
d5c732ac7305a79fe20704c2d134c130f14eca83
[ "MIT" ]
56
2018-12-23T18:11:40.000Z
2021-11-30T13:18:17.000Z
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: set ts=8 sts=4 et sw=4 tw=99: * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef frontend_SwitchEmitter_h #define frontend_SwitchEmitter_h #include "mozilla/Attributes.h" #include "mozilla/Maybe.h" #include <stddef.h> #include <stdint.h> #include "frontend/BytecodeControlStructures.h" #include "frontend/EmitterScope.h" #include "frontend/JumpList.h" #include "frontend/TDZCheckCache.h" #include "gc/Rooting.h" #include "js/AllocPolicy.h" #include "js/Value.h" #include "js/Vector.h" #include "vm/Scope.h" namespace js { namespace frontend { struct BytecodeEmitter; // Class for emitting bytecode for switch-case-default block. // // Usage: (check for the return value is omitted for simplicity) // // `switch (discriminant) { case c1_expr: c1_body; }` // SwitchEmitter se(this); // se.emitDiscriminant(Some(offset_of_switch)); // emit(discriminant); // // se.validateCaseCount(1); // se.emitCond(); // // emit(c1_expr); // se.emitCaseJump(); // // se.emitCaseBody(); // emit(c1_body); // // se.emitEnd(); // // `switch (discriminant) { case c1_expr: c1_body; case c2_expr: c2_body; // default: def_body; }` // SwitchEmitter se(this); // se.emitDiscriminant(Some(offset_of_switch)); // emit(discriminant); // // se.validateCaseCount(2); // se.emitCond(); // // emit(c1_expr); // se.emitCaseJump(); // // emit(c2_expr); // se.emitCaseJump(); // // se.emitCaseBody(); // emit(c1_body); // // se.emitCaseBody(); // emit(c2_body); // // se.emitDefaultBody(); // emit(def_body); // // se.emitEnd(); // // `switch (discriminant) { case c1_expr: c1_body; case c2_expr: c2_body; }` // with Table Switch // SwitchEmitter::TableGenerator tableGen(this); // tableGen.addNumber(c1_expr_value); // tableGen.addNumber(c2_expr_value); // tableGen.finish(2); // // // If `!tableGen.isValid()` here, `emitCond` should be used instead. // // SwitchEmitter se(this); // se.emitDiscriminant(Some(offset_of_switch)); // emit(discriminant); // se.validateCaseCount(2); // se.emitTable(tableGen); // // se.emitCaseBody(c1_expr_value, tableGen); // emit(c1_body); // // se.emitCaseBody(c2_expr_value, tableGen); // emit(c2_body); // // se.emitEnd(); // // `switch (discriminant) { case c1_expr: c1_body; case c2_expr: c2_body; // default: def_body; }` // with Table Switch // SwitchEmitter::TableGenerator tableGen(bce); // tableGen.addNumber(c1_expr_value); // tableGen.addNumber(c2_expr_value); // tableGen.finish(2); // // // If `!tableGen.isValid()` here, `emitCond` should be used instead. // // SwitchEmitter se(this); // se.emitDiscriminant(Some(offset_of_switch)); // emit(discriminant); // se.validateCaseCount(2); // se.emitTable(tableGen); // // se.emitCaseBody(c1_expr_value, tableGen); // emit(c1_body); // // se.emitCaseBody(c2_expr_value, tableGen); // emit(c2_body); // // se.emitDefaultBody(); // emit(def_body); // // se.emitEnd(); // // `switch (discriminant) { case c1_expr: c1_body; }` // in case c1_body contains lexical bindings // SwitchEmitter se(this); // se.emitDiscriminant(Some(offset_of_switch)); // emit(discriminant); // // se.validateCaseCount(1); // // se.emitLexical(bindings); // // se.emitCond(); // // emit(c1_expr); // se.emitCaseJump(); // // se.emitCaseBody(); // emit(c1_body); // // se.emitEnd(); // // `switch (discriminant) { case c1_expr: c1_body; }` // in case c1_body contains hosted functions // SwitchEmitter se(this); // se.emitDiscriminant(Some(offset_of_switch)); // emit(discriminant); // // se.validateCaseCount(1); // // se.emitLexical(bindings); // emit(hosted functions); // // se.emitCond(); // // emit(c1_expr); // se.emitCaseJump(); // // se.emitCaseBody(); // emit(c1_body); // // se.emitEnd(); // class MOZ_STACK_CLASS SwitchEmitter { // Bytecode for each case. // // Cond Switch // {discriminant} // JSOP_CONDSWITCH // // {c1_expr} // JSOP_CASE c1 // // JSOP_JUMPTARGET // {c2_expr} // JSOP_CASE c2 // // ... // // JSOP_JUMPTARGET // JSOP_DEFAULT default // // c1: // JSOP_JUMPTARGET // {c1_body} // JSOP_GOTO end // // c2: // JSOP_JUMPTARGET // {c2_body} // JSOP_GOTO end // // default: // end: // JSOP_JUMPTARGET // // Table Switch // {discriminant} // JSOP_TABLESWITCH c1, c2, ... // // c1: // JSOP_JUMPTARGET // {c1_body} // JSOP_GOTO end // // c2: // JSOP_JUMPTARGET // {c2_body} // JSOP_GOTO end // // ... // // end: // JSOP_JUMPTARGET public: enum class Kind { Table, Cond }; // Class for generating optimized table switch data. class MOZ_STACK_CLASS TableGenerator { BytecodeEmitter* bce_; // Bit array for given numbers. mozilla::Maybe<js::Vector<size_t, 128, SystemAllocPolicy>> intmap_; // The length of the intmap_. int32_t intmapBitLength_ = 0; // The length of the table. uint32_t tableLength_ = 0; // The lower and higher bounds of the table. int32_t low_ = JSVAL_INT_MAX, high_ = JSVAL_INT_MIN; // Whether the table is still valid. bool valid_= true; #ifdef DEBUG bool finished_ = false; #endif public: explicit TableGenerator(BytecodeEmitter* bce) : bce_(bce) {} void setInvalid() { valid_ = false; } MOZ_MUST_USE bool isValid() const { return valid_; } MOZ_MUST_USE bool isInvalid() const { return !valid_; } // Add the given number to the table. The number is the value of // `expr` for `case expr:` syntax. MOZ_MUST_USE bool addNumber(int32_t caseValue); // Finish generating the table. // `caseCount` should be the number of cases in the switch statement, // excluding the default case. void finish(uint32_t caseCount); private: friend SwitchEmitter; // The following methods can be used only after calling `finish`. // Returns the lower bound of the added numbers. int32_t low() const { MOZ_ASSERT(finished_); return low_; } // Returns the higher bound of the numbers. int32_t high() const { MOZ_ASSERT(finished_); return high_; } // Returns the index in SwitchEmitter.caseOffsets_ for table switch. uint32_t toCaseIndex(int32_t caseValue) const; // Returns the length of the table. // This method can be called only if `isValid()` is true. uint32_t tableLength() const; }; private: BytecodeEmitter* bce_; // `kind_` should be set to the correct value in emitCond/emitTable. Kind kind_ = Kind::Cond; // True if there's explicit default case. bool hasDefault_ = false; // The source note index for SRC_CONDSWITCH. unsigned noteIndex_ = 0; // Source note index of the previous SRC_NEXTCASE. unsigned caseNoteIndex_ = 0; // The number of cases in the switch statement, excluding the default case. uint32_t caseCount_ = 0; // Internal index for case jump and case body, used by cond switch. uint32_t caseIndex_ = 0; // Bytecode offset after emitting `discriminant`. ptrdiff_t top_ = 0; // Bytecode offset of the previous JSOP_CASE. ptrdiff_t lastCaseOffset_ = 0; // Bytecode offset of the JSOP_JUMPTARGET for default body. JumpTarget defaultJumpTargetOffset_ = { -1 }; // Bytecode offset of the JSOP_DEFAULT. JumpList condSwitchDefaultOffset_; // Instantiated when there's lexical scope for entire switch. mozilla::Maybe<TDZCheckCache> tdzCacheLexical_; mozilla::Maybe<EmitterScope> emitterScope_; // Instantiated while emitting case expression and case/default body. mozilla::Maybe<TDZCheckCache> tdzCacheCaseAndBody_; // Control for switch. mozilla::Maybe<BreakableControl> controlInfo_; mozilla::Maybe<uint32_t> switchPos_; // Cond Switch: // Offset of each JSOP_CASE. // Table Switch: // Offset of each JSOP_JUMPTARGET for case. js::Vector<ptrdiff_t, 32, SystemAllocPolicy> caseOffsets_; // The state of this emitter. // // +-------+ emitDiscriminant +--------------+ // | Start |----------------->| Discriminant |-+ // +-------+ +--------------+ | // | // +-------------------------------------------+ // | // | validateCaseCount +-----------+ // +->+------------------------>+------------------>| CaseCount |-+ // | ^ +-----------+ | // | emitLexical +---------+ | | // +------------>| Lexical |-+ | // +---------+ | // | // +--------------------------------------------------------------+ // | // | emitTable +-------+ // +---------->| Table |---------------------------->+-+ // | +-------+ ^ | // | | | // | emitCond +------+ | | // +---------->| Cond |-+------------------------>+->+ | // +------+ | ^ | // | | | // | emitCase +------+ | | // +->+--------->| Case |->+-+ | // ^ +------+ | | // | | | // +--------------------+ | // | // +---------------------------------------------------+ // | // | emitEnd +-----+ // +-+----------------------------------------->+-------->| End | // | ^ +-----+ // | emitCaseBody +----------+ | // +->+-+---------------->| CaseBody |--->+-+-+ // ^ | +----------+ ^ | // | | | | // | | emitDefaultBody +-------------+ | | // | +---------------->| DefaultBody |-+ | // | +-------------+ | // | | // +-------------------------------------+ // enum class State { // The initial state. Start, // After calling emitDiscriminant. Discriminant, // After calling validateCaseCount. CaseCount, // After calling emitLexical. Lexical, // After calling emitCond. Cond, // After calling emitTable. Table, // After calling emitCase. Case, // After calling emitCaseBody. CaseBody, // After calling emitDefaultBody. DefaultBody, // After calling emitEnd. End }; State state_ = State::Start; public: explicit SwitchEmitter(BytecodeEmitter* bce); // `switchPos` is the offset in the source code for the character below: // // switch ( cond ) { ... } // ^ // | // switchPos // // Can be Nothing() if not available. MOZ_MUST_USE bool emitDiscriminant(const mozilla::Maybe<uint32_t>& switchPos); // `caseCount` should be the number of cases in the switch statement, // excluding the default case. MOZ_MUST_USE bool validateCaseCount(uint32_t caseCount); // `bindings` is a lexical scope for the entire switch, in case there's // let/const effectively directly under case or default blocks. MOZ_MUST_USE bool emitLexical(Handle<LexicalScope::Data*> bindings); MOZ_MUST_USE bool emitCond(); MOZ_MUST_USE bool emitTable(const TableGenerator& tableGen); MOZ_MUST_USE bool emitCaseJump(); MOZ_MUST_USE bool emitCaseBody(); MOZ_MUST_USE bool emitCaseBody(int32_t caseValue, const TableGenerator& tableGen); MOZ_MUST_USE bool emitDefaultBody(); MOZ_MUST_USE bool emitEnd(); private: MOZ_MUST_USE bool emitCaseOrDefaultJump(uint32_t caseIndex, bool isDefault); MOZ_MUST_USE bool emitImplicitDefault(); }; } /* namespace frontend */ } /* namespace js */ #endif /* frontend_SwitchEmitter_h */
28.446809
86
0.514061
922c1cefa127c71523e5a0498edacfae5e10ceeb
2,183
h
C
microcontroller/src/silvia_display.h
willhunt/silviabot
c7800f88b8776f608bd1832d2449f714cce96887
[ "MIT" ]
1
2020-12-03T20:29:27.000Z
2020-12-03T20:29:27.000Z
microcontroller/src/silvia_display.h
willhunt/silviabot
c7800f88b8776f608bd1832d2449f714cce96887
[ "MIT" ]
null
null
null
microcontroller/src/silvia_display.h
willhunt/silviabot
c7800f88b8776f608bd1832d2449f714cce96887
[ "MIT" ]
null
null
null
#ifndef SILVIA_DISPLAY_H #define SILVIA_DISPLAY_H #include <Arduino.h> #include <Wire.h> #include <Adafruit_SSD1306.h> #include <Adafruit_GFX.h> #include <ros.h> #include <django_interface/SilviaController.h> #include <django_interface/SilviaStatus.h> #include <django_interface/SilviaBrewTimer.h> #include <django_interface/SilviaCleaner.h> #include <django_interface/SilviaMass.h> #include "silvia_logo.h" #include "silvia_state.h" #include "silvia_sensors.h" #include "silvia_controllers.h" #include "silvia_clean.h" #include "silvia_timer.h" #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define SCREEN_PADDING 4 // Edge padding #define UPDATE_INTERVAL 1000 // Update/refresh interval #define WELCOME_INTERVAL 2000 // Display welcome #define ACCEPTABLE_DATA_AGE 2000 // Interval over which to display "old" data extern SilviaStatus silvia_status; extern TemperatureSensor temperature_sensor; extern PressureSensor pressure_sensor; extern TemperatureController heater; extern PressureController pump; extern PressureSensor pressure_sensor; extern BrewTimer brew_timer; class SilviaDisplay : public Adafruit_SSD1306 { private: NodeHandle* nh_; ros::Subscriber<django_interface::SilviaMass, SilviaDisplay> mass_subscriber_; unsigned long t_power_on_; // Time machine was last turned on bool power_status_last_update_; // Power status recorded last update unsigned long t_last_update_; double mass_; unsigned long t_mass_update_; // Mass update is coming externally so need to flag if data is old void drawCentreString(const char *buffer, int x, int y); void formatPressureString(char* buffer, double pressure); void drawPressureString(char* buffer, double pressure, int x, int y, int size); void massCallback(const django_interface::SilviaMass& msg); public: SilviaDisplay(TwoWire* wire); void setup(NodeHandle* nh); void showData(); void showLogo(); void showBlank(); void update(); void showDebug(char* text); }; #endif // SILVIA_DISPLAY_H
35.209677
105
0.746221
4dee4282a87f01fd8c3f761af3c688bd83ceb380
15,829
h
C
recipes-kernel/tmk1553b-mod/files/tmknll.h
pohmelie/meta-cpc304
10ac23640cda40238fab2e87089148e7937ee7f3
[ "MIT" ]
null
null
null
recipes-kernel/tmk1553b-mod/files/tmknll.h
pohmelie/meta-cpc304
10ac23640cda40238fab2e87089148e7937ee7f3
[ "MIT" ]
null
null
null
recipes-kernel/tmk1553b-mod/files/tmknll.h
pohmelie/meta-cpc304
10ac23640cda40238fab2e87089148e7937ee7f3
[ "MIT" ]
1
2018-07-02T06:00:18.000Z
2018-07-02T06:00:18.000Z
/****************************************************************************/ /* TMKNLL.H v7.06. ELCUS, 1995,2011 */ /* Interface to the driver TMKNLL v7.06. */ /****************************************************************************/ #ifndef _TMKNLLX_ #define _TMKNLLX_ typedef unsigned char U08; #if defined(DOS) && !defined(DOS32) typedef unsigned U16; #else typedef unsigned short U16; #endif typedef unsigned long U32; #ifndef RETIR #define RETIR void #endif #ifndef TYPIR #define TYPIR interrupt #endif #define TMK_INT_SAVED 0x0001 #define TMK_INT_MORE 0x8000 #define TMK_INT_DRV_OVF 0x0002 #define TMK_INT_OTHER 0x7FF4 //#define TMK_INT_TIMER //#define TMK_INT_BUSJAM //#define TMK_INT_FIFO_OVF //#define TMK_INT_GEN1 //#define TMK_INT_GEN2 #define MIN_TMK_TYPE 2 #define MAX_TMK_TYPE 12 #define RTMK 0 #define RTMK1 1 #define TMK400 2 #define TMKMPC 3 #define RTMK400 4 #define TMKX 5 #define TMKXI 6 #define MRTX 7 #define MRTXI 8 #define TA 9 #define TAI 10 #define MRTA 11 #define MRTAI 12 #define ALL_TMKS 0x00FF #ifdef NMBCID #define MBC_ALLOC_FAIL 0xFFFF #endif #define GET_TIMEOUT 0xFFFF #define SWTIMER_OFF 0x0000 #define SWTIMER_ON 0x2400 #define SWTIMER_EVENT 0x8000 #define SWTIMER_RESET 0xFBFF #define GET_SWTIMER_CTRL 0xFFFF #define TIMER_RESET 0xFBFF #define TIMER_OFF 0x0000 #define TIMER_16BIT 0x3400 #define TIMER_32BIT 0x2400 #define TIMER_1US 0x0000 #define TIMER_2US 0x0080 #define TIMER_4US 0x0100 #define TIMER_8US 0x0180 #define TIMER_16US 0x0200 #define TIMER_32US 0x0280 #define TIMER_64US 0x0300 #define TIMER_STOP 0x0380 #define TIMER_SYN 0x0040 #define TIMER_SYND 0x0020 #define TIMER_SA 0x001F #define TIMER_NOSTOP 0x2000 #define TIMER_MASK 0x37FF #define TIMER_STEP 0x0380 #define TIMER_BITS 0x3400 #define GET_TIMER_CTRL 0xFFFF #define DATA_BC_RT 0x00 #define DATA_BC_RT_BRCST 0x08 #define DATA_RT_BC 0x01 #define DATA_RT_RT 0x02 #define DATA_RT_RT_BRCST 0x0A #define CTRL_C_A 0x03 #define CTRL_C_BRCST 0x0B #define CTRL_CD_A 0x04 #define CTRL_CD_BRCST 0x0C #define CTRL_C_AD 0x05 #define CC_FMT_1 0x00 #define CC_FMT_2 0x01 #define CC_FMT_3 0x02 #define CC_FMT_4 0x03 #define CC_FMT_5 0x05 #define CC_FMT_6 0x04 #define CC_FMT_7 0x08 #define CC_FMT_8 0x0A #define CC_FMT_9 0x0B #define CC_FMT_10 0x0C #define BUS_A 0 #define BUS_B 1 #define BUS_1 0 #define BUS_2 1 #define ERAO_MASK 0x0001 #define MEO_MASK 0x0002 #define IB_MASK 0x0004 #define TO_MASK 0x0008 #define EM_MASK 0x0010 #define EBC_MASK 0x0020 #define DI_MASK 0x0040 #define ELN_MASK 0x0080 #define G1_MASK 0x1000 #define G2_MASK 0x2000 #define S_ERAO_MASK 0x0001 #define S_MEO_MASK 0x0002 #define S_IB_MASK 0x0004 #define S_TO_MASK 0x0008 #define S_EM_MASK 0x0010 #define S_EBC_MASK 0x0020 #define S_DI_MASK 0x0040 #define S_ELN_MASK 0x0080 #define S_G1_MASK 0x1000 #define S_G2_MASK 0x2000 #define NWORDS_MASK 0x001F #define CMD_MASK 0x041F #define SUBADDR_MASK 0x03E0 #define CI_MASK 0x03E0 #define HBIT_MASK 0x0200 #define RT_DIR_MASK 0x0400 #define ADDRESS_MASK 0xF800 #define RTFL_MASK 0x0001 #define DNBA_MASK 0x0002 #define SSFL_MASK 0x0004 #define BUSY_MASK 0x0008 #define BRCST_MASK 0x0010 #define NULL_MASK 0x00E0 #define SREQ_MASK 0x0100 #define ERROR_MASK 0x0400 #define SREQ 0x01 #define BUSY 0x02 #define SSFL 0x04 #define RTFL 0x08 #define DNBA 0x10 #define CWB0 0x20 #define CWB1 0x40 #define BC_MODE 0x0000 #define RT_MODE 0x0080 #define MT_MODE 0x0100 #define MRT_MODE 0x0280 #define UNDEFINED_MODE 0xFFFF #define RT_ENABLE 0x0 #define RT_DISABLE 0x1F #define RT_GET_ENABLE 0xFFFF #define RT_TRANSMIT 0x0400 #define RT_RECEIVE 0x0000 #define RT_ERROR_MASK 0x4000 #define RT_FLAG 0x8000 #define RT_FLAG_MASK 0x8000 #define RT_HBIT_MODE 0x0001 #define MT_HBIT_MODE 0x0001 #define RT_FLAG_MODE 0x0002 #define RT_BRCST_MODE 0x0004 #define RT_DATA_BL 0x2000 #define RT_GENER1_BL 0x0004 #define RT_GENER2_BL 0x4000 #define BC_GENER1_BL 0x0004 #define BC_GENER2_BL 0x4000 #define MT_GENER1_BL 0x0004 #define MT_GENER2_BL 0x4000 #define TMK_IRQ_OFF 0x8000 #define CX_CC_MASK 0x000F #define CX_CONT_MASK 0x0010 #define CX_BUS_MASK 0x0020 #define CX_SIG_MASK 0x8000 #define CX_INT_MASK 0x0020 #define CX_CONT 0x0010 #define CX_STOP 0x0000 #define CX_BUS_0 0x0000 #define CX_BUS_A 0x0000 #define CX_BUS_1 0x0020 #define CX_BUS_B 0x0020 #define CX_NOSIG 0x0000 #define CX_SIG 0x8000 #define CX_INT 0x0000 #define CX_NOINT 0x0020 #define SX_NOERR 0 #define SX_MEO 1 #define SX_TOA 2 #define SX_TOD 3 #define SX_ELN 4 #define SX_ERAO 5 #define SX_ESYN 6 #define SX_EBC 7 #define SX_ERR_MASK 0x0007 #define SX_IB_MASK 0x0008 #define SX_G1_MASK 0x0010 #define SX_G2_MASK 0x0020 #define SX_K2_MASK 0x0100 #define SX_K1_MASK 0x0200 #define SX_SCC_MASK 0x3C00 #define SX_ME_MASK 0x4000 #define SX_BUS_MASK 0x8000 #define SX_BUS_0 0x0000 #define SX_BUS_A 0x0000 #define SX_BUS_1 0x8000 #define SX_BUS_B 0x8000 #define GET_IO_DELAY 0xFFFF #define CW(ADDR,DIR,SUBADDR,NWORDS) (((ADDR)<<11)|(DIR)|((SUBADDR)<<5)|((NWORDS)&0x1F)) #define CWM(ADDR,COMMAND) (((ADDR)<<11)|(CI_MASK)|(COMMAND)) /*#define CMD_ILLEGAL 0x000*/ #define CMD_DYNAMIC_BUS_CONTROL 0x400 #define CMD_SYNCHRONIZE 0x401 #define CMD_TRANSMIT_STATUS_WORD 0x402 #define CMD_INITIATE_SELF_TEST 0x403 #define CMD_TRANSMITTER_SHUTDOWN 0x404 #define CMD_OVERRIDE_TRANSMITTER_SHUTDOWN 0x405 #define CMD_INHIBIT_TERMINAL_FLAG_BIT 0x406 #define CMD_OVERRIDE_INHIBIT_TERMINAL_FLAG_BIT 0x407 #define CMD_RESET_REMOTE_TERMINAL 0x408 #define CMD_TRANSMIT_VECTOR_WORD 0x410 #define CMD_SYNCHRONIZE_WITH_DATA_WORD 0x011 #define CMD_TRANSMIT_LAST_COMMAND_WORD 0x412 #define CMD_TRANSMIT_BUILT_IN_TEST_WORD 0x413 #ifndef TMK_ERROR_0 #define TMK_ERROR_0 0 #endif #define TMK_BAD_TYPE (1 + TMK_ERROR_0) #define TMK_BAD_IRQ (2 + TMK_ERROR_0) #define TMK_BAD_NUMBER (3 + TMK_ERROR_0) #define BC_BAD_BUS (4 + TMK_ERROR_0) #define BC_BAD_BASE (5 + TMK_ERROR_0) #define BC_BAD_LEN (6 + TMK_ERROR_0) #define RT_BAD_PAGE (7 + TMK_ERROR_0) #define RT_BAD_LEN (8 + TMK_ERROR_0) #define RT_BAD_ADDRESS (9 + TMK_ERROR_0) #define RT_BAD_FUNC (10 + TMK_ERROR_0) #define BC_BAD_FUNC (11 + TMK_ERROR_0) #define TMK_BAD_FUNC (12 + TMK_ERROR_0) #define TMK_PCI_ERROR (13 + TMK_ERROR_0) #define TMK_MAX_ERROR (13 + TMK_ERROR_0) #ifdef DOS32 #define TMK_DPMI_ERROR (100 + TMK_ERROR_0) #endif //DOS32 #ifndef __EXTERN #ifdef __cplusplus #define __EXTERN extern #else #define __EXTERN #endif #endif #ifdef __cplusplus //__EXTERN "C" { #endif #if !(defined(DOS)) __EXTERN U16 __rtDisableMask[NTMK+NRT]; #endif #ifdef QNX4 __EXTERN U16 __tmkIrqPort[NTMK]; __EXTERN U16 __tmkIrqBit[NTMK]; #endif #ifndef DYNAMIC_TMKNUM __EXTERN int tmkError; #define int_TMKNUM void #define int_TMKNUM__ #else __EXTERN int tmkError[NTMK+NRT]; #define int_TMKNUM int tmkNumber #define int_TMKNUM__ int tmkNumber, #endif #ifdef DOS32 __EXTERN void FARFN tmkOpenDPMI(void); #endif __EXTERN U16 FARFN tmkiodelay(int_TMKNUM__ U16 IODelay); __EXTERN int FARFN tmkgetmaxn(void); #ifdef QNX4VME __EXTERN int FARFN tmkconfig(int tmkNumber, U16 tmkType, U16 tmkPorts1, U16 tmkPorts2, U08 tmkIrq1, U08 tmkIrq2, char *pTmkName); #else __EXTERN int FARFN tmkconfig(int tmkNumber, U16 tmkType, U16 tmkPorts1, U16 tmkPorts2, U08 tmkIrq1, U08 tmkIrq2); #endif //def QNX4VME __EXTERN int FARFN tmkdone(int tmkNumber); #ifdef DOS #if NRT > 0 __EXTERN U32 FARFN mrtconfig(int tmkNumber, U16 tmkType, U16 tmkPorts1, U16 tmkPorts2, U08 tmkIrq1, U08 tmkIrq2); #endif //NRT __EXTERN void FARFN tmkdefirq(int_TMKNUM__ U16 pcIrq); __EXTERN void FARFN tmkundefirq(int_TMKNUM__ U16 pcIrq); __EXTERN void FARFN tmkdeferrors(int_TMKNUM__ void (FARIR* UserErrors)()); #endif __EXTERN int FARFN tmkselect(int tmkNumber); #ifndef DYNAMIC_TMKNUM __EXTERN int FARFN tmkselected(void); #endif __EXTERN U16 FARFN tmkgetmode(int_TMKNUM); __EXTERN void FARFN tmksave(int_TMKNUM); __EXTERN void FARFN tmkrestore(int_TMKNUM); __EXTERN void FARFN tmksetcwbits(int_TMKNUM__ U16 tmkSetControl); __EXTERN void FARFN tmkclrcwbits(int_TMKNUM__ U16 tmkClrControl); __EXTERN U16 FARFN tmkgetcwbits(int_TMKNUM); #if defined(DOS) || defined(QNX4) __EXTERN void FARFN bcdefintnorm(int_TMKNUM__ RETIR (FARIR* UserNormBC)(U16, U16, U16)); __EXTERN void FARFN bcdefintexc(int_TMKNUM__ RETIR (FARIR* UserExcBC)(U16, U16, U16)); __EXTERN void FARFN bcdefintx(int_TMKNUM__ RETIR (FARIR* UserXBC)(U16, U16)); __EXTERN void FARFN bcdefintsig(int_TMKNUM__ RETIR (FARIR* UserSigBC)(U16)); #endif __EXTERN int FARFN bcreset(int_TMKNUM); __EXTERN void FARFN bcrestore(int_TMKNUM); __EXTERN void FARFN bc_def_tldw(U16 wTLDW); __EXTERN void FARFN bc_enable_di(void); __EXTERN void FARFN bc_disable_di(void); __EXTERN int FARFN bcdefirqmode(int_TMKNUM__ U16 bcIrqMode); __EXTERN U16 FARFN bcgetirqmode(int_TMKNUM); __EXTERN U16 FARFN bcgetmaxbase(int_TMKNUM); __EXTERN int FARFN bcdefbase(int_TMKNUM__ U16 bcBasePC); __EXTERN U16 FARFN bcgetbase(int_TMKNUM); __EXTERN void FARFN bcputw(int_TMKNUM__ U16 bcAddr, U16 bcData); __EXTERN U16 FARFN bcgetw(int_TMKNUM__ U16 bcAddr); __EXTERN U32 FARFN bcgetansw(int_TMKNUM__ U16 bcCtrlCode); __EXTERN void FARFN bcputblk(int_TMKNUM__ U16 bcAddr, void FARDT *pcBuffer, U16 cwLength); __EXTERN void FARFN bcgetblk(int_TMKNUM__ U16 bcAddr, void FARDT *pcBuffer, U16 cwLength); __EXTERN int FARFN bcdefbus(int_TMKNUM__ U16 bcBus); __EXTERN U16 FARFN bcgetbus(int_TMKNUM); __EXTERN int FARFN bcstart(int_TMKNUM__ U16 bcBase, U16 bcCtrlCode); __EXTERN int FARFN bcstartx(int_TMKNUM__ U16 bcBase, U16 bcCtrlCode); __EXTERN int FARFN bcdeflink(int_TMKNUM__ U16 bcBase, U16 bcCtrlCode); __EXTERN U32 FARFN bcgetlink(int_TMKNUM); __EXTERN int FARFN bcstop(int_TMKNUM); __EXTERN U32 FARFN bcgetstate(int_TMKNUM); #if defined(DOS) || defined(QNX4) __EXTERN void FARFN rtdefintcmd(int_TMKNUM__ RETIR (FARIR* UserCmdRT)(U16)); __EXTERN void FARFN rtdefinterr(int_TMKNUM__ RETIR (FARIR* UserErrRT)(U16)); __EXTERN void FARFN rtdefintdata(int_TMKNUM__ RETIR (FARIR* UserDataRT)(U16)); #endif __EXTERN int FARFN rtreset(int_TMKNUM); __EXTERN void FARFN rtrestore(int_TMKNUM); __EXTERN int FARFN rtdefirqmode(int_TMKNUM__ U16 rtIrqMode); __EXTERN U16 FARFN rtgetirqmode(int_TMKNUM); __EXTERN int FARFN rtdefmode(int_TMKNUM__ U16 rtMode); __EXTERN U16 FARFN rtgetmode(int_TMKNUM); __EXTERN U16 FARFN rtgetmaxpage(int_TMKNUM); __EXTERN int FARFN rtdefpage(int_TMKNUM__ U16 rtPage); __EXTERN U16 FARFN rtgetpage(int_TMKNUM); __EXTERN int FARFN rtdefpagepc(int_TMKNUM__ U16 rtPagePC); __EXTERN int FARFN rtdefpagebus(int_TMKNUM__ U16 rtPageBus); __EXTERN U16 FARFN rtgetpagepc(int_TMKNUM); __EXTERN U16 FARFN rtgetpagebus(int_TMKNUM); __EXTERN int FARFN rtdefaddress(int_TMKNUM__ U16 rtAddress); __EXTERN U16 FARFN rtgetaddress(int_TMKNUM); __EXTERN void FARFN rtdefsubaddr(int_TMKNUM__ U16 rtDir, U16 rtSubAddr); __EXTERN U16 FARFN rtgetsubaddr(int_TMKNUM); __EXTERN void FARFN rtputw(int_TMKNUM__ U16 rtAddr, U16 rtData); __EXTERN U16 FARFN rtgetw(int_TMKNUM__ U16 rtAddr); __EXTERN void FARFN rtputblk(int_TMKNUM__ U16 rtAddr, void FARDT *pcBuffer, U16 cwLength); __EXTERN void FARFN rtgetblk(int_TMKNUM__ U16 rtAddr, void FARDT *pcBuffer, U16 cwLength); __EXTERN void FARFN rtsetanswbits(int_TMKNUM__ U16 rtSetControl); __EXTERN void FARFN rtclranswbits(int_TMKNUM__ U16 rtClrControl); __EXTERN U16 FARFN rtgetanswbits(int_TMKNUM); __EXTERN void FARFN rtgetflags(int_TMKNUM__ void FARDT *pcBuffer, U16 rtDir, U16 rtFlagMin, U16 rtFlagMax); __EXTERN void FARFN rtputflags(int_TMKNUM__ void FARDT *pcBuffer, U16 rtDir, U16 rtFlagMin, U16 rtFlagMax); __EXTERN void FARFN rtsetflag(int_TMKNUM); __EXTERN void FARFN rtclrflag(int_TMKNUM); __EXTERN U16 FARFN rtgetflag(int_TMKNUM__ U16 rtDir, U16 rtSubAddr); __EXTERN U16 FARFN rtgetstate(int_TMKNUM); __EXTERN int FARFN rtbusy(int_TMKNUM); __EXTERN void FARFN rtlock(int_TMKNUM__ U16 rtDir, U16 rtSubAddr); __EXTERN void FARFN rtunlock(int_TMKNUM); __EXTERN U16 FARFN rtgetcmddata(int_TMKNUM__ U16 rtBusCommand); __EXTERN void FARFN rtputcmddata(int_TMKNUM__ U16 rtBusCommand, U16 rtData); #if defined(DOS) || defined(QNX4) __EXTERN void FARFN mtdefintx(int_TMKNUM__ RETIR (FARIR* UserIntXMT)(U16, U16)); __EXTERN void FARFN mtdefintsig(int_TMKNUM__ RETIR (FARIR* UserSigMT)(U16)); #endif __EXTERN int FARFN mtreset(int_TMKNUM); #define mtrestore bcrestore #define mtdefirqmode bcdefirqmode #define mtgetirqmode bcgetirqmode #define mtgetmaxbase bcgetmaxbase #define mtdefbase bcdefbase #define mtgetbase bcgetbase #define mtputw bcputw #define mtgetw bcgetw __EXTERN U16 FARFN mtgetsw(int_TMKNUM); #define mtputblk bcputblk #define mtgetblk bcgetblk #define mtstartx bcstartx #define mtdeflink bcdeflink #define mtgetlink bcgetlink #define mtstop bcstop #define mtgetstate bcgetstate __EXTERN U16 FARFN rtenable(int_TMKNUM__ U16 rtfEnable); #if NRT > 0 __EXTERN int FARFN mrtgetmaxn(void); #ifndef DYNAMIC_TMKNUM __EXTERN int FARFN mrtselected(void); #endif __EXTERN int FARFN mrtgetnrt(int_TMKNUM); __EXTERN int FARFN mrtgetrt0(int_TMKNUM); __EXTERN U16 FARFN mrtgetstate(int_TMKNUM); __EXTERN void FARFN mrtdefbrcsubaddr0(int_TMKNUM); __EXTERN int FARFN mrtdefbrcpage(int_TMKNUM__ U16 mrtBrcPage); __EXTERN U16 FARFN mrtgetbrcpage(int_TMKNUM); //__EXTERN int _cdecl mrtreset(void); #define mrtreset bcreset __EXTERN int FARFN rt2mrt(int rtNumber); __EXTERN void FARFN mrtdefmaxnrt(int mrtMaxNrt); #endif //NRT __EXTERN U16 FARFN rtgetlock(int_TMKNUM); __EXTERN void FARFN rtputflag(int_TMKNUM__ U16 rtDir, U16 rtSubAddr, U16 rtFlag); __EXTERN U16 FARFN tmkgethwver(int_TMKNUM); __EXTERN U16 FARFN tmktimer(int_TMKNUM__ U16 tmkTimerCtrl); __EXTERN U16 FARFN tmkgettimerl(int_TMKNUM); __EXTERN U32 FARFN tmkgettimer(int_TMKNUM); __EXTERN U32 FARFN bcgetmsgtime(int_TMKNUM); #define mtgetmsgtime bcgetmsgtime __EXTERN U32 FARFN rtgetmsgtime(int_TMKNUM); #ifdef DOS __EXTERN U16 FARFN tmkswtimer(int_TMKNUM__ U16 tmkSwTimerCtrl); __EXTERN U32 FARFN tmkgetswtimer(int_TMKNUM); __EXTERN U32 FARFN tmkgetevtime(int_TMKNUM); #endif //def DOS __EXTERN U16 FARFN tmktimeout(int_TMKNUM__ U16 tmkTimeOut); __EXTERN int FARFN mtdefmode(int_TMKNUM__ U16 mtMode); __EXTERN U16 FARFN mtgetmode(int_TMKNUM); __EXTERN int FARFN tmkdefdac(int_TMKNUM__ U16 tmkDacValue); __EXTERN int FARFN tmkgetdac(int_TMKNUM__ U16 *tmkDacValue, U16 *tmkDacMode); #ifdef NMBCID __EXTERN int FARFN mbcinit(U16 mbcId); __EXTERN int FARFN mbcpreparex(int_TMKNUM__ U16 mbcId, U16 bcBase, U16 bcCtrlCode, U16 mbcDelay); __EXTERN int FARFN mbcstartx(U16 mbcId); __EXTERN U16 FARFN mbcalloc(void); __EXTERN int FARFN mbcfree(U16 mbcId); #endif #if NRT > 0 && defined(MRTA) __EXTERN void FARFN __rtputblkmrta(int_TMKNUM__ U16 rtAddr, void FARDT *pcBuffer, U16 cwLength); __EXTERN void FARFN __rtgetblkmrta(int_TMKNUM__ U16 rtAddr, void FARDT *pcBuffer, U16 cwLength); unsigned long DIRQLTmkSave(int hTMK); void DIRQLTmkRestore(int hTMK, unsigned long Saved); #else unsigned DIRQLTmkSave(int hTMK); void DIRQLTmkRestore(int hTMK, unsigned Saved); #endif //NRT MRTA unsigned DIRQLTmksInt1(int hTMK, void *pEvData); void DpcIExcBC(int hTMK, void *pEvData); #ifdef __cplusplus //} #endif #endif
31.037255
130
0.767389
ff0fdf4f23025396c78d05ab54672cf57b1b13ed
5,709
h
C
PWGGA/EMCALTasks/AliAnalysisTaskEMCALPi0V2ShSh.h
maroozm/AliPhysics
22ec256928cfdf8f800e05bfc1a6e124d90b6eaf
[ "BSD-3-Clause" ]
114
2017-03-03T09:12:23.000Z
2022-03-03T20:29:42.000Z
PWGGA/EMCALTasks/AliAnalysisTaskEMCALPi0V2ShSh.h
maroozm/AliPhysics
22ec256928cfdf8f800e05bfc1a6e124d90b6eaf
[ "BSD-3-Clause" ]
19,637
2017-01-16T12:34:41.000Z
2022-03-31T22:02:40.000Z
PWGGA/EMCALTasks/AliAnalysisTaskEMCALPi0V2ShSh.h
maroozm/AliPhysics
22ec256928cfdf8f800e05bfc1a6e124d90b6eaf
[ "BSD-3-Clause" ]
1,021
2016-07-14T22:41:16.000Z
2022-03-31T05:15:51.000Z
#ifndef AliAnalysisTaskEMCALPi0V2ShSh_h #define AliAnalysisTaskEMCALPi0V2ShSh_h // $Id: AliAnalysisTaskEMCALPi0V2ShSh.h$ class TH1I; class TH1F; class TH1D; class TH2F; class THnSparse; class TList; class TObjArray; class TProfile; class TProfile2D; class AliOADBContainer; class AliEMCALGeometry; class AliESDEvent; class AliESDtrack; class AliESDCaloCells; class AliAODEvent; class AliAODCaloCells; class AliVCluster; class AliCentrality; class AliEPFlattener; #include "AliAnalysisTaskSE.h" class AliAnalysisTaskEMCALPi0V2ShSh : public AliAnalysisTaskSE { public: AliAnalysisTaskEMCALPi0V2ShSh(); AliAnalysisTaskEMCALPi0V2ShSh(const char *name); virtual ~AliAnalysisTaskEMCALPi0V2ShSh() {} void UserCreateOutputObjects(); void UserExec(Option_t *option); void Terminate(Option_t *); void SetEMCALClusterListName(TString name) {fEMCALClustersListName = name;} void IsPHOSCali(Bool_t e) {isPhosCali = e;} void IsCentFlat(Bool_t e) {isCentFlat = e;} protected: AliEventplane *fEventPlane; Double_t fCentrality; TString fEMCALClustersListName; // TClonesArray *fClusterArray; //!pointer to EMCal cluster /* AliESDCaloCells *fESDCells; //!pointer to EMCal cells, esd */ /* AliAODCaloCells *fAODCells; //!pointer to EMCal cells, aod */ AliEMCALGeometry *fGeom; // geometry utils TString fGeoName; // geometry name (def = EMCAL_FIRSTYEARV1) AliOADBContainer *fOADBContainer; //!OADB container used to load misalignment matrices AliOADBContainer *fFlatContainer; private: void FillHistsCluster(); void FillHistsTrack(); Int_t GetInternalRunNum(Int_t runnumber); Bool_t IsCentAccepted(); void VZEROEventPlane(Bool_t isFlatten); Double_t ApplyFlatteningTPC(Double_t phi, Double_t c) ; //Apply centrality-dependent flattening Double_t ApplyFlatteningV0A(Double_t phi, Double_t c) ; //Apply centrality-dependent flattening Double_t ApplyFlatteningV0C(Double_t phi, Double_t c) ; //Apply centrality-dependent flattening Bool_t IsGoodCluster(const AliVCluster *c) const; Double_t GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const; Bool_t IsWithinFiducialVolume(Short_t id) const; Double_t GetCrossEnergy(const AliVCluster *cluster, Short_t &idmax) const; Bool_t IsPi0Candidate(const AliVCluster *c); AliESDEvent *fESD; //! ESD object AliAODEvent *fAOD; //! AOD object TList *fOutputList; //! General Output list TGeoHMatrix *fGeomMatrix[12]; //! Geometry misalignment matrices for EMCal Bool_t isPhosCali; // use Phos flatten EP Bool_t isCentFlat; // flatten 0-10% cent AliEPFlattener *fTPCFlat; //! Object for flattening of TPC AliEPFlattener *fV0AFlat; //! Object for flattening of V0A AliEPFlattener *fV0CFlat; //! Object for flattening of V0C Int_t fRunNumber; Int_t fInternalRunNum; Double_t fEPTPC; Double_t fEPTPCResolution; Double_t fEPV0; Double_t fEPV0A; Double_t fEPV0C; Double_t fEPV0AR; Double_t fEPV0CR; Double_t fEPV0R; Double_t fEPV0AR4; Double_t fEPV0AR5; Double_t fEPV0AR6; Double_t fEPV0AR7; Double_t fEPV0CR0; Double_t fEPV0CR1; Double_t fEPV0CR2; Double_t fEPV0CR3; // histograms TH1I *fHistStatEvt; TH1I *fHistStatCluster; TH1I *fHistStatRunNum; TH1D *fHistStatCentrality; TH1D *fHistStatCentralityCorrected; TH2F *fHistEPTPC; TH2F *fHistEPTPCResolution; TH2F *fHistEPV0; TH2F *fHistEPV0A; TH2F *fHistEPV0C; TH2F *fHistEPV0AR; TH2F *fHistEPV0CR; TH2F *fHistEPV0R; TH2F *fHistEPV0AR4; TH2F *fHistEPV0AR7; TH2F *fHistEPV0CR0; TH2F *fHistEPV0CR3; TH2F *fHistEPTPCFlatten; TH2F *fHistEPV0AFlatten; TH2F *fHistEPV0CFlatten; TH2F *fHistEPDiffV0A_V0CR0; TH2F *fHistEPDiffV0A_V0CR3; TH2F *fHistEPDiffV0CR0_V0CR3; TH2F *fHistEPDiffV0C_V0AR4; TH2F *fHistEPDiffV0C_V0AR7; TH2F *fHistEPDiffV0AR4_V0AR7; TH2F *fHistEPDiffV0AR_V0CR; TProfile2D *fHistEPRBRCosV0A; TProfile2D *fHistEPRBRSinV0A; TProfile2D *fHistEPRBRCosV0C; TProfile2D *fHistEPRBRSinV0C; TProfile2D *fHistEPRBRCosTPC; TProfile2D *fHistEPRBRSinTPC; TH1F *fHistClusterEta; TH1F *fHistClusterPhi; TH1F *fHistClusterE; TH1F *fHistClusterEt; TH1F *fHistClusterN; TH1F *fHistClusterM02; TH2F *fHistClusterEN; TH2F *fHistClusterEM02Raw; TH2F *fHistClusterEM02Cut; TH2F *fHistClusterPhiEta; TH2F *fHistClusterEtN; TH2F *fHistClusterEtM02; TH1D *fHistClusterdphiV0; TH1D *fHistClusterNLMRaw; TH1D *fHistClusterNLM; TH1F *fHistTrackPt; TH1F *fHistTrackEta; TH1F *fHistTrackPhi; TH2F *fHistTrackPhiEta; THnSparse *fClusterV0; THnSparse *fClusterV0A; THnSparse *fClusterV0C; THnSparse *fClusterTPC; AliAnalysisTaskEMCALPi0V2ShSh(const AliAnalysisTaskEMCALPi0V2ShSh&); // not implemented AliAnalysisTaskEMCALPi0V2ShSh& operator=(const AliAnalysisTaskEMCALPi0V2ShSh&); // not implemented ClassDef(AliAnalysisTaskEMCALPi0V2ShSh, 1); }; #endif
33
101
0.663163
ff10c1c9cd6138ebf6649978ffe7355de85d80de
758
h
C
src/common/misc/pint-clean-malloc.h
dschwoerer/orangefs
386a12df2b0310ec2e0d37aba092204d9490c7be
[ "Apache-2.0" ]
44
2018-10-11T23:16:42.000Z
2022-03-16T11:23:49.000Z
src/common/misc/pint-clean-malloc.h
dschwoerer/orangefs
386a12df2b0310ec2e0d37aba092204d9490c7be
[ "Apache-2.0" ]
84
2018-05-31T20:14:51.000Z
2021-09-05T19:37:51.000Z
src/common/misc/pint-clean-malloc.h
dschwoerer/orangefs
386a12df2b0310ec2e0d37aba092204d9490c7be
[ "Apache-2.0" ]
7
2018-10-23T13:40:21.000Z
2021-09-26T07:19:44.000Z
/* * (C) 2013 Clemson University and The University of Chicago * * See COPYING in top-level directory. * */ #ifndef PINT_CLEAN_MALLOC_H #define PINT_CLEAN_MALLOC_H extern void *clean_malloc(size_t size); extern void *clean_calloc(size_t nmemb, size_t size); extern int clean_posix_memalign(void **ptr, size_t alignment, size_t size); extern void *clean_memalign(size_t alignment, size_t size); extern void *clean_valloc(size_t size); extern void *clean_realloc(void *ptr, size_t size); extern char *clean_strdup(const char *str); extern char *clean_strndup(const char *str, size_t n); extern void clean_free(void *ptr); #endif /* * Local variables: * c-indent-level: 4 * c-basic-offset: 4 * End: * * vim: ts=4 sts=4 sw=4 expandtab */
24.451613
77
0.733509
b14907209822e64000da92240c26b1fa0eb0654f
9,341
c
C
arch/powerpc/kernel/vdso.c
bm16ton/yoga-c630-linux-kernel
1ad0c23bc5361821b3ddf173469772c488a1ee88
[ "Unlicense" ]
5
2020-07-08T01:35:16.000Z
2021-04-12T16:35:29.000Z
arch/powerpc/kernel/vdso.c
bm16ton/yoga-c630-linux-kernel
1ad0c23bc5361821b3ddf173469772c488a1ee88
[ "Unlicense" ]
null
null
null
arch/powerpc/kernel/vdso.c
bm16ton/yoga-c630-linux-kernel
1ad0c23bc5361821b3ddf173469772c488a1ee88
[ "Unlicense" ]
null
null
null
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp. * <benh@kernel.crashing.org> */ #include <linux/errno.h> #include <linux/sched.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/smp.h> #include <linux/stddef.h> #include <linux/unistd.h> #include <linux/slab.h> #include <linux/user.h> #include <linux/elf.h> #include <linux/security.h> #include <linux/memblock.h> #include <linux/syscalls.h> #include <vdso/datapage.h> #include <asm/syscall.h> #include <asm/processor.h> #include <asm/mmu.h> #include <asm/mmu_context.h> #include <asm/prom.h> #include <asm/machdep.h> #include <asm/cputable.h> #include <asm/sections.h> #include <asm/firmware.h> #include <asm/vdso.h> #include <asm/vdso_datapage.h> #include <asm/setup.h> /* The alignment of the vDSO */ #define VDSO_ALIGNMENT (1 << 16) extern char vdso32_start, vdso32_end; extern char vdso64_start, vdso64_end; /* * The vdso data page (aka. systemcfg for old ppc64 fans) is here. * Once the early boot kernel code no longer needs to muck around * with it, it will become dynamically allocated */ static union { struct vdso_arch_data data; u8 page[PAGE_SIZE]; } vdso_data_store __page_aligned_data; struct vdso_arch_data *vdso_data = &vdso_data_store.data; static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma, unsigned long text_size) { unsigned long new_size = new_vma->vm_end - new_vma->vm_start; if (new_size != text_size) return -EINVAL; current->mm->context.vdso = (void __user *)new_vma->vm_start; return 0; } static int vdso32_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { return vdso_mremap(sm, new_vma, &vdso32_end - &vdso32_start); } static int vdso64_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { return vdso_mremap(sm, new_vma, &vdso64_end - &vdso64_start); } static struct vm_special_mapping vvar_spec __ro_after_init = { .name = "[vvar]", }; static struct vm_special_mapping vdso32_spec __ro_after_init = { .name = "[vdso]", .mremap = vdso32_mremap, }; static struct vm_special_mapping vdso64_spec __ro_after_init = { .name = "[vdso]", .mremap = vdso64_mremap, }; /* * This is called from binfmt_elf, we create the special vma for the * vDSO and insert it into the mm struct tree */ static int __arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) { unsigned long vdso_size, vdso_base, mappings_size; struct vm_special_mapping *vdso_spec; unsigned long vvar_size = PAGE_SIZE; struct mm_struct *mm = current->mm; struct vm_area_struct *vma; if (is_32bit_task()) { vdso_spec = &vdso32_spec; vdso_size = &vdso32_end - &vdso32_start; vdso_base = VDSO32_MBASE; } else { vdso_spec = &vdso64_spec; vdso_size = &vdso64_end - &vdso64_start; /* * On 64bit we don't have a preferred map address. This * allows get_unmapped_area to find an area near other mmaps * and most likely share a SLB entry. */ vdso_base = 0; } mappings_size = vdso_size + vvar_size; mappings_size += (VDSO_ALIGNMENT - 1) & PAGE_MASK; /* * pick a base address for the vDSO in process space. We try to put it * at vdso_base which is the "natural" base for it, but we might fail * and end up putting it elsewhere. * Add enough to the size so that the result can be aligned. */ vdso_base = get_unmapped_area(NULL, vdso_base, mappings_size, 0, 0); if (IS_ERR_VALUE(vdso_base)) return vdso_base; /* Add required alignment. */ vdso_base = ALIGN(vdso_base, VDSO_ALIGNMENT); /* * Put vDSO base into mm struct. We need to do this before calling * install_special_mapping or the perf counter mmap tracking code * will fail to recognise it as a vDSO. */ mm->context.vdso = (void __user *)vdso_base + vvar_size; vma = _install_special_mapping(mm, vdso_base, vvar_size, VM_READ | VM_MAYREAD | VM_IO | VM_DONTDUMP | VM_PFNMAP, &vvar_spec); if (IS_ERR(vma)) return PTR_ERR(vma); /* * our vma flags don't have VM_WRITE so by default, the process isn't * allowed to write those pages. * gdb can break that with ptrace interface, and thus trigger COW on * those pages but it's then your responsibility to never do that on * the "data" page of the vDSO or you'll stop getting kernel updates * and your nice userland gettimeofday will be totally dead. * It's fine to use that for setting breakpoints in the vDSO code * pages though. */ vma = _install_special_mapping(mm, vdso_base + vvar_size, vdso_size, VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC, vdso_spec); if (IS_ERR(vma)) do_munmap(mm, vdso_base, vvar_size, NULL); return PTR_ERR_OR_ZERO(vma); } int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) { struct mm_struct *mm = current->mm; int rc; mm->context.vdso = NULL; if (mmap_write_lock_killable(mm)) return -EINTR; rc = __arch_setup_additional_pages(bprm, uses_interp); if (rc) mm->context.vdso = NULL; mmap_write_unlock(mm); return rc; } #define VDSO_DO_FIXUPS(type, value, bits, sec) do { \ void *__start = (void *)VDSO##bits##_SYMBOL(&vdso##bits##_start, sec##_start); \ void *__end = (void *)VDSO##bits##_SYMBOL(&vdso##bits##_start, sec##_end); \ \ do_##type##_fixups((value), __start, __end); \ } while (0) static void __init vdso_fixup_features(void) { #ifdef CONFIG_PPC64 VDSO_DO_FIXUPS(feature, cur_cpu_spec->cpu_features, 64, ftr_fixup); VDSO_DO_FIXUPS(feature, cur_cpu_spec->mmu_features, 64, mmu_ftr_fixup); VDSO_DO_FIXUPS(feature, powerpc_firmware_features, 64, fw_ftr_fixup); VDSO_DO_FIXUPS(lwsync, cur_cpu_spec->cpu_features, 64, lwsync_fixup); #endif /* CONFIG_PPC64 */ #ifdef CONFIG_VDSO32 VDSO_DO_FIXUPS(feature, cur_cpu_spec->cpu_features, 32, ftr_fixup); VDSO_DO_FIXUPS(feature, cur_cpu_spec->mmu_features, 32, mmu_ftr_fixup); #ifdef CONFIG_PPC64 VDSO_DO_FIXUPS(feature, powerpc_firmware_features, 32, fw_ftr_fixup); #endif /* CONFIG_PPC64 */ VDSO_DO_FIXUPS(lwsync, cur_cpu_spec->cpu_features, 32, lwsync_fixup); #endif } /* * Called from setup_arch to initialize the bitmap of available * syscalls in the systemcfg page */ static void __init vdso_setup_syscall_map(void) { unsigned int i; for (i = 0; i < NR_syscalls; i++) { if (sys_call_table[i] != (unsigned long)&sys_ni_syscall) vdso_data->syscall_map[i >> 5] |= 0x80000000UL >> (i & 0x1f); if (IS_ENABLED(CONFIG_COMPAT) && compat_sys_call_table[i] != (unsigned long)&sys_ni_syscall) vdso_data->compat_syscall_map[i >> 5] |= 0x80000000UL >> (i & 0x1f); } } #ifdef CONFIG_PPC64 int vdso_getcpu_init(void) { unsigned long cpu, node, val; /* * SPRG_VDSO contains the CPU in the bottom 16 bits and the NUMA node * in the next 16 bits. The VDSO uses this to implement getcpu(). */ cpu = get_cpu(); WARN_ON_ONCE(cpu > 0xffff); node = cpu_to_node(cpu); WARN_ON_ONCE(node > 0xffff); val = (cpu & 0xffff) | ((node & 0xffff) << 16); mtspr(SPRN_SPRG_VDSO_WRITE, val); get_paca()->sprg_vdso = val; put_cpu(); return 0; } /* We need to call this before SMP init */ early_initcall(vdso_getcpu_init); #endif static struct page ** __init vdso_setup_pages(void *start, void *end) { int i; struct page **pagelist; int pages = (end - start) >> PAGE_SHIFT; pagelist = kcalloc(pages + 1, sizeof(struct page *), GFP_KERNEL); if (!pagelist) panic("%s: Cannot allocate page list for VDSO", __func__); for (i = 0; i < pages; i++) pagelist[i] = virt_to_page(start + i * PAGE_SIZE); return pagelist; } static struct page ** __init vvar_setup_pages(void) { struct page **pagelist; /* .pages is NULL-terminated */ pagelist = kcalloc(2, sizeof(struct page *), GFP_KERNEL); if (!pagelist) panic("%s: Cannot allocate page list for VVAR", __func__); pagelist[0] = virt_to_page(vdso_data); return pagelist; } static int __init vdso_init(void) { #ifdef CONFIG_PPC64 /* * Fill up the "systemcfg" stuff for backward compatibility */ strcpy((char *)vdso_data->eye_catcher, "SYSTEMCFG:PPC64"); vdso_data->version.major = SYSTEMCFG_MAJOR; vdso_data->version.minor = SYSTEMCFG_MINOR; vdso_data->processor = mfspr(SPRN_PVR); /* * Fake the old platform number for pSeries and add * in LPAR bit if necessary */ vdso_data->platform = 0x100; if (firmware_has_feature(FW_FEATURE_LPAR)) vdso_data->platform |= 1; vdso_data->physicalMemorySize = memblock_phys_mem_size(); vdso_data->dcache_size = ppc64_caches.l1d.size; vdso_data->dcache_line_size = ppc64_caches.l1d.line_size; vdso_data->icache_size = ppc64_caches.l1i.size; vdso_data->icache_line_size = ppc64_caches.l1i.line_size; vdso_data->dcache_block_size = ppc64_caches.l1d.block_size; vdso_data->icache_block_size = ppc64_caches.l1i.block_size; vdso_data->dcache_log_block_size = ppc64_caches.l1d.log_block_size; vdso_data->icache_log_block_size = ppc64_caches.l1i.log_block_size; #endif /* CONFIG_PPC64 */ vdso_setup_syscall_map(); vdso_fixup_features(); if (IS_ENABLED(CONFIG_VDSO32)) vdso32_spec.pages = vdso_setup_pages(&vdso32_start, &vdso32_end); if (IS_ENABLED(CONFIG_PPC64)) vdso64_spec.pages = vdso_setup_pages(&vdso64_start, &vdso64_end); vvar_spec.pages = vvar_setup_pages(); smp_wmb(); return 0; } arch_initcall(vdso_init);
28.565749
93
0.728081
3d1944f7a02ba7529b16ec1d22d2dc2991009039
948
h
C
Source/UE5VoxelTutorial/Private/GreedyChunk.h
Aidanjhk/UE5VoxelTutorial
8a2cfb388e7cbcb3adc1f1225831204536f9158f
[ "MIT" ]
null
null
null
Source/UE5VoxelTutorial/Private/GreedyChunk.h
Aidanjhk/UE5VoxelTutorial
8a2cfb388e7cbcb3adc1f1225831204536f9158f
[ "MIT" ]
null
null
null
Source/UE5VoxelTutorial/Private/GreedyChunk.h
Aidanjhk/UE5VoxelTutorial
8a2cfb388e7cbcb3adc1f1225831204536f9158f
[ "MIT" ]
null
null
null
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "ChunkBase.h" #include "ChunkMeshData.h" #include "GameFramework/Actor.h" #include "GreedyChunk.generated.h" enum class EBlock; enum class EDirection; class FastNoiseLite; class UProceduralMeshComponent; UCLASS() class AGreedyChunk final : public AChunkBase { GENERATED_BODY() struct FMask { EBlock Block; int Normal; }; public: // Sets default values for this actor's properties AGreedyChunk(); protected: virtual void GenerateHeightMap() override; virtual void GenerateMesh() override; private: TArray<EBlock> Blocks; void CreateQuad(FMask Mask, FIntVector AxisMask, int Width, int Height, FIntVector V1, FIntVector V2, FIntVector V3, FIntVector V4); int GetBlockIndex(int X, int Y, int Z) const; EBlock GetBlock(FIntVector Index) const; bool CompareMask(FMask M1, FMask M2) const; };
18.96
133
0.759494
3211cd08281d561bb38d9045c7ca5952d79ddd8a
31,448
c
C
third_party/webrtc/src/chromium/src/third_party/libvpx_new/source/libvpx/vp10/common/vp10_fwd_txfm.c
bopopescu/webrtc-streaming-node
727a441204344ff596401b0253caac372b714d91
[ "MIT" ]
83
2015-08-04T06:19:59.000Z
2022-03-25T03:33:55.000Z
third_party/webrtc/src/chromium/src/third_party/libvpx_new/source/libvpx/vp10/common/vp10_fwd_txfm.c
bopopescu/webrtc-streaming-node
727a441204344ff596401b0253caac372b714d91
[ "MIT" ]
32
2015-07-31T22:47:16.000Z
2022-03-16T01:57:49.000Z
third_party/webrtc/src/chromium/src/third_party/libvpx_new/source/libvpx/vp10/common/vp10_fwd_txfm.c
bopopescu/webrtc-streaming-node
727a441204344ff596401b0253caac372b714d91
[ "MIT" ]
40
2015-07-25T03:01:48.000Z
2022-03-29T07:55:34.000Z
/* * Copyright (c) 2015 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "vp10/common/vp10_fwd_txfm.h" void vp10_fdct4x4_c(const int16_t *input, tran_low_t *output, int stride) { // The 2D transform is done with two passes which are actually pretty // similar. In the first one, we transform the columns and transpose // the results. In the second one, we transform the rows. To achieve that, // as the first pass results are transposed, we transpose the columns (that // is the transposed rows) and transpose the results (so that it goes back // in normal/row positions). int pass; // We need an intermediate buffer between passes. tran_low_t intermediate[4 * 4]; const int16_t *in_pass0 = input; const tran_low_t *in = NULL; tran_low_t *out = intermediate; // Do the two transform/transpose passes for (pass = 0; pass < 2; ++pass) { tran_high_t input[4]; // canbe16 tran_high_t step[4]; // canbe16 tran_high_t temp1, temp2; // needs32 int i; for (i = 0; i < 4; ++i) { // Load inputs. if (0 == pass) { input[0] = in_pass0[0 * stride] * 16; input[1] = in_pass0[1 * stride] * 16; input[2] = in_pass0[2 * stride] * 16; input[3] = in_pass0[3 * stride] * 16; if (i == 0 && input[0]) { input[0] += 1; } } else { input[0] = in[0 * 4]; input[1] = in[1 * 4]; input[2] = in[2 * 4]; input[3] = in[3 * 4]; } // Transform. step[0] = input[0] + input[3]; step[1] = input[1] + input[2]; step[2] = input[1] - input[2]; step[3] = input[0] - input[3]; temp1 = (step[0] + step[1]) * cospi_16_64; temp2 = (step[0] - step[1]) * cospi_16_64; out[0] = (tran_low_t)fdct_round_shift(temp1); out[2] = (tran_low_t)fdct_round_shift(temp2); temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64; temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64; out[1] = (tran_low_t)fdct_round_shift(temp1); out[3] = (tran_low_t)fdct_round_shift(temp2); // Do next column (which is a transposed row in second/horizontal pass) in_pass0++; in++; out += 4; } // Setup in/out for next pass. in = intermediate; out = output; } { int i, j; for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) output[j + i * 4] = (output[j + i * 4] + 1) >> 2; } } } void vp10_fdct4x4_1_c(const int16_t *input, tran_low_t *output, int stride) { int r, c; tran_low_t sum = 0; for (r = 0; r < 4; ++r) for (c = 0; c < 4; ++c) sum += input[r * stride + c]; output[0] = sum << 1; output[1] = 0; } void vp10_fdct8x8_c(const int16_t *input, tran_low_t *final_output, int stride) { int i, j; tran_low_t intermediate[64]; int pass; tran_low_t *output = intermediate; const tran_low_t *in = NULL; // Transform columns for (pass = 0; pass < 2; ++pass) { tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16 tran_high_t t0, t1, t2, t3; // needs32 tran_high_t x0, x1, x2, x3; // canbe16 int i; for (i = 0; i < 8; i++) { // stage 1 if (pass == 0) { s0 = (input[0 * stride] + input[7 * stride]) * 4; s1 = (input[1 * stride] + input[6 * stride]) * 4; s2 = (input[2 * stride] + input[5 * stride]) * 4; s3 = (input[3 * stride] + input[4 * stride]) * 4; s4 = (input[3 * stride] - input[4 * stride]) * 4; s5 = (input[2 * stride] - input[5 * stride]) * 4; s6 = (input[1 * stride] - input[6 * stride]) * 4; s7 = (input[0 * stride] - input[7 * stride]) * 4; ++input; } else { s0 = in[0 * 8] + in[7 * 8]; s1 = in[1 * 8] + in[6 * 8]; s2 = in[2 * 8] + in[5 * 8]; s3 = in[3 * 8] + in[4 * 8]; s4 = in[3 * 8] - in[4 * 8]; s5 = in[2 * 8] - in[5 * 8]; s6 = in[1 * 8] - in[6 * 8]; s7 = in[0 * 8] - in[7 * 8]; ++in; } // fdct4(step, step); x0 = s0 + s3; x1 = s1 + s2; x2 = s1 - s2; x3 = s0 - s3; t0 = (x0 + x1) * cospi_16_64; t1 = (x0 - x1) * cospi_16_64; t2 = x2 * cospi_24_64 + x3 * cospi_8_64; t3 = -x2 * cospi_8_64 + x3 * cospi_24_64; output[0] = (tran_low_t)fdct_round_shift(t0); output[2] = (tran_low_t)fdct_round_shift(t2); output[4] = (tran_low_t)fdct_round_shift(t1); output[6] = (tran_low_t)fdct_round_shift(t3); // Stage 2 t0 = (s6 - s5) * cospi_16_64; t1 = (s6 + s5) * cospi_16_64; t2 = fdct_round_shift(t0); t3 = fdct_round_shift(t1); // Stage 3 x0 = s4 + t2; x1 = s4 - t2; x2 = s7 - t3; x3 = s7 + t3; // Stage 4 t0 = x0 * cospi_28_64 + x3 * cospi_4_64; t1 = x1 * cospi_12_64 + x2 * cospi_20_64; t2 = x2 * cospi_12_64 + x1 * -cospi_20_64; t3 = x3 * cospi_28_64 + x0 * -cospi_4_64; output[1] = (tran_low_t)fdct_round_shift(t0); output[3] = (tran_low_t)fdct_round_shift(t2); output[5] = (tran_low_t)fdct_round_shift(t1); output[7] = (tran_low_t)fdct_round_shift(t3); output += 8; } in = intermediate; output = final_output; } // Rows for (i = 0; i < 8; ++i) { for (j = 0; j < 8; ++j) final_output[j + i * 8] /= 2; } } void vp10_fdct8x8_1_c(const int16_t *input, tran_low_t *output, int stride) { int r, c; tran_low_t sum = 0; for (r = 0; r < 8; ++r) for (c = 0; c < 8; ++c) sum += input[r * stride + c]; output[0] = sum; output[1] = 0; } void vp10_fdct16x16_c(const int16_t *input, tran_low_t *output, int stride) { // The 2D transform is done with two passes which are actually pretty // similar. In the first one, we transform the columns and transpose // the results. In the second one, we transform the rows. To achieve that, // as the first pass results are transposed, we transpose the columns (that // is the transposed rows) and transpose the results (so that it goes back // in normal/row positions). int pass; // We need an intermediate buffer between passes. tran_low_t intermediate[256]; const int16_t *in_pass0 = input; const tran_low_t *in = NULL; tran_low_t *out = intermediate; // Do the two transform/transpose passes for (pass = 0; pass < 2; ++pass) { tran_high_t step1[8]; // canbe16 tran_high_t step2[8]; // canbe16 tran_high_t step3[8]; // canbe16 tran_high_t input[8]; // canbe16 tran_high_t temp1, temp2; // needs32 int i; for (i = 0; i < 16; i++) { if (0 == pass) { // Calculate input for the first 8 results. input[0] = (in_pass0[0 * stride] + in_pass0[15 * stride]) * 4; input[1] = (in_pass0[1 * stride] + in_pass0[14 * stride]) * 4; input[2] = (in_pass0[2 * stride] + in_pass0[13 * stride]) * 4; input[3] = (in_pass0[3 * stride] + in_pass0[12 * stride]) * 4; input[4] = (in_pass0[4 * stride] + in_pass0[11 * stride]) * 4; input[5] = (in_pass0[5 * stride] + in_pass0[10 * stride]) * 4; input[6] = (in_pass0[6 * stride] + in_pass0[ 9 * stride]) * 4; input[7] = (in_pass0[7 * stride] + in_pass0[ 8 * stride]) * 4; // Calculate input for the next 8 results. step1[0] = (in_pass0[7 * stride] - in_pass0[ 8 * stride]) * 4; step1[1] = (in_pass0[6 * stride] - in_pass0[ 9 * stride]) * 4; step1[2] = (in_pass0[5 * stride] - in_pass0[10 * stride]) * 4; step1[3] = (in_pass0[4 * stride] - in_pass0[11 * stride]) * 4; step1[4] = (in_pass0[3 * stride] - in_pass0[12 * stride]) * 4; step1[5] = (in_pass0[2 * stride] - in_pass0[13 * stride]) * 4; step1[6] = (in_pass0[1 * stride] - in_pass0[14 * stride]) * 4; step1[7] = (in_pass0[0 * stride] - in_pass0[15 * stride]) * 4; } else { // Calculate input for the first 8 results. input[0] = ((in[0 * 16] + 1) >> 2) + ((in[15 * 16] + 1) >> 2); input[1] = ((in[1 * 16] + 1) >> 2) + ((in[14 * 16] + 1) >> 2); input[2] = ((in[2 * 16] + 1) >> 2) + ((in[13 * 16] + 1) >> 2); input[3] = ((in[3 * 16] + 1) >> 2) + ((in[12 * 16] + 1) >> 2); input[4] = ((in[4 * 16] + 1) >> 2) + ((in[11 * 16] + 1) >> 2); input[5] = ((in[5 * 16] + 1) >> 2) + ((in[10 * 16] + 1) >> 2); input[6] = ((in[6 * 16] + 1) >> 2) + ((in[ 9 * 16] + 1) >> 2); input[7] = ((in[7 * 16] + 1) >> 2) + ((in[ 8 * 16] + 1) >> 2); // Calculate input for the next 8 results. step1[0] = ((in[7 * 16] + 1) >> 2) - ((in[ 8 * 16] + 1) >> 2); step1[1] = ((in[6 * 16] + 1) >> 2) - ((in[ 9 * 16] + 1) >> 2); step1[2] = ((in[5 * 16] + 1) >> 2) - ((in[10 * 16] + 1) >> 2); step1[3] = ((in[4 * 16] + 1) >> 2) - ((in[11 * 16] + 1) >> 2); step1[4] = ((in[3 * 16] + 1) >> 2) - ((in[12 * 16] + 1) >> 2); step1[5] = ((in[2 * 16] + 1) >> 2) - ((in[13 * 16] + 1) >> 2); step1[6] = ((in[1 * 16] + 1) >> 2) - ((in[14 * 16] + 1) >> 2); step1[7] = ((in[0 * 16] + 1) >> 2) - ((in[15 * 16] + 1) >> 2); } // Work on the first eight values; fdct8(input, even_results); { tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16 tran_high_t t0, t1, t2, t3; // needs32 tran_high_t x0, x1, x2, x3; // canbe16 // stage 1 s0 = input[0] + input[7]; s1 = input[1] + input[6]; s2 = input[2] + input[5]; s3 = input[3] + input[4]; s4 = input[3] - input[4]; s5 = input[2] - input[5]; s6 = input[1] - input[6]; s7 = input[0] - input[7]; // fdct4(step, step); x0 = s0 + s3; x1 = s1 + s2; x2 = s1 - s2; x3 = s0 - s3; t0 = (x0 + x1) * cospi_16_64; t1 = (x0 - x1) * cospi_16_64; t2 = x3 * cospi_8_64 + x2 * cospi_24_64; t3 = x3 * cospi_24_64 - x2 * cospi_8_64; out[0] = (tran_low_t)fdct_round_shift(t0); out[4] = (tran_low_t)fdct_round_shift(t2); out[8] = (tran_low_t)fdct_round_shift(t1); out[12] = (tran_low_t)fdct_round_shift(t3); // Stage 2 t0 = (s6 - s5) * cospi_16_64; t1 = (s6 + s5) * cospi_16_64; t2 = fdct_round_shift(t0); t3 = fdct_round_shift(t1); // Stage 3 x0 = s4 + t2; x1 = s4 - t2; x2 = s7 - t3; x3 = s7 + t3; // Stage 4 t0 = x0 * cospi_28_64 + x3 * cospi_4_64; t1 = x1 * cospi_12_64 + x2 * cospi_20_64; t2 = x2 * cospi_12_64 + x1 * -cospi_20_64; t3 = x3 * cospi_28_64 + x0 * -cospi_4_64; out[2] = (tran_low_t)fdct_round_shift(t0); out[6] = (tran_low_t)fdct_round_shift(t2); out[10] = (tran_low_t)fdct_round_shift(t1); out[14] = (tran_low_t)fdct_round_shift(t3); } // Work on the next eight values; step1 -> odd_results { // step 2 temp1 = (step1[5] - step1[2]) * cospi_16_64; temp2 = (step1[4] - step1[3]) * cospi_16_64; step2[2] = fdct_round_shift(temp1); step2[3] = fdct_round_shift(temp2); temp1 = (step1[4] + step1[3]) * cospi_16_64; temp2 = (step1[5] + step1[2]) * cospi_16_64; step2[4] = fdct_round_shift(temp1); step2[5] = fdct_round_shift(temp2); // step 3 step3[0] = step1[0] + step2[3]; step3[1] = step1[1] + step2[2]; step3[2] = step1[1] - step2[2]; step3[3] = step1[0] - step2[3]; step3[4] = step1[7] - step2[4]; step3[5] = step1[6] - step2[5]; step3[6] = step1[6] + step2[5]; step3[7] = step1[7] + step2[4]; // step 4 temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64; temp2 = step3[2] * cospi_24_64 + step3[5] * cospi_8_64; step2[1] = fdct_round_shift(temp1); step2[2] = fdct_round_shift(temp2); temp1 = step3[2] * cospi_8_64 - step3[5] * cospi_24_64; temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64; step2[5] = fdct_round_shift(temp1); step2[6] = fdct_round_shift(temp2); // step 5 step1[0] = step3[0] + step2[1]; step1[1] = step3[0] - step2[1]; step1[2] = step3[3] + step2[2]; step1[3] = step3[3] - step2[2]; step1[4] = step3[4] - step2[5]; step1[5] = step3[4] + step2[5]; step1[6] = step3[7] - step2[6]; step1[7] = step3[7] + step2[6]; // step 6 temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64; temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64; out[1] = (tran_low_t)fdct_round_shift(temp1); out[9] = (tran_low_t)fdct_round_shift(temp2); temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64; temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64; out[5] = (tran_low_t)fdct_round_shift(temp1); out[13] = (tran_low_t)fdct_round_shift(temp2); temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64; temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64; out[3] = (tran_low_t)fdct_round_shift(temp1); out[11] = (tran_low_t)fdct_round_shift(temp2); temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64; temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64; out[7] = (tran_low_t)fdct_round_shift(temp1); out[15] = (tran_low_t)fdct_round_shift(temp2); } // Do next column (which is a transposed row in second/horizontal pass) in++; in_pass0++; out += 16; } // Setup in/out for next pass. in = intermediate; out = output; } } void vp10_fdct16x16_1_c(const int16_t *input, tran_low_t *output, int stride) { int r, c; tran_low_t sum = 0; for (r = 0; r < 16; ++r) for (c = 0; c < 16; ++c) sum += input[r * stride + c]; output[0] = sum >> 1; output[1] = 0; } static INLINE tran_high_t dct_32_round(tran_high_t input) { tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS); // TODO(debargha, peter.derivaz): Find new bounds for this assert, // and make the bounds consts. // assert(-131072 <= rv && rv <= 131071); return rv; } static INLINE tran_high_t half_round_shift(tran_high_t input) { tran_high_t rv = (input + 1 + (input < 0)) >> 2; return rv; } void vp10_fdct32(const tran_high_t *input, tran_high_t *output, int round) { tran_high_t step[32]; // Stage 1 step[0] = input[0] + input[(32 - 1)]; step[1] = input[1] + input[(32 - 2)]; step[2] = input[2] + input[(32 - 3)]; step[3] = input[3] + input[(32 - 4)]; step[4] = input[4] + input[(32 - 5)]; step[5] = input[5] + input[(32 - 6)]; step[6] = input[6] + input[(32 - 7)]; step[7] = input[7] + input[(32 - 8)]; step[8] = input[8] + input[(32 - 9)]; step[9] = input[9] + input[(32 - 10)]; step[10] = input[10] + input[(32 - 11)]; step[11] = input[11] + input[(32 - 12)]; step[12] = input[12] + input[(32 - 13)]; step[13] = input[13] + input[(32 - 14)]; step[14] = input[14] + input[(32 - 15)]; step[15] = input[15] + input[(32 - 16)]; step[16] = -input[16] + input[(32 - 17)]; step[17] = -input[17] + input[(32 - 18)]; step[18] = -input[18] + input[(32 - 19)]; step[19] = -input[19] + input[(32 - 20)]; step[20] = -input[20] + input[(32 - 21)]; step[21] = -input[21] + input[(32 - 22)]; step[22] = -input[22] + input[(32 - 23)]; step[23] = -input[23] + input[(32 - 24)]; step[24] = -input[24] + input[(32 - 25)]; step[25] = -input[25] + input[(32 - 26)]; step[26] = -input[26] + input[(32 - 27)]; step[27] = -input[27] + input[(32 - 28)]; step[28] = -input[28] + input[(32 - 29)]; step[29] = -input[29] + input[(32 - 30)]; step[30] = -input[30] + input[(32 - 31)]; step[31] = -input[31] + input[(32 - 32)]; // Stage 2 output[0] = step[0] + step[16 - 1]; output[1] = step[1] + step[16 - 2]; output[2] = step[2] + step[16 - 3]; output[3] = step[3] + step[16 - 4]; output[4] = step[4] + step[16 - 5]; output[5] = step[5] + step[16 - 6]; output[6] = step[6] + step[16 - 7]; output[7] = step[7] + step[16 - 8]; output[8] = -step[8] + step[16 - 9]; output[9] = -step[9] + step[16 - 10]; output[10] = -step[10] + step[16 - 11]; output[11] = -step[11] + step[16 - 12]; output[12] = -step[12] + step[16 - 13]; output[13] = -step[13] + step[16 - 14]; output[14] = -step[14] + step[16 - 15]; output[15] = -step[15] + step[16 - 16]; output[16] = step[16]; output[17] = step[17]; output[18] = step[18]; output[19] = step[19]; output[20] = dct_32_round((-step[20] + step[27]) * cospi_16_64); output[21] = dct_32_round((-step[21] + step[26]) * cospi_16_64); output[22] = dct_32_round((-step[22] + step[25]) * cospi_16_64); output[23] = dct_32_round((-step[23] + step[24]) * cospi_16_64); output[24] = dct_32_round((step[24] + step[23]) * cospi_16_64); output[25] = dct_32_round((step[25] + step[22]) * cospi_16_64); output[26] = dct_32_round((step[26] + step[21]) * cospi_16_64); output[27] = dct_32_round((step[27] + step[20]) * cospi_16_64); output[28] = step[28]; output[29] = step[29]; output[30] = step[30]; output[31] = step[31]; // dump the magnitude by 4, hence the intermediate values are within // the range of 16 bits. if (round) { output[0] = half_round_shift(output[0]); output[1] = half_round_shift(output[1]); output[2] = half_round_shift(output[2]); output[3] = half_round_shift(output[3]); output[4] = half_round_shift(output[4]); output[5] = half_round_shift(output[5]); output[6] = half_round_shift(output[6]); output[7] = half_round_shift(output[7]); output[8] = half_round_shift(output[8]); output[9] = half_round_shift(output[9]); output[10] = half_round_shift(output[10]); output[11] = half_round_shift(output[11]); output[12] = half_round_shift(output[12]); output[13] = half_round_shift(output[13]); output[14] = half_round_shift(output[14]); output[15] = half_round_shift(output[15]); output[16] = half_round_shift(output[16]); output[17] = half_round_shift(output[17]); output[18] = half_round_shift(output[18]); output[19] = half_round_shift(output[19]); output[20] = half_round_shift(output[20]); output[21] = half_round_shift(output[21]); output[22] = half_round_shift(output[22]); output[23] = half_round_shift(output[23]); output[24] = half_round_shift(output[24]); output[25] = half_round_shift(output[25]); output[26] = half_round_shift(output[26]); output[27] = half_round_shift(output[27]); output[28] = half_round_shift(output[28]); output[29] = half_round_shift(output[29]); output[30] = half_round_shift(output[30]); output[31] = half_round_shift(output[31]); } // Stage 3 step[0] = output[0] + output[(8 - 1)]; step[1] = output[1] + output[(8 - 2)]; step[2] = output[2] + output[(8 - 3)]; step[3] = output[3] + output[(8 - 4)]; step[4] = -output[4] + output[(8 - 5)]; step[5] = -output[5] + output[(8 - 6)]; step[6] = -output[6] + output[(8 - 7)]; step[7] = -output[7] + output[(8 - 8)]; step[8] = output[8]; step[9] = output[9]; step[10] = dct_32_round((-output[10] + output[13]) * cospi_16_64); step[11] = dct_32_round((-output[11] + output[12]) * cospi_16_64); step[12] = dct_32_round((output[12] + output[11]) * cospi_16_64); step[13] = dct_32_round((output[13] + output[10]) * cospi_16_64); step[14] = output[14]; step[15] = output[15]; step[16] = output[16] + output[23]; step[17] = output[17] + output[22]; step[18] = output[18] + output[21]; step[19] = output[19] + output[20]; step[20] = -output[20] + output[19]; step[21] = -output[21] + output[18]; step[22] = -output[22] + output[17]; step[23] = -output[23] + output[16]; step[24] = -output[24] + output[31]; step[25] = -output[25] + output[30]; step[26] = -output[26] + output[29]; step[27] = -output[27] + output[28]; step[28] = output[28] + output[27]; step[29] = output[29] + output[26]; step[30] = output[30] + output[25]; step[31] = output[31] + output[24]; // Stage 4 output[0] = step[0] + step[3]; output[1] = step[1] + step[2]; output[2] = -step[2] + step[1]; output[3] = -step[3] + step[0]; output[4] = step[4]; output[5] = dct_32_round((-step[5] + step[6]) * cospi_16_64); output[6] = dct_32_round((step[6] + step[5]) * cospi_16_64); output[7] = step[7]; output[8] = step[8] + step[11]; output[9] = step[9] + step[10]; output[10] = -step[10] + step[9]; output[11] = -step[11] + step[8]; output[12] = -step[12] + step[15]; output[13] = -step[13] + step[14]; output[14] = step[14] + step[13]; output[15] = step[15] + step[12]; output[16] = step[16]; output[17] = step[17]; output[18] = dct_32_round(step[18] * -cospi_8_64 + step[29] * cospi_24_64); output[19] = dct_32_round(step[19] * -cospi_8_64 + step[28] * cospi_24_64); output[20] = dct_32_round(step[20] * -cospi_24_64 + step[27] * -cospi_8_64); output[21] = dct_32_round(step[21] * -cospi_24_64 + step[26] * -cospi_8_64); output[22] = step[22]; output[23] = step[23]; output[24] = step[24]; output[25] = step[25]; output[26] = dct_32_round(step[26] * cospi_24_64 + step[21] * -cospi_8_64); output[27] = dct_32_round(step[27] * cospi_24_64 + step[20] * -cospi_8_64); output[28] = dct_32_round(step[28] * cospi_8_64 + step[19] * cospi_24_64); output[29] = dct_32_round(step[29] * cospi_8_64 + step[18] * cospi_24_64); output[30] = step[30]; output[31] = step[31]; // Stage 5 step[0] = dct_32_round((output[0] + output[1]) * cospi_16_64); step[1] = dct_32_round((-output[1] + output[0]) * cospi_16_64); step[2] = dct_32_round(output[2] * cospi_24_64 + output[3] * cospi_8_64); step[3] = dct_32_round(output[3] * cospi_24_64 - output[2] * cospi_8_64); step[4] = output[4] + output[5]; step[5] = -output[5] + output[4]; step[6] = -output[6] + output[7]; step[7] = output[7] + output[6]; step[8] = output[8]; step[9] = dct_32_round(output[9] * -cospi_8_64 + output[14] * cospi_24_64); step[10] = dct_32_round(output[10] * -cospi_24_64 + output[13] * -cospi_8_64); step[11] = output[11]; step[12] = output[12]; step[13] = dct_32_round(output[13] * cospi_24_64 + output[10] * -cospi_8_64); step[14] = dct_32_round(output[14] * cospi_8_64 + output[9] * cospi_24_64); step[15] = output[15]; step[16] = output[16] + output[19]; step[17] = output[17] + output[18]; step[18] = -output[18] + output[17]; step[19] = -output[19] + output[16]; step[20] = -output[20] + output[23]; step[21] = -output[21] + output[22]; step[22] = output[22] + output[21]; step[23] = output[23] + output[20]; step[24] = output[24] + output[27]; step[25] = output[25] + output[26]; step[26] = -output[26] + output[25]; step[27] = -output[27] + output[24]; step[28] = -output[28] + output[31]; step[29] = -output[29] + output[30]; step[30] = output[30] + output[29]; step[31] = output[31] + output[28]; // Stage 6 output[0] = step[0]; output[1] = step[1]; output[2] = step[2]; output[3] = step[3]; output[4] = dct_32_round(step[4] * cospi_28_64 + step[7] * cospi_4_64); output[5] = dct_32_round(step[5] * cospi_12_64 + step[6] * cospi_20_64); output[6] = dct_32_round(step[6] * cospi_12_64 + step[5] * -cospi_20_64); output[7] = dct_32_round(step[7] * cospi_28_64 + step[4] * -cospi_4_64); output[8] = step[8] + step[9]; output[9] = -step[9] + step[8]; output[10] = -step[10] + step[11]; output[11] = step[11] + step[10]; output[12] = step[12] + step[13]; output[13] = -step[13] + step[12]; output[14] = -step[14] + step[15]; output[15] = step[15] + step[14]; output[16] = step[16]; output[17] = dct_32_round(step[17] * -cospi_4_64 + step[30] * cospi_28_64); output[18] = dct_32_round(step[18] * -cospi_28_64 + step[29] * -cospi_4_64); output[19] = step[19]; output[20] = step[20]; output[21] = dct_32_round(step[21] * -cospi_20_64 + step[26] * cospi_12_64); output[22] = dct_32_round(step[22] * -cospi_12_64 + step[25] * -cospi_20_64); output[23] = step[23]; output[24] = step[24]; output[25] = dct_32_round(step[25] * cospi_12_64 + step[22] * -cospi_20_64); output[26] = dct_32_round(step[26] * cospi_20_64 + step[21] * cospi_12_64); output[27] = step[27]; output[28] = step[28]; output[29] = dct_32_round(step[29] * cospi_28_64 + step[18] * -cospi_4_64); output[30] = dct_32_round(step[30] * cospi_4_64 + step[17] * cospi_28_64); output[31] = step[31]; // Stage 7 step[0] = output[0]; step[1] = output[1]; step[2] = output[2]; step[3] = output[3]; step[4] = output[4]; step[5] = output[5]; step[6] = output[6]; step[7] = output[7]; step[8] = dct_32_round(output[8] * cospi_30_64 + output[15] * cospi_2_64); step[9] = dct_32_round(output[9] * cospi_14_64 + output[14] * cospi_18_64); step[10] = dct_32_round(output[10] * cospi_22_64 + output[13] * cospi_10_64); step[11] = dct_32_round(output[11] * cospi_6_64 + output[12] * cospi_26_64); step[12] = dct_32_round(output[12] * cospi_6_64 + output[11] * -cospi_26_64); step[13] = dct_32_round(output[13] * cospi_22_64 + output[10] * -cospi_10_64); step[14] = dct_32_round(output[14] * cospi_14_64 + output[9] * -cospi_18_64); step[15] = dct_32_round(output[15] * cospi_30_64 + output[8] * -cospi_2_64); step[16] = output[16] + output[17]; step[17] = -output[17] + output[16]; step[18] = -output[18] + output[19]; step[19] = output[19] + output[18]; step[20] = output[20] + output[21]; step[21] = -output[21] + output[20]; step[22] = -output[22] + output[23]; step[23] = output[23] + output[22]; step[24] = output[24] + output[25]; step[25] = -output[25] + output[24]; step[26] = -output[26] + output[27]; step[27] = output[27] + output[26]; step[28] = output[28] + output[29]; step[29] = -output[29] + output[28]; step[30] = -output[30] + output[31]; step[31] = output[31] + output[30]; // Final stage --- outputs indices are bit-reversed. output[0] = step[0]; output[16] = step[1]; output[8] = step[2]; output[24] = step[3]; output[4] = step[4]; output[20] = step[5]; output[12] = step[6]; output[28] = step[7]; output[2] = step[8]; output[18] = step[9]; output[10] = step[10]; output[26] = step[11]; output[6] = step[12]; output[22] = step[13]; output[14] = step[14]; output[30] = step[15]; output[1] = dct_32_round(step[16] * cospi_31_64 + step[31] * cospi_1_64); output[17] = dct_32_round(step[17] * cospi_15_64 + step[30] * cospi_17_64); output[9] = dct_32_round(step[18] * cospi_23_64 + step[29] * cospi_9_64); output[25] = dct_32_round(step[19] * cospi_7_64 + step[28] * cospi_25_64); output[5] = dct_32_round(step[20] * cospi_27_64 + step[27] * cospi_5_64); output[21] = dct_32_round(step[21] * cospi_11_64 + step[26] * cospi_21_64); output[13] = dct_32_round(step[22] * cospi_19_64 + step[25] * cospi_13_64); output[29] = dct_32_round(step[23] * cospi_3_64 + step[24] * cospi_29_64); output[3] = dct_32_round(step[24] * cospi_3_64 + step[23] * -cospi_29_64); output[19] = dct_32_round(step[25] * cospi_19_64 + step[22] * -cospi_13_64); output[11] = dct_32_round(step[26] * cospi_11_64 + step[21] * -cospi_21_64); output[27] = dct_32_round(step[27] * cospi_27_64 + step[20] * -cospi_5_64); output[7] = dct_32_round(step[28] * cospi_7_64 + step[19] * -cospi_25_64); output[23] = dct_32_round(step[29] * cospi_23_64 + step[18] * -cospi_9_64); output[15] = dct_32_round(step[30] * cospi_15_64 + step[17] * -cospi_17_64); output[31] = dct_32_round(step[31] * cospi_31_64 + step[16] * -cospi_1_64); } void vp10_fdct32x32_c(const int16_t *input, tran_low_t *out, int stride) { int i, j; tran_high_t output[32 * 32]; // Columns for (i = 0; i < 32; ++i) { tran_high_t temp_in[32], temp_out[32]; for (j = 0; j < 32; ++j) temp_in[j] = input[j * stride + i] * 4; vp10_fdct32(temp_in, temp_out, 0); for (j = 0; j < 32; ++j) output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2; } // Rows for (i = 0; i < 32; ++i) { tran_high_t temp_in[32], temp_out[32]; for (j = 0; j < 32; ++j) temp_in[j] = output[j + i * 32]; vp10_fdct32(temp_in, temp_out, 0); for (j = 0; j < 32; ++j) out[j + i * 32] = (tran_low_t)((temp_out[j] + 1 + (temp_out[j] < 0)) >> 2); } } // Note that although we use dct_32_round in dct32 computation flow, // this 2d fdct32x32 for rate-distortion optimization loop is operating // within 16 bits precision. void vp10_fdct32x32_rd_c(const int16_t *input, tran_low_t *out, int stride) { int i, j; tran_high_t output[32 * 32]; // Columns for (i = 0; i < 32; ++i) { tran_high_t temp_in[32], temp_out[32]; for (j = 0; j < 32; ++j) temp_in[j] = input[j * stride + i] * 4; vp10_fdct32(temp_in, temp_out, 0); for (j = 0; j < 32; ++j) // TODO(cd): see quality impact of only doing // output[j * 32 + i] = (temp_out[j] + 1) >> 2; // PS: also change code in vp10_dsp/x86/vp10_dct_sse2.c output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2; } // Rows for (i = 0; i < 32; ++i) { tran_high_t temp_in[32], temp_out[32]; for (j = 0; j < 32; ++j) temp_in[j] = output[j + i * 32]; vp10_fdct32(temp_in, temp_out, 1); for (j = 0; j < 32; ++j) out[j + i * 32] = (tran_low_t)temp_out[j]; } } void vp10_fdct32x32_1_c(const int16_t *input, tran_low_t *output, int stride) { int r, c; tran_low_t sum = 0; for (r = 0; r < 32; ++r) for (c = 0; c < 32; ++c) sum += input[r * stride + c]; output[0] = sum >> 3; output[1] = 0; } #if CONFIG_VP9_HIGHBITDEPTH void vp10_highbd_fdct4x4_c(const int16_t *input, tran_low_t *output, int stride) { vp10_fdct4x4_c(input, output, stride); } void vp10_highbd_fdct8x8_c(const int16_t *input, tran_low_t *final_output, int stride) { vp10_fdct8x8_c(input, final_output, stride); } void vp10_highbd_fdct8x8_1_c(const int16_t *input, tran_low_t *final_output, int stride) { vp10_fdct8x8_1_c(input, final_output, stride); } void vp10_highbd_fdct16x16_c(const int16_t *input, tran_low_t *output, int stride) { vp10_fdct16x16_c(input, output, stride); } void vp10_highbd_fdct16x16_1_c(const int16_t *input, tran_low_t *output, int stride) { vp10_fdct16x16_1_c(input, output, stride); } void vp10_highbd_fdct32x32_c(const int16_t *input, tran_low_t *out, int stride) { vp10_fdct32x32_c(input, out, stride); } void vp10_highbd_fdct32x32_rd_c(const int16_t *input, tran_low_t *out, int stride) { vp10_fdct32x32_rd_c(input, out, stride); } void vp10_highbd_fdct32x32_1_c(const int16_t *input, tran_low_t *out, int stride) { vp10_fdct32x32_1_c(input, out, stride); } #endif // CONFIG_VP9_HIGHBITDEPTH
38.118788
80
0.567826
82cdbe4481c483333010d33a19346ca1fa34e07f
2,315
h
C
qbmove_adv_firmware.cydsn/codegentemp/PSoC3_8051.h
NMMI/qbmove-advanced
835ca000a2ee3a850b7c3662f27b60f833636954
[ "BSD-3-Clause" ]
null
null
null
qbmove_adv_firmware.cydsn/codegentemp/PSoC3_8051.h
NMMI/qbmove-advanced
835ca000a2ee3a850b7c3662f27b60f833636954
[ "BSD-3-Clause" ]
null
null
null
qbmove_adv_firmware.cydsn/codegentemp/PSoC3_8051.h
NMMI/qbmove-advanced
835ca000a2ee3a850b7c3662f27b60f833636954
[ "BSD-3-Clause" ]
null
null
null
/******************************************************************************* * File Name: PSoC3_8051.h * Version 5.0 * * Description: * 8051 register definitions for the PSoC3 family of parts. * * Note: * * ******************************************************************************** * Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ #if !defined(CY_BOOT_PSoC3_8051_H) #define CY_BOOT_PSoC3_8051_H #include "cyfitter.h" sfr SFRPRT0DR = 0x80u; sfr SP = 0x81u; sfr DPL = 0x82u; sfr DPH = 0x83u; sfr DPL1 = 0x84u; sfr DPH1 = 0x85u; sfr DPS = 0x86u; sfr SFRPRT0PS = 0x89u; sfr SFRPRT0SEL = 0x8Au; sfr SFRPRT1DR = 0x90u; sfr SFRPRT1PS = 0x91u; sfr DPX = 0x93u; sfr DPX1 = 0x95u; sfr SFRPRT2DR = 0x98u; sfr SFRPRT2PS = 0x99u; sfr SFRPRT2SEL = 0x9Au; sfr P2AX = 0xA0u; sfr SFRPRT1SEL = 0xA2u; sfr IE = 0xA8u; sbit EA = 0xA8u^7u; sfr SFRPRT3DR = 0xB0u; sfr SFRPRT3PS = 0xB1u; sfr SFRPRT3SEL = 0xB2u; sfr SFRPRT4DR = 0xC0u; sfr SFRPRT4PS = 0xC1u; sfr SFRPRT4SEL = 0xC2u; sfr SFRPRT5DR = 0xC8u; sfr SFRPRT5PS = 0xC9u; sfr SFRPRT5SEL = 0xCAu; sfr PSW = 0xD0u; sbit P = 0xD0u^0u; sbit F1 = 0xD0u^1u; sbit OV = 0xD0u^2u; sbit RS0 = 0xD0u^3u; sbit RS1 = 0xD0u^4u; sbit F0 = 0xD0u^5u; sbit AC = 0xD0u^6u; sbit CY = 0xD0u^7u; sfr SFRPRT6DR = 0xD8u; sfr SFRPRT6PS = 0xD9u; sfr SFRPRT6SEL = 0xDAu; sfr ACC = 0xE0u; sfr SFRPRT12DR = 0xE8u; sfr SFRPRT12PS = 0xE9u; sfr MXAX = 0xEAu; sfr B = 0xF0u; sfr SFRPRT12SEL = 0xF2u; sfr SFRPRT15DR = 0xF8u; sfr SFRPRT15PS = 0xF9u; sfr SFRPRT15SEL = 0xFAu; #endif /* (CY_BOOT_PSoC3_8051_H) */ /* [] END OF FILE */
24.892473
80
0.509719
962e6dae237121f5fe51882425900b230f2da019
2,248
h
C
snake_source/gameManager.h
WSU-Cpts322/snake-revisited-BhysjulienWSU
5d29e8ff6519a206b5ec07ad8f1cc3e169ea141b
[ "MIT" ]
null
null
null
snake_source/gameManager.h
WSU-Cpts322/snake-revisited-BhysjulienWSU
5d29e8ff6519a206b5ec07ad8f1cc3e169ea141b
[ "MIT" ]
null
null
null
snake_source/gameManager.h
WSU-Cpts322/snake-revisited-BhysjulienWSU
5d29e8ff6519a206b5ec07ad8f1cc3e169ea141b
[ "MIT" ]
null
null
null
#ifndef GAMEMANAGER #define GAMEMANAGER #define numOfSnakes 4 #define HARD_MODE 4 #define TIMERSET 80 #include "snake.h" #include "badSnake.h" #include "fruit.h" #include "settings.h" #include "gameMap.h" #include <cstring> #include <string> //TODO function for selecting color scheme in own class. //TODO This is allow for GameManager to oppoerate without passing myGame settings. //function for selecting game mode for both types of gd/ames. using namespace std; class GameManager { private: int height; int fruitCount; int width; bool badSnakeX; bool badSnakeY; bool pause; int gameMultiplier; int score = 0; int delay; int baseScore = 10; string snake_Head = "O"; string snake_tail = "o"; string space = " "; string fruitChar = "@"; BadSnake* badSnake; Fruit* fruit; //Setup basic game variables bool SpaceCheck(int y, int x, GameMap &terminal, char checkChar); //Simple check. Mostly used for turning badsnake off and on. bool Compare(int y, int x, int direction, GameMap &terminal, Snake sanke); //Checks if there is a collision of good snake void ChangeDirection(Snake &snake, int input, Settings &myGame, int delay); //Local function to check for change of direction conditions. void FruitMatch(Fruit *fruit, Settings &myGame, GameMap &terminal, bool snakePower); //Handles if there ia fruit match and the needed logic. int SnakeAttack(int count, int &attackNumMove, BadSnake *badSnake, Settings &myGame, GameMap &terminal); //Updates a position for attack Snake. void GameSetup(GameMap &terminal, Settings &myGame, Snake &snake, BadSnake *badSnake, Fruit *fruit); //Sets up all game objects and positions void PrintFruit(Fruit *fruit, GameMap &terminal, bool gametype); //Private function for handling the printing of all static fruit positions void BadAttack(Settings &myGame, BadSnake &badSnake, bool &badSnakeX, bool &badSnakeY); //TODO CAN'T GET THE RANDOM NUMBERS TO WORK CORRECTLY> public: GameManager(int _height, int _width, int _gameMultiplier, string _snakeHead, int _fruitCount, int _delay); ~GameManager(); int PlayGame(Settings &myGame); //handles the core logic functions ofthe gameplay. This is consider the game engine. }; #endif
43.230769
146
0.740214
c5b8ddd2a61436922ac8591f45a3a06f0c72d555
1,266
h
C
old ver-read ascii/get_information.h
helenawang/MBR-VBR-FDTinterpreter
27d3f8cf5d0285200265fafdc1de9fe57e28ab39
[ "Apache-2.0" ]
null
null
null
old ver-read ascii/get_information.h
helenawang/MBR-VBR-FDTinterpreter
27d3f8cf5d0285200265fafdc1de9fe57e28ab39
[ "Apache-2.0" ]
null
null
null
old ver-read ascii/get_information.h
helenawang/MBR-VBR-FDTinterpreter
27d3f8cf5d0285200265fafdc1de9fe57e28ab39
[ "Apache-2.0" ]
null
null
null
//filename: get_information.h author: Wang Ting date:2015.8.17. //main function----int get_info(char arr[],int start,int end) //parameters: //arr----the array of data, obtained from "xxd -p" (no extra space between characters) //start----the first byte you want to get //end----the last byte you want to get //return: //an integer equals to the specified hexdecimal string char str[1024]; int base_table[8]={16,1,4096,256,1048576,65536,268435456,16777216}; int change_to_value(char arr[],int cnt) {//change ascii to its value int i; for(i=0;i<cnt;i++) { if(arr[i]>='0' && arr[i]<='9') arr[i]-='0'; else if(arr[i]>='a' && arr[i]<='f') arr[i]-=87; else if(arr[i]>='A' && arr[i]<='F') arr[i]-=55; else return -1; } return 0; } int get_dec(char arr[],int cnt) {//change hexdecimal to decimal int i,sum=0; if(change_to_value(arr,cnt)) return -1; for(i=0;i<cnt;i++) { if(arr[i]==0) continue; sum+=base_table[i]*arr[i]; } return sum; } int get_info(char arr[],int start,int end) {//get information from specified bytes if(start>end || start<0 || end>=512) {printf("Range Error!\n"); return -1;} start*=2; end*=2; int i,p=start; char temp[8]; int cnt=end-start+2; for(i=0;i<cnt;i++,p++) { temp[i]=arr[p]; } return get_dec(temp,cnt); }
26.93617
87
0.64139
cf0ff0c9607c9455154397b59978d172ecd906d6
9,860
h
C
vendors/renesas/FIT/RDP_v1.15_modified/r_flash_rx/src/targets/rx63n/r_mcu_config_reference.h
tahirrrhassan/AWS-FreeRTOS
9305bf2a8a9eb94edc722188fb64754a31112bb6
[ "MIT" ]
10
2019-09-10T11:20:19.000Z
2021-08-10T02:14:57.000Z
vendors/renesas/FIT/RDP_v1.15_modified/r_flash_rx/src/targets/rx63n/r_mcu_config_reference.h
tahirrrhassan/AWS-FreeRTOS
9305bf2a8a9eb94edc722188fb64754a31112bb6
[ "MIT" ]
5
2020-04-30T03:47:19.000Z
2021-03-31T02:10:11.000Z
vendors/renesas/FIT/RDP_v1.15_modified/r_flash_rx/src/targets/rx63n/r_mcu_config_reference.h
tahirrrhassan/AWS-FreeRTOS
9305bf2a8a9eb94edc722188fb64754a31112bb6
[ "MIT" ]
13
2019-12-31T21:22:09.000Z
2022-03-07T15:55:27.000Z
/*********************************************************************************************************************** * DISCLAIMER * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all * applicable laws, including copyright laws. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of * this software. By using this software, you agree to the additional terms and conditions found by accessing the * following link: * http://www.renesas.com/disclaimer * * Copyright (C) 2016 Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ /*********************************************************************************************************************** * File Name : r_mcu_config_reference.h * Description : Defines the FLASH MCU configuration when not using the FIT BSP. ***********************************************************************************************************************/ /*********************************************************************************************************************** * History : DD.MM.YYYY Version Description * 08.08.2016 1.00 First Release * 25.05.2017 2.20 Added equates for several new MCU_CFG_PART_MEMORY_SIZEs. * 02.08.2017 2.10 Moved FLASH_CFG_USE_FIT_BSP == 1 case to r_flash_targets.h. * xx.xx.xxxx x.xx Added support for GNUC and ICCRX. ***********************************************************************************************************************/ #ifndef R_MCU_CONFIG_HEADER_FILE #define R_MCU_CONFIG_HEADER_FILE #include "r_flash_rx_config.h" #if (FLASH_CFG_USE_FIT_BSP == 0) #include <stdint.h> // typedefs #include <stdbool.h> #include <stddef.h> // NULL #if defined(__CCRX__) || defined(__ICCRX__) /* Intrinsic functions provided by compiler. */ #include <machine.h> #elif defined(__GNUC__) /* No header file for intrinsic functions. */ #endif #include "_r_compiler.h" #include "iodefine.h" #define MCU_RX63N #define MCU_RX631 #define MCU_RX63_ALL /**************************************************************************************** MCU Configuration when not using r_bsp: Configuration options are set here Change the values of the following defines as needed. DON'T FORGET TO SELECT CLOCK (if LOCO not desired) AND ENABLE GLOBAL INTERRUPTS IN YOUR MAIN APPLICATION (normally done by BSP). ****************************************************************************************/ #define MCU_CFG_ICLK_HZ (96000000) #define MCU_CFG_FCLK_HZ (48000000) /* ROM, RAM, and Data Flash Capacity. Character(s) = Value for macro = ROM Size/Ram Size/Data Flash Size F = 0xF = 2MB/256KB/32KB K = 0x14 = 2MB/192KB/32KB E = 0xE = 2MB/128KB/32KB J = 0x13 = 1.5MB/256KB/32KB G = 0x10 = 1.5MB/192KB/32KB D = 0xD = 1.5MB/128KB/32KB Y = 0x22 = 1MB/256KB/32KB W = 0x20 = 1MB/192KB/32KB B = 0xB = 1MB/128KB/32KB A = 0xA = 768KB/128KB/32KB 8 = 0x8 = 512KB/128KB/32KB 7 = 0x7 = 384KB/128KB/32KB 6 = 0x6 = 256KB/128KB/32KB P = 0x19 = 512KB/64KB/32KB N = 0x17 = 384KB/64KB/32KB M = 0x16 = 256KB/64KB/32KB 0 = 0x0 = 0/128KB/0 */ #define MCU_CFG_PART_MEMORY_SIZE (0xB) /**************************************************************************************** Do not change the following values. ****************************************************************************************/ #if MCU_CFG_PART_MEMORY_SIZE == 0x0 /* 0/128KB/0 */ #define MCU_ROM_SIZE_BYTES (0) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (0) #elif MCU_CFG_PART_MEMORY_SIZE == 0x6 /* 256KB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (262144) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x7 /* 384KB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (393216) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x8 /* 512KB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (524288) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0xA /* 768KB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (786432) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0xB /* 1MB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (1048576) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0xD /* 1.5MB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (1572864) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0xE /* 2MB/128KB/32KB */ #define MCU_ROM_SIZE_BYTES (2097152) #define MCU_RAM_SIZE_BYTES (131072) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0xF /* 2MB/256KB/32KB */ #define MCU_ROM_SIZE_BYTES (2097152) #define MCU_RAM_SIZE_BYTES (262144) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x10 /* 1.5MB/192KB/32KB */ #define MCU_ROM_SIZE_BYTES (1572864) #define MCU_RAM_SIZE_BYTES (196608) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x13 /* 1.5MB/256KB/32KB */ #define MCU_ROM_SIZE_BYTES (1572864) #define MCU_RAM_SIZE_BYTES (262144) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x14 /* 2MB/192KB/32KB */ #define MCU_ROM_SIZE_BYTES (2097152) #define MCU_RAM_SIZE_BYTES (196608) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x16 /* 256KB/64KB/32KB */ #define MCU_ROM_SIZE_BYTES (262144) #define MCU_RAM_SIZE_BYTES (65536) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x17 /* 384KB/64KB/32KB */ #define MCU_ROM_SIZE_BYTES (393216) #define MCU_RAM_SIZE_BYTES (65536) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x19 /* 512KB/64KB/32KB */ #define MCU_ROM_SIZE_BYTES (524288) #define MCU_RAM_SIZE_BYTES (65536) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x20 /* 1MB/192KB/32KB */ #define MCU_ROM_SIZE_BYTES (1048576) #define MCU_RAM_SIZE_BYTES (196608) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #elif MCU_CFG_PART_MEMORY_SIZE == 0x22 /* 1MB/256KB/32KB */ #define MCU_ROM_SIZE_BYTES (1048576) #define MCU_RAM_SIZE_BYTES (262144) #define MCU_DATA_FLASH_SIZE_BYTES (32768) #else #error "ERROR - MCU_CFG_PART_MEMORY_SIZE - Unknown memory size chosen in r_mcu_config.h" #endif #define FIT_NO_PTR ((void *)0x10000000) // Reserved space on RX #define FIT_NO_FUNC ((void *)0x10000000) // Reserved space on RX /* RDKRX63N equates for reference. Change to #if 1 if want to use. */ #if 0 #define LED_ON (0) #define LED_OFF (1) #define LED4 PORTD.PODR.BIT.B5 #define LED5 PORTE.PODR.BIT.B3 #define LED6 PORTD.PODR.BIT.B2 #define LED7 PORTE.PODR.BIT.B0 #define LED8 PORTD.PODR.BIT.B4 #define LED9 PORTE.PODR.BIT.B2 #define LED10 PORTD.PODR.BIT.B1 #define LED11 PORTD.PODR.BIT.B7 #define LED12 PORTD.PODR.BIT.B3 #define LED13 PORTE.PODR.BIT.B1 #define LED14 PORTD.PODR.BIT.B0 #define LED15 PORTD.PODR.BIT.B6 #define SW1 PORT4.PIDR.BIT.B0 #define SW2 PORT4.PIDR.BIT.B1 #define SW3 PORT4.PIDR.BIT.B4 #endif #endif /* R_BSP Module not used */ #endif /* R_MCU_CONFIG_HEADER_FILE */
52.169312
121
0.557302
fd9f23db3e3d65b487ba0066a91498120722d1d0
8,281
h
C
aws-cpp-sdk-macie2/include/aws/macie2/model/TagScopeTerm.h
perfectrecall/aws-sdk-cpp
fb8cbebf2fd62720b65aeff841ad2950e73d8ebd
[ "Apache-2.0" ]
1
2022-02-12T08:09:30.000Z
2022-02-12T08:09:30.000Z
aws-cpp-sdk-macie2/include/aws/macie2/model/TagScopeTerm.h
perfectrecall/aws-sdk-cpp
fb8cbebf2fd62720b65aeff841ad2950e73d8ebd
[ "Apache-2.0" ]
1
2021-10-14T16:57:00.000Z
2021-10-18T10:47:24.000Z
aws-cpp-sdk-macie2/include/aws/macie2/model/TagScopeTerm.h
ravindra-wagh/aws-sdk-cpp
7d5ff01b3c3b872f31ca98fb4ce868cd01e97696
[ "Apache-2.0" ]
1
2021-11-09T11:58:03.000Z
2021-11-09T11:58:03.000Z
/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #pragma once #include <aws/macie2/Macie2_EXPORTS.h> #include <aws/macie2/model/JobComparator.h> #include <aws/core/utils/memory/stl/AWSString.h> #include <aws/core/utils/memory/stl/AWSVector.h> #include <aws/macie2/model/TagTarget.h> #include <aws/macie2/model/TagValuePair.h> #include <utility> namespace Aws { namespace Utils { namespace Json { class JsonValue; class JsonView; } // namespace Json } // namespace Utils namespace Macie2 { namespace Model { /** * <p>Specifies a tag-based condition that determines whether an S3 object is * included or excluded from a classification job.</p><p><h3>See Also:</h3> <a * href="http://docs.aws.amazon.com/goto/WebAPI/macie2-2020-01-01/TagScopeTerm">AWS * API Reference</a></p> */ class AWS_MACIE2_API TagScopeTerm { public: TagScopeTerm(); TagScopeTerm(Aws::Utils::Json::JsonView jsonValue); TagScopeTerm& operator=(Aws::Utils::Json::JsonView jsonValue); Aws::Utils::Json::JsonValue Jsonize() const; /** * <p>The operator to use in the condition. Valid values are EQ (equals) or NE (not * equals).</p> */ inline const JobComparator& GetComparator() const{ return m_comparator; } /** * <p>The operator to use in the condition. Valid values are EQ (equals) or NE (not * equals).</p> */ inline bool ComparatorHasBeenSet() const { return m_comparatorHasBeenSet; } /** * <p>The operator to use in the condition. Valid values are EQ (equals) or NE (not * equals).</p> */ inline void SetComparator(const JobComparator& value) { m_comparatorHasBeenSet = true; m_comparator = value; } /** * <p>The operator to use in the condition. Valid values are EQ (equals) or NE (not * equals).</p> */ inline void SetComparator(JobComparator&& value) { m_comparatorHasBeenSet = true; m_comparator = std::move(value); } /** * <p>The operator to use in the condition. Valid values are EQ (equals) or NE (not * equals).</p> */ inline TagScopeTerm& WithComparator(const JobComparator& value) { SetComparator(value); return *this;} /** * <p>The operator to use in the condition. Valid values are EQ (equals) or NE (not * equals).</p> */ inline TagScopeTerm& WithComparator(JobComparator&& value) { SetComparator(std::move(value)); return *this;} /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline const Aws::String& GetKey() const{ return m_key; } /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline bool KeyHasBeenSet() const { return m_keyHasBeenSet; } /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline void SetKey(const Aws::String& value) { m_keyHasBeenSet = true; m_key = value; } /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline void SetKey(Aws::String&& value) { m_keyHasBeenSet = true; m_key = std::move(value); } /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline void SetKey(const char* value) { m_keyHasBeenSet = true; m_key.assign(value); } /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline TagScopeTerm& WithKey(const Aws::String& value) { SetKey(value); return *this;} /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline TagScopeTerm& WithKey(Aws::String&& value) { SetKey(std::move(value)); return *this;} /** * <p>The object property to use in the condition. The only valid value is TAG.</p> */ inline TagScopeTerm& WithKey(const char* value) { SetKey(value); return *this;} /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline const Aws::Vector<TagValuePair>& GetTagValues() const{ return m_tagValues; } /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline bool TagValuesHasBeenSet() const { return m_tagValuesHasBeenSet; } /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline void SetTagValues(const Aws::Vector<TagValuePair>& value) { m_tagValuesHasBeenSet = true; m_tagValues = value; } /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline void SetTagValues(Aws::Vector<TagValuePair>&& value) { m_tagValuesHasBeenSet = true; m_tagValues = std::move(value); } /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline TagScopeTerm& WithTagValues(const Aws::Vector<TagValuePair>& value) { SetTagValues(value); return *this;} /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline TagScopeTerm& WithTagValues(Aws::Vector<TagValuePair>&& value) { SetTagValues(std::move(value)); return *this;} /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline TagScopeTerm& AddTagValues(const TagValuePair& value) { m_tagValuesHasBeenSet = true; m_tagValues.push_back(value); return *this; } /** * <p>The tag keys or tag key and value pairs to use in the condition. To specify * only tag keys in a condition, specify the keys in this array and set the value * for each associated tag value to an empty string.</p> */ inline TagScopeTerm& AddTagValues(TagValuePair&& value) { m_tagValuesHasBeenSet = true; m_tagValues.push_back(std::move(value)); return *this; } /** * <p>The type of object to apply the condition to.</p> */ inline const TagTarget& GetTarget() const{ return m_target; } /** * <p>The type of object to apply the condition to.</p> */ inline bool TargetHasBeenSet() const { return m_targetHasBeenSet; } /** * <p>The type of object to apply the condition to.</p> */ inline void SetTarget(const TagTarget& value) { m_targetHasBeenSet = true; m_target = value; } /** * <p>The type of object to apply the condition to.</p> */ inline void SetTarget(TagTarget&& value) { m_targetHasBeenSet = true; m_target = std::move(value); } /** * <p>The type of object to apply the condition to.</p> */ inline TagScopeTerm& WithTarget(const TagTarget& value) { SetTarget(value); return *this;} /** * <p>The type of object to apply the condition to.</p> */ inline TagScopeTerm& WithTarget(TagTarget&& value) { SetTarget(std::move(value)); return *this;} private: JobComparator m_comparator; bool m_comparatorHasBeenSet; Aws::String m_key; bool m_keyHasBeenSet; Aws::Vector<TagValuePair> m_tagValues; bool m_tagValuesHasBeenSet; TagTarget m_target; bool m_targetHasBeenSet; }; } // namespace Model } // namespace Macie2 } // namespace Aws
36.320175
148
0.665137
e78761831129741bab11c3e52363ddd2e89decce
14,973
c
C
XFree86-3.3/xc/programs/Xserver/iplan2p4/iplcmap.c
tharindusathis/sourcecodes-of-CodeReadingTheOpenSourcePerspective
1b0172cdb78757fd17898503aaf6ce03d940ef28
[ "Apache-1.1" ]
46
2015-12-04T17:12:58.000Z
2022-03-11T04:30:49.000Z
XFree86-3.3/xc/programs/Xserver/iplan2p4/iplcmap.c
tharindusathis/sourcecodes-of-CodeReadingTheOpenSourcePerspective
1b0172cdb78757fd17898503aaf6ce03d940ef28
[ "Apache-1.1" ]
null
null
null
XFree86-3.3/xc/programs/Xserver/iplan2p4/iplcmap.c
tharindusathis/sourcecodes-of-CodeReadingTheOpenSourcePerspective
1b0172cdb78757fd17898503aaf6ce03d940ef28
[ "Apache-1.1" ]
23
2016-10-24T09:18:14.000Z
2022-02-25T02:11:35.000Z
/* $XFree86: xc/programs/Xserver/iplan2p4/iplcmap.c,v 3.0 1996/08/18 01:54:40 dawes Exp $ */ /* $XConsortium: iplcmap.c,v 4.19 94/04/17 20:28:46 dpw Exp $ */ /************************************************************ Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright no- tice appear in all copies and that both that copyright no- tice and this permission notice appear in supporting docu- mentation, and that the names of Sun or X Consortium not be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. Sun and X Consortium make no representations about the suitability of this software for any purpose. It is provided "as is" without any express or implied warranty. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- ABLE FOR ANY SPECIAL, 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. ********************************************************/ /* Modified nov 94 by Martin Schaller (Martin_Schaller@maus.r.de) for use with interleaved planes */ #include "X.h" #include "Xproto.h" #include "scrnintstr.h" #include "colormapst.h" #include "resource.h" #ifdef STATIC_COLOR static ColormapPtr InstalledMaps[MAXSCREENS]; int iplListInstalledColormaps(pScreen, pmaps) ScreenPtr pScreen; Colormap *pmaps; { /* By the time we are processing requests, we can guarantee that there * is always a colormap installed */ *pmaps = InstalledMaps[pScreen->myNum]->mid; return (1); } void iplInstallColormap(pmap) ColormapPtr pmap; { int index = pmap->pScreen->myNum; ColormapPtr oldpmap = InstalledMaps[index]; if(pmap != oldpmap) { /* Uninstall pInstalledMap. No hardware changes required, just * notify all interested parties. */ if(oldpmap != (ColormapPtr)None) WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid); /* Install pmap */ InstalledMaps[index] = pmap; WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid); } } void iplUninstallColormap(pmap) ColormapPtr pmap; { int index = pmap->pScreen->myNum; ColormapPtr curpmap = InstalledMaps[index]; if(pmap == curpmap) { if (pmap->mid != pmap->pScreen->defColormap) { curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap, RT_COLORMAP); (*pmap->pScreen->InstallColormap)(curpmap); } } } #endif void iplResolveColor(pred, pgreen, pblue, pVisual) unsigned short *pred, *pgreen, *pblue; register VisualPtr pVisual; { int shift = 16 - pVisual->bitsPerRGBValue; unsigned lim = (1 << pVisual->bitsPerRGBValue) - 1; if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor)) { /* rescale to rgb bits */ *pred = ((*pred >> shift) * 65535) / lim; *pgreen = ((*pgreen >> shift) * 65535) / lim; *pblue = ((*pblue >> shift) * 65535) / lim; } else if (pVisual->class == GrayScale) { /* rescale to gray then rgb bits */ *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100; *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim; } else if (pVisual->class == StaticGray) { unsigned limg = pVisual->ColormapEntries - 1; /* rescale to gray then [0..limg] then [0..65535] then rgb bits */ *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100; *pred = ((((*pred * (limg + 1))) >> 16) * 65535) / limg; *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim; } else { unsigned limr, limg, limb; limr = pVisual->redMask >> pVisual->offsetRed; limg = pVisual->greenMask >> pVisual->offsetGreen; limb = pVisual->blueMask >> pVisual->offsetBlue; /* rescale to [0..limN] then [0..65535] then rgb bits */ *pred = ((((((*pred * (limr + 1)) >> 16) * 65535) / limr) >> shift) * 65535) / lim; *pgreen = ((((((*pgreen * (limg + 1)) >> 16) * 65535) / limg) >> shift) * 65535) / lim; *pblue = ((((((*pblue * (limb + 1)) >> 16) * 65535) / limb) >> shift) * 65535) / lim; } } Bool iplInitializeColormap(pmap) register ColormapPtr pmap; { register unsigned i; register VisualPtr pVisual; unsigned lim, maxent, shift; pVisual = pmap->pVisual; lim = (1 << pVisual->bitsPerRGBValue) - 1; shift = 16 - pVisual->bitsPerRGBValue; maxent = pVisual->ColormapEntries - 1; if (pVisual->class == TrueColor) { unsigned limr, limg, limb; limr = pVisual->redMask >> pVisual->offsetRed; limg = pVisual->greenMask >> pVisual->offsetGreen; limb = pVisual->blueMask >> pVisual->offsetBlue; for(i = 0; i <= maxent; i++) { /* rescale to [0..65535] then rgb bits */ pmap->red[i].co.local.red = ((((i * 65535) / limr) >> shift) * 65535) / lim; pmap->green[i].co.local.green = ((((i * 65535) / limg) >> shift) * 65535) / lim; pmap->blue[i].co.local.blue = ((((i * 65535) / limb) >> shift) * 65535) / lim; } } else if (pVisual->class == StaticColor) { unsigned limr, limg, limb; limr = pVisual->redMask >> pVisual->offsetRed; limg = pVisual->greenMask >> pVisual->offsetGreen; limb = pVisual->blueMask >> pVisual->offsetBlue; for(i = 0; i <= maxent; i++) { /* rescale to [0..65535] then rgb bits */ pmap->red[i].co.local.red = ((((((i & pVisual->redMask) >> pVisual->offsetRed) * 65535) / limr) >> shift) * 65535) / lim; pmap->red[i].co.local.green = ((((((i & pVisual->greenMask) >> pVisual->offsetGreen) * 65535) / limg) >> shift) * 65535) / lim; pmap->red[i].co.local.blue = ((((((i & pVisual->blueMask) >> pVisual->offsetBlue) * 65535) / limb) >> shift) * 65535) / lim; } } else if (pVisual->class == StaticGray) { for(i = 0; i <= maxent; i++) { /* rescale to [0..65535] then rgb bits */ pmap->red[i].co.local.red = ((((i * 65535) / maxent) >> shift) * 65535) / lim; pmap->red[i].co.local.green = pmap->red[i].co.local.red; pmap->red[i].co.local.blue = pmap->red[i].co.local.red; } } return TRUE; } /* When simulating DirectColor on PseudoColor hardware, multiple entries of the colormap must be updated */ #define AddElement(mask) { \ pixel = red | green | blue; \ for (i = 0; i < nresult; i++) \ if (outdefs[i].pixel == pixel) \ break; \ if (i == nresult) \ { \ nresult++; \ outdefs[i].pixel = pixel; \ outdefs[i].flags = 0; \ } \ outdefs[i].flags |= (mask); \ outdefs[i].red = pmap->red[red >> pVisual->offsetRed].co.local.red; \ outdefs[i].green = pmap->green[green >> pVisual->offsetGreen].co.local.green; \ outdefs[i].blue = pmap->blue[blue >> pVisual->offsetBlue].co.local.blue; \ } iplExpandDirectColors (pmap, ndef, indefs, outdefs) ColormapPtr pmap; int ndef; xColorItem *indefs, *outdefs; { int minred, mingreen, minblue; register int red, green, blue; int maxred, maxgreen, maxblue; int stepred, stepgreen, stepblue; VisualPtr pVisual; register int pixel; register int nresult; register int i; pVisual = pmap->pVisual; stepred = 1 << pVisual->offsetRed; stepgreen = 1 << pVisual->offsetGreen; stepblue = 1 << pVisual->offsetBlue; maxred = pVisual->redMask; maxgreen = pVisual->greenMask; maxblue = pVisual->blueMask; nresult = 0; for (;ndef--; indefs++) { if (indefs->flags & DoRed) { red = indefs->pixel & pVisual->redMask; for (green = 0; green <= maxgreen; green += stepgreen) { for (blue = 0; blue <= maxblue; blue += stepblue) { AddElement (DoRed) } } } if (indefs->flags & DoGreen) { green = indefs->pixel & pVisual->greenMask; for (red = 0; red <= maxred; red += stepred) { for (blue = 0; blue <= maxblue; blue += stepblue) { AddElement (DoGreen) } } } if (indefs->flags & DoBlue) { blue = indefs->pixel & pVisual->blueMask; for (red = 0; red <= maxred; red += stepred) { for (green = 0; green <= maxgreen; green += stepgreen) { AddElement (DoBlue) } } } } return nresult; } Bool iplCreateDefColormap(pScreen) ScreenPtr pScreen; { unsigned short zero = 0, ones = 0xFFFF; VisualPtr pVisual; ColormapPtr cmap; Pixel wp, bp; for (pVisual = pScreen->visuals; pVisual->vid != pScreen->rootVisual; pVisual++) ; if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap, (pVisual->class & DynamicClass) ? AllocNone : AllocAll, 0) != Success) return FALSE; wp = pScreen->whitePixel; bp = pScreen->blackPixel; if ((AllocColor(cmap, &ones, &ones, &ones, &wp, 0) != Success) || (AllocColor(cmap, &zero, &zero, &zero, &bp, 0) != Success)) return FALSE; pScreen->whitePixel = wp; pScreen->blackPixel = bp; (*pScreen->InstallColormap)(cmap); return TRUE; } extern int defaultColorVisualClass; #define _RZ(d) ((d + 2) / 3) #define _RS(d) 0 #define _RM(d) ((1 << _RZ(d)) - 1) #define _GZ(d) ((d - _RZ(d) + 1) / 2) #define _GS(d) _RZ(d) #define _GM(d) (((1 << _GZ(d)) - 1) << _GS(d)) #define _BZ(d) (d - _RZ(d) - _GZ(d)) #define _BS(d) (_RZ(d) + _GZ(d)) #define _BM(d) (((1 << _BZ(d)) - 1) << _BS(d)) #define _CE(d) (1 << _RZ(d)) #define MAX_PSEUDO_DEPTH 10 /* largest DAC size I know */ #define StaticGrayMask (1 << StaticGray) #define GrayScaleMask (1 << GrayScale) #define StaticColorMask (1 << StaticColor) #define PseudoColorMask (1 << PseudoColor) #define TrueColorMask (1 << TrueColor) #define DirectColorMask (1 << DirectColor) #define ALL_VISUALS (StaticGrayMask|\ GrayScaleMask|\ StaticColorMask|\ PseudoColorMask|\ TrueColorMask|\ DirectColorMask) #define LARGE_VISUALS (TrueColorMask|\ DirectColorMask) typedef struct _iplVisuals { struct _iplVisuals *next; int depth; int bitsPerRGB; int visuals; int count; } iplVisualsRec, *iplVisualsPtr; static int iplVisualPriority[] = { PseudoColor, DirectColor, GrayScale, StaticColor, TrueColor, StaticGray }; #define NUM_PRIORITY 6 static iplVisualsPtr iplVisuals; Bool iplSetVisualTypes (depth, visuals, bitsPerRGB) int depth; int visuals; { iplVisualsPtr new, *prev, v; int count; new = (iplVisualsPtr) xalloc (sizeof *new); if (!new) return FALSE; new->next = 0; new->depth = depth; new->visuals = visuals; new->bitsPerRGB = bitsPerRGB; count = (visuals >> 1) & 033333333333; count = visuals - count - ((count >> 1) & 033333333333); count = (((count + (count >> 3)) & 030707070707) % 077); /* HAKMEM 169 */ new->count = count; for (prev = &iplVisuals; v = *prev; prev = &v->next); *prev = new; return TRUE; } /* * Given a list of formats for a screen, create a list * of visuals and depths for the screen which coorespond to * the set which can be used with this version of ipl. */ Bool iplInitVisuals (visualp, depthp, nvisualp, ndepthp, rootDepthp, defaultVisp, sizes, bitsPerRGB) VisualPtr *visualp; DepthPtr *depthp; int *nvisualp, *ndepthp; int *rootDepthp; VisualID *defaultVisp; unsigned long sizes; int bitsPerRGB; { int i, j, k; VisualPtr visual; DepthPtr depth; VisualID *vid; int d, b; int f; int ndepth, nvisual; int nvtype; int vtype; VisualID defaultVisual; iplVisualsPtr visuals, nextVisuals; /* none specified, we'll guess from pixmap formats */ if (!iplVisuals) { for (f = 0; f < screenInfo.numPixmapFormats; f++) { d = screenInfo.formats[f].depth; b = screenInfo.formats[f].bitsPerPixel; if (sizes & (1 << (b - 1))) { if (d > MAX_PSEUDO_DEPTH) vtype = LARGE_VISUALS; else if (d == 1) vtype = StaticGrayMask; else vtype = ALL_VISUALS; } else vtype = 0; if (!iplSetVisualTypes (d, vtype, bitsPerRGB)) return FALSE; } } nvisual = 0; ndepth = 0; for (visuals = iplVisuals; visuals; visuals = nextVisuals) { nextVisuals = visuals->next; ndepth++; nvisual += visuals->count; } depth = (DepthPtr) xalloc (ndepth * sizeof (DepthRec)); visual = (VisualPtr) xalloc (nvisual * sizeof (VisualRec)); if (!depth || !visual) { xfree (depth); xfree (visual); return FALSE; } *depthp = depth; *visualp = visual; *ndepthp = ndepth; *nvisualp = nvisual; for (visuals = iplVisuals; visuals; visuals = nextVisuals) { nextVisuals = visuals->next; d = visuals->depth; vtype = visuals->visuals; nvtype = visuals->count; vid = NULL; if (nvtype) { vid = (VisualID *) xalloc (nvtype * sizeof (VisualID)); if (!vid) return FALSE; } depth->depth = d; depth->numVids = nvtype; depth->vids = vid; depth++; for (i = 0; i < NUM_PRIORITY; i++) { if (! (vtype & (1 << iplVisualPriority[i]))) continue; visual->class = iplVisualPriority[i]; visual->bitsPerRGBValue = visuals->bitsPerRGB; visual->ColormapEntries = 1 << d; visual->nplanes = d; visual->vid = *vid = FakeClientID (0); switch (visual->class) { case PseudoColor: case GrayScale: case StaticGray: visual->redMask = 0; visual->greenMask = 0; visual->blueMask = 0; visual->offsetRed = 0; visual->offsetGreen = 0; visual->offsetBlue = 0; break; case DirectColor: case TrueColor: visual->ColormapEntries = _CE(d); /* fall through */ case StaticColor: visual->redMask = _RM(d); visual->greenMask = _GM(d); visual->blueMask = _BM(d); visual->offsetRed = _RS(d); visual->offsetGreen = _GS(d); visual->offsetBlue = _BS(d); } vid++; visual++; } xfree (visuals); } iplVisuals = NULL; visual = *visualp; depth = *depthp; for (i = 0; i < ndepth; i++) { if (*rootDepthp && *rootDepthp != depth[i].depth) continue; for (j = 0; j < depth[i].numVids; j++) { for (k = 0; k < nvisual; k++) if (visual[k].vid == depth[i].vids[j]) break; if (k == nvisual) continue; if (defaultColorVisualClass < 0 || visual[k].class == defaultColorVisualClass) break; } if (j != depth[i].numVids) break; } if (i == ndepth) { i = 0; j = 0; } *rootDepthp = depth[i].depth; *defaultVisp = depth[i].vids[j]; return TRUE; }
27.372943
95
0.607493
c8ce677b5b092f47d583f5196bf824322daa1e5f
24,475
c
C
palacios/src/vnet/vnet_core.c
jnouyang/palacios
e06aee743c38e53901d2e80590d687e5b93f93f2
[ "BSD-3-Clause" ]
1
2015-07-14T01:02:15.000Z
2015-07-14T01:02:15.000Z
palacios/src/vnet/vnet_core.c
jnouyang/palacios
e06aee743c38e53901d2e80590d687e5b93f93f2
[ "BSD-3-Clause" ]
null
null
null
palacios/src/vnet/vnet_core.c
jnouyang/palacios
e06aee743c38e53901d2e80590d687e5b93f93f2
[ "BSD-3-Clause" ]
null
null
null
/* * This file is part of the Palacios Virtual Machine Monitor developed * by the V3VEE Project with funding from the United States National * Science Foundation and the Department of Energy. * * The V3VEE Project is a joint project between Northwestern University * and the University of New Mexico. You can find out more at * http://www.v3vee.org * * Copyright (c) 2010, Lei Xia <lxia@northwestern.edu> * Copyright (c) 2009, Yuan Tang <ytang@northwestern.edu> * Copyright (c) 2009, The V3VEE Project <http://www.v3vee.org> * All rights reserved * * Author: Lei Xia <lxia@northwestern.edu> * Yuan Tang <ytang@northwestern.edu> * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "V3VEE_LICENSE". */ #include <vnet/vnet.h> #include <vnet/vnet_hashtable.h> #include <vnet/vnet_host.h> #include <vnet/vnet_vmm.h> #include <palacios/vmm_queue.h> #ifndef V3_CONFIG_DEBUG_VNET #undef PrintDebug #define PrintDebug(fmt, args...) #endif #define VNET_YIELD_USEC 1000 int net_debug = 0; struct eth_hdr { uint8_t dst_mac[ETH_ALEN]; uint8_t src_mac[ETH_ALEN]; uint16_t type; /* indicates layer 3 protocol type */ } __attribute__((packed)); struct vnet_dev { int dev_id; uint8_t mac_addr[ETH_ALEN]; struct v3_vm_info * vm; struct v3_vnet_dev_ops dev_ops; int poll; #define VNET_MAX_QUOTE 64 int quote; void * private_data; struct list_head node; } __attribute__((packed)); struct vnet_brg_dev { struct v3_vm_info * vm; struct v3_vnet_bridge_ops brg_ops; uint8_t type; void * private_data; } __attribute__((packed)); struct vnet_route_info { struct v3_vnet_route route_def; struct vnet_dev * dst_dev; struct vnet_dev * src_dev; uint32_t idx; struct list_head node; struct list_head match_node; // used for route matching }; struct route_list { uint8_t hash_buf[VNET_HASH_SIZE]; uint32_t num_routes; struct vnet_route_info * routes[0]; } __attribute__((packed)); struct queue_entry{ uint8_t use; struct v3_vnet_pkt pkt; uint8_t * data; uint32_t size_alloc; }; static struct { struct list_head routes; struct list_head devs; uint8_t status; uint32_t num_routes; uint32_t route_idx; uint32_t num_devs; uint32_t dev_idx; struct vnet_brg_dev * bridge; vnet_lock_t lock; struct vnet_stat stats; /* device queue that are waiting to be polled */ struct v3_queue * poll_devs; struct vnet_thread * pkt_flush_thread; struct hashtable * route_cache; } vnet_state; #ifdef V3_CONFIG_DEBUG_VNET static inline void mac2str(uint8_t * mac, char * buf) { snprintf(buf, 100, "%2x:%2x:%2x:%2x:%2x:%2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } static void print_route(struct v3_vnet_route * route){ char str[50]; mac2str(route->src_mac, str); PrintDebug("Src Mac (%s), src_qual (%d)\n", str, route->src_mac_qual); mac2str(route->dst_mac, str); PrintDebug("Dst Mac (%s), dst_qual (%d)\n", str, route->dst_mac_qual); PrintDebug("Src dev id (%d), src type (%d)", route->src_id, route->src_type); PrintDebug("Dst dev id (%d), dst type (%d)\n", route->dst_id, route->dst_type); } static void dump_routes(){ struct vnet_route_info *route; PrintDebug("\n========Dump routes starts ============\n"); list_for_each_entry(route, &(vnet_state.routes), node) { PrintDebug("\nroute %d:\n", route->idx); print_route(&(route->route_def)); if (route->route_def.dst_type == LINK_INTERFACE) { PrintDebug("dst_dev (%p), dst_dev_id (%d), dst_dev_ops(%p), dst_dev_data (%p)\n", route->dst_dev, route->dst_dev->dev_id, (void *)&(route->dst_dev->dev_ops), route->dst_dev->private_data); } } PrintDebug("\n========Dump routes end ============\n"); } #endif /* * A VNET packet is a packed struct with the hashed fields grouped together. * This means we can generate the hash from an offset into the pkt struct */ static inline uint_t hash_fn(addr_t hdr_ptr) { uint8_t * hdr_buf = (uint8_t *)hdr_ptr; return vnet_hash_buffer(hdr_buf, VNET_HASH_SIZE); } static inline int hash_eq(addr_t key1, addr_t key2) { return (memcmp((uint8_t *)key1, (uint8_t *)key2, VNET_HASH_SIZE) == 0); } static int add_route_to_cache(const struct v3_vnet_pkt * pkt, struct route_list * routes) { memcpy(routes->hash_buf, pkt->hash_buf, VNET_HASH_SIZE); if (vnet_htable_insert(vnet_state.route_cache, (addr_t)routes->hash_buf, (addr_t)routes) == 0) { PrintError("VNET/P Core: Failed to insert new route entry to the cache\n"); return -1; } return 0; } static int clear_hash_cache() { vnet_free_htable(vnet_state.route_cache, 1, 1); vnet_state.route_cache = vnet_create_htable(0, &hash_fn, &hash_eq); return 0; } static int look_into_cache(const struct v3_vnet_pkt * pkt, struct route_list ** routes) { *routes = (struct route_list *)vnet_htable_search(vnet_state.route_cache, (addr_t)(pkt->hash_buf)); return 0; } static struct vnet_dev * dev_by_id(int idx) { struct vnet_dev * dev = NULL; list_for_each_entry(dev, &(vnet_state.devs), node) { if (dev->dev_id == idx) { return dev; } } return NULL; } static struct vnet_dev * dev_by_mac(uint8_t * mac) { struct vnet_dev * dev = NULL; list_for_each_entry(dev, &(vnet_state.devs), node) { if (!compare_ethaddr(dev->mac_addr, mac)){ return dev; } } return NULL; } int v3_vnet_find_dev(uint8_t * mac) { struct vnet_dev * dev = NULL; dev = dev_by_mac(mac); if(dev != NULL) { return dev->dev_id; } return -1; } int v3_vnet_add_route(struct v3_vnet_route route) { struct vnet_route_info * new_route = NULL; vnet_intr_flags_t flags; new_route = (struct vnet_route_info *)Vnet_Malloc(sizeof(struct vnet_route_info)); if (!new_route) { PrintError("Cannot allocate new route\n"); return -1; } memset(new_route, 0, sizeof(struct vnet_route_info)); #ifdef V3_CONFIG_DEBUG_VNET PrintDebug("VNET/P Core: add_route_entry:\n"); print_route(&route); #endif memcpy(new_route->route_def.src_mac, route.src_mac, ETH_ALEN); memcpy(new_route->route_def.dst_mac, route.dst_mac, ETH_ALEN); new_route->route_def.src_mac_qual = route.src_mac_qual; new_route->route_def.dst_mac_qual = route.dst_mac_qual; new_route->route_def.dst_type = route.dst_type; new_route->route_def.src_type = route.src_type; new_route->route_def.src_id = route.src_id; new_route->route_def.dst_id = route.dst_id; if (new_route->route_def.dst_type == LINK_INTERFACE) { new_route->dst_dev = dev_by_id(new_route->route_def.dst_id); } if (new_route->route_def.src_type == LINK_INTERFACE) { new_route->src_dev = dev_by_id(new_route->route_def.src_id); } flags = vnet_lock_irqsave(vnet_state.lock); list_add(&(new_route->node), &(vnet_state.routes)); new_route->idx = ++ vnet_state.route_idx; vnet_state.num_routes ++; vnet_unlock_irqrestore(vnet_state.lock, flags); clear_hash_cache(); #ifdef V3_CONFIG_DEBUG_VNET dump_routes(); #endif return new_route->idx; } void v3_vnet_del_route(uint32_t route_idx){ struct vnet_route_info * route = NULL; vnet_intr_flags_t flags; flags = vnet_lock_irqsave(vnet_state.lock); list_for_each_entry(route, &(vnet_state.routes), node) { Vnet_Print(0, "v3_vnet_del_route, route idx: %d\n", route->idx); if(route->idx == route_idx){ list_del(&(route->node)); Vnet_Free(route); break; } } vnet_unlock_irqrestore(vnet_state.lock, flags); clear_hash_cache(); #ifdef V3_CONFIG_DEBUG_VNET dump_routes(); #endif } /* delete all route entries with specfied src or dst device id */ static void inline del_routes_by_dev(int dev_id){ struct vnet_route_info * route, *tmp_route; vnet_intr_flags_t flags; flags = vnet_lock_irqsave(vnet_state.lock); list_for_each_entry_safe(route, tmp_route, &(vnet_state.routes), node) { if((route->route_def.dst_type == LINK_INTERFACE && route->route_def.dst_id == dev_id) || (route->route_def.src_type == LINK_INTERFACE && route->route_def.src_id == dev_id)){ list_del(&(route->node)); list_del(&(route->match_node)); Vnet_Free(route); } } vnet_unlock_irqrestore(vnet_state.lock, flags); } /* At the end allocate a route_list * This list will be inserted into the cache so we don't need to free it */ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { struct vnet_route_info * route = NULL; struct route_list * matches = NULL; int num_matches = 0; int max_rank = 0; struct list_head match_list; struct eth_hdr * hdr = (struct eth_hdr *)(pkt->data); // uint8_t src_type = pkt->src_type; // uint32_t src_link = pkt->src_id; #ifdef V3_CONFIG_DEBUG_VNET { char dst_str[100]; char src_str[100]; mac2str(hdr->src_mac, src_str); mac2str(hdr->dst_mac, dst_str); PrintDebug("VNET/P Core: match_route. pkt: SRC(%s), DEST(%s)\n", src_str, dst_str); } #endif INIT_LIST_HEAD(&match_list); #define UPDATE_MATCHES(rank) do { \ if (max_rank < (rank)) { \ max_rank = (rank); \ INIT_LIST_HEAD(&match_list); \ \ list_add(&(route->match_node), &match_list); \ num_matches = 1; \ } else if (max_rank == (rank)) { \ list_add(&(route->match_node), &match_list); \ num_matches++; \ } \ } while (0) list_for_each_entry(route, &(vnet_state.routes), node) { struct v3_vnet_route * route_def = &(route->route_def); /* // CHECK SOURCE TYPE HERE if ( (route_def->src_type != LINK_ANY) && ( (route_def->src_type != src_type) || ( (route_def->src_id != src_link) && (route_def->src_id != -1)))) { continue; } */ if ((route_def->dst_mac_qual == MAC_ANY) && (route_def->src_mac_qual == MAC_ANY)) { UPDATE_MATCHES(3); } if (memcmp(route_def->src_mac, hdr->src_mac, 6) == 0) { if (route_def->src_mac_qual != MAC_NOT) { if (route_def->dst_mac_qual == MAC_ANY) { UPDATE_MATCHES(6); } else if (route_def->dst_mac_qual != MAC_NOT && memcmp(route_def->dst_mac, hdr->dst_mac, 6) == 0) { UPDATE_MATCHES(8); } } } if (memcmp(route_def->dst_mac, hdr->dst_mac, 6) == 0) { if (route_def->dst_mac_qual != MAC_NOT) { if (route_def->src_mac_qual == MAC_ANY) { UPDATE_MATCHES(6); } else if ((route_def->src_mac_qual != MAC_NOT) && (memcmp(route_def->src_mac, hdr->src_mac, 6) == 0)) { UPDATE_MATCHES(8); } } } if ((route_def->dst_mac_qual == MAC_NOT) && (memcmp(route_def->dst_mac, hdr->dst_mac, 6) != 0)) { if (route_def->src_mac_qual == MAC_ANY) { UPDATE_MATCHES(5); } else if ((route_def->src_mac_qual != MAC_NOT) && (memcmp(route_def->src_mac, hdr->src_mac, 6) == 0)) { UPDATE_MATCHES(7); } } if ((route_def->src_mac_qual == MAC_NOT) && (memcmp(route_def->src_mac, hdr->src_mac, 6) != 0)) { if (route_def->dst_mac_qual == MAC_ANY) { UPDATE_MATCHES(5); } else if ((route_def->dst_mac_qual != MAC_NOT) && (memcmp(route_def->dst_mac, hdr->dst_mac, 6) == 0)) { UPDATE_MATCHES(7); } } // Default route if ( (memcmp(route_def->src_mac, hdr->src_mac, 6) == 0) && (route_def->dst_mac_qual == MAC_NONE)) { UPDATE_MATCHES(4); } } PrintDebug("VNET/P Core: match_route: Matches=%d\n", num_matches); if (num_matches <= 0) { return NULL; } matches = (struct route_list *)Vnet_Malloc(sizeof(struct route_list) + (sizeof(struct vnet_route_info *) * num_matches)); if (!matches) { PrintError("VNET/P Core: Unable to allocate matches\n"); return NULL; } matches->num_routes = num_matches; { int i = 0; list_for_each_entry(route, &match_list, match_node) { matches->routes[i++] = route; } } return matches; } int v3_vnet_query_header(uint8_t src_mac[6], uint8_t dest_mac[6], int recv, // 0 = send, 1=recv struct v3_vnet_header *header) { struct route_list *routes; struct vnet_route_info *r; struct v3_vnet_pkt p; p.size=14; p.data=p.header; memcpy(p.header,dest_mac,6); memcpy(p.header+6,src_mac,6); memset(p.header+12,0,2); p.src_type = LINK_EDGE; p.src_id = 0; memcpy(header->src_mac,src_mac,6); memcpy(header->dst_mac,dest_mac,6); look_into_cache(&p,&routes); if (!routes) { routes = match_route(&p); if (!routes) { PrintError("Cannot match route\n"); header->header_type=VNET_HEADER_NOMATCH; header->header_len=0; return -1; } else { add_route_to_cache(&p,routes); } } if (routes->num_routes<1) { PrintError("Less than one route\n"); header->header_type=VNET_HEADER_NOMATCH; header->header_len=0; return -1; } if (routes->num_routes>1) { PrintError("More than one route, building header for the first one only\n"); } r=routes->routes[0]; switch (r->route_def.dst_type) { case LINK_EDGE: { // switch based on the link type // for mac-in-udp, we would want to generate a mac, ip, and udp header // direct transmission // for now we will say we have no encapsulation // header->header_type=VNET_HEADER_NONE; header->header_len=0; header->src_mac_qual=r->route_def.src_mac_qual; header->dst_mac_qual=r->route_def.dst_mac_qual; } return 0; break; case LINK_INTERFACE: // direct transmission // let's guess that it goes to the same interface... header->header_type=VNET_HEADER_NONE; header->header_len=0; header->src_mac_qual=r->route_def.src_mac_qual; header->dst_mac_qual=r->route_def.dst_mac_qual; return 0; break; default: PrintError("Unknown destination type\n"); return -1; break; } } int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { struct route_list * matched_routes = NULL; vnet_intr_flags_t flags; int i; int cpu = V3_Get_CPU(); Vnet_Print(2, "VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n", cpu, pkt->size, pkt->src_id, pkt->src_type, pkt->dst_id, pkt->dst_type); if(net_debug >= 4){ v3_hexdump(pkt->data, pkt->size, NULL, 0); } flags = vnet_lock_irqsave(vnet_state.lock); vnet_state.stats.rx_bytes += pkt->size; vnet_state.stats.rx_pkts++; look_into_cache(pkt, &matched_routes); if (matched_routes == NULL) { PrintDebug("VNET/P Core: sending pkt - matching route\n"); matched_routes = match_route(pkt); if (matched_routes) { add_route_to_cache(pkt, matched_routes); } else { PrintDebug("VNET/P Core: Could not find route for packet... discarding packet\n"); vnet_unlock_irqrestore(vnet_state.lock, flags); return 0; /* do we return -1 here?*/ } } vnet_unlock_irqrestore(vnet_state.lock, flags); PrintDebug("VNET/P Core: send pkt route matches %d\n", matched_routes->num_routes); for (i = 0; i < matched_routes->num_routes; i++) { struct vnet_route_info * route = matched_routes->routes[i]; if (route->route_def.dst_type == LINK_EDGE) { struct vnet_brg_dev * bridge = vnet_state.bridge; pkt->dst_type = LINK_EDGE; pkt->dst_id = route->route_def.dst_id; if (bridge == NULL) { Vnet_Print(2, "VNET/P Core: No active bridge to sent data to\n"); continue; } if(bridge->brg_ops.input(bridge->vm, pkt, bridge->private_data) < 0){ Vnet_Print(2, "VNET/P Core: Packet not sent properly to bridge\n"); continue; } vnet_state.stats.tx_bytes += pkt->size; vnet_state.stats.tx_pkts ++; } else if (route->route_def.dst_type == LINK_INTERFACE) { if (route->dst_dev == NULL){ Vnet_Print(2, "VNET/P Core: No active device to sent data to\n"); continue; } if(route->dst_dev->dev_ops.input(route->dst_dev->vm, pkt, route->dst_dev->private_data) < 0) { Vnet_Print(2, "VNET/P Core: Packet not sent properly\n"); continue; } vnet_state.stats.tx_bytes += pkt->size; vnet_state.stats.tx_pkts ++; } else { Vnet_Print(0, "VNET/P Core: Wrong dst type\n"); } } return 0; } int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, struct v3_vnet_dev_ops * ops, int quote, int poll_state, void * priv_data){ struct vnet_dev * new_dev = NULL; vnet_intr_flags_t flags; new_dev = (struct vnet_dev *)Vnet_Malloc(sizeof(struct vnet_dev)); if (new_dev == NULL) { Vnet_Print(0, "VNET/P Core: Unable to allocate a new device\n"); return -1; } memcpy(new_dev->mac_addr, mac, 6); new_dev->dev_ops.input = ops->input; new_dev->dev_ops.poll = ops->poll; new_dev->private_data = priv_data; new_dev->vm = vm; new_dev->dev_id = 0; new_dev->quote = quote<VNET_MAX_QUOTE ? quote : VNET_MAX_QUOTE; new_dev->poll = poll_state; flags = vnet_lock_irqsave(vnet_state.lock); if (dev_by_mac(mac) == NULL) { list_add(&(new_dev->node), &(vnet_state.devs)); new_dev->dev_id = ++ vnet_state.dev_idx; vnet_state.num_devs ++; if(new_dev->poll) { v3_enqueue(vnet_state.poll_devs, (addr_t)new_dev); } } else { PrintError("VNET/P: Device with the same MAC has already been added\n"); } vnet_unlock_irqrestore(vnet_state.lock, flags); /* if the device was found previosly the id should still be 0 */ if (new_dev->dev_id == 0) { Vnet_Print(0, "VNET/P Core: Device Already exists\n"); return -1; } PrintDebug("VNET/P Core: Add Device: dev_id %d\n", new_dev->dev_id); return new_dev->dev_id; } int v3_vnet_del_dev(int dev_id){ struct vnet_dev * dev = NULL; vnet_intr_flags_t flags; flags = vnet_lock_irqsave(vnet_state.lock); dev = dev_by_id(dev_id); if (dev != NULL){ list_del(&(dev->node)); //del_routes_by_dev(dev_id); vnet_state.num_devs --; } vnet_unlock_irqrestore(vnet_state.lock, flags); Vnet_Free(dev); PrintDebug("VNET/P Core: Removed Device: dev_id %d\n", dev_id); return 0; } int v3_vnet_stat(struct vnet_stat * stats){ stats->rx_bytes = vnet_state.stats.rx_bytes; stats->rx_pkts = vnet_state.stats.rx_pkts; stats->tx_bytes = vnet_state.stats.tx_bytes; stats->tx_pkts = vnet_state.stats.tx_pkts; return 0; } static void deinit_devices_list(){ struct vnet_dev * dev, * tmp; list_for_each_entry_safe(dev, tmp, &(vnet_state.devs), node) { list_del(&(dev->node)); Vnet_Free(dev); } } static void deinit_routes_list(){ struct vnet_route_info * route, * tmp; list_for_each_entry_safe(route, tmp, &(vnet_state.routes), node) { list_del(&(route->node)); list_del(&(route->match_node)); Vnet_Free(route); } } int v3_vnet_add_bridge(struct v3_vm_info * vm, struct v3_vnet_bridge_ops * ops, uint8_t type, void * priv_data) { vnet_intr_flags_t flags; int bridge_free = 0; struct vnet_brg_dev * tmp_bridge = NULL; flags = vnet_lock_irqsave(vnet_state.lock); if (vnet_state.bridge == NULL) { bridge_free = 1; vnet_state.bridge = (void *)1; } vnet_unlock_irqrestore(vnet_state.lock, flags); if (bridge_free == 0) { PrintError("VNET/P Core: Bridge already set\n"); return -1; } tmp_bridge = (struct vnet_brg_dev *)Vnet_Malloc(sizeof(struct vnet_brg_dev)); if (tmp_bridge == NULL) { PrintError("VNET/P Core: Unable to allocate new bridge\n"); vnet_state.bridge = NULL; return -1; } tmp_bridge->vm = vm; tmp_bridge->brg_ops.input = ops->input; tmp_bridge->brg_ops.poll = ops->poll; tmp_bridge->private_data = priv_data; tmp_bridge->type = type; /* make this atomic to avoid possible race conditions */ flags = vnet_lock_irqsave(vnet_state.lock); vnet_state.bridge = tmp_bridge; vnet_unlock_irqrestore(vnet_state.lock, flags); return 0; } void v3_vnet_del_bridge(uint8_t type) { vnet_intr_flags_t flags; struct vnet_brg_dev * tmp_bridge = NULL; flags = vnet_lock_irqsave(vnet_state.lock); if (vnet_state.bridge != NULL && vnet_state.bridge->type == type) { tmp_bridge = vnet_state.bridge; vnet_state.bridge = NULL; } vnet_unlock_irqrestore(vnet_state.lock, flags); if (tmp_bridge) { Vnet_Free(tmp_bridge); } } /* can be instanieoued to multiple threads * that runs on multiple cores * or it could be running on a dedicated side core */ static int vnet_tx_flush(void * args){ struct vnet_dev * dev = NULL; int more; int rc; Vnet_Print(0, "VNET/P Polling Thread Starting ....\n"); // since there are multiple instances of this thread, and only // one queue of pollable devices, our model here will be to synchronize // on that queue, removing devices as we go, and keeping them // then putting them back on the queue when we are done // in this way, multiple instances of this function will never // be polling the same device at the same time struct v3_queue * tq = v3_create_queue(); if (!tq) { PrintError("VNET/P polling thread cannot allocate queue\n"); return -1; } while (!vnet_thread_should_stop()) { more=0; // will indicate if any device has more work for us to do while ((dev = (struct vnet_dev *)v3_dequeue(vnet_state.poll_devs))) { // we are handling this device v3_enqueue(tq,(addr_t)dev); if (dev->poll && dev->dev_ops.poll) { // The device's poll function MUST NOT BLOCK rc = dev->dev_ops.poll(dev->vm, dev->quote, dev->private_data); if (rc<0) { Vnet_Print(0, "VNET/P: poll from device %p error (ignoring) !\n", dev); } else { more |= rc; } } } while ((dev = (struct vnet_dev *)v3_dequeue(tq))) { // now someone else can handle it v3_enqueue(vnet_state.poll_devs, (addr_t)dev); } // Yield regardless of whether we handled any devices - need // to allow other threads to run if (more) { // we have more to do, so we want to get back asap V3_Yield(); } else { // put ourselves briefly to sleep if we we don't have more V3_Yield_Timed(VNET_YIELD_USEC); } } Vnet_Free(tq); Vnet_Print(0, "VNET/P Polling Thread Done.\n"); return 0; } int v3_init_vnet() { memset(&vnet_state, 0, sizeof(vnet_state)); INIT_LIST_HEAD(&(vnet_state.routes)); INIT_LIST_HEAD(&(vnet_state.devs)); vnet_state.num_devs = 0; vnet_state.num_routes = 0; if (vnet_lock_init(&(vnet_state.lock)) == -1){ PrintError("VNET/P: Fails to initiate lock\n"); } vnet_state.route_cache = vnet_create_htable(0, &hash_fn, &hash_eq); if (vnet_state.route_cache == NULL) { PrintError("VNET/P: Fails to initiate route cache\n"); return -1; } vnet_state.poll_devs = v3_create_queue(); vnet_state.pkt_flush_thread = vnet_start_thread(vnet_tx_flush, NULL, "vnetd-1"); PrintDebug("VNET/P is initiated\n"); return 0; } void v3_deinit_vnet() { v3_deinit_queue(vnet_state.poll_devs); Vnet_Free(vnet_state.poll_devs); PrintDebug("Stopping flush thread\n"); // This will pause until the flush thread is gone vnet_thread_stop(vnet_state.pkt_flush_thread); // At this point there should be no lock-holder Vnet_Free(vnet_state.poll_devs); PrintDebug("Deiniting Device List\n"); // close any devices we have open deinit_devices_list(); PrintDebug("Deiniting Route List\n"); // remove any routes we have deinit_routes_list(); PrintDebug("Freeing hash table\n"); // remove the hash table vnet_free_htable(vnet_state.route_cache, 1, 1); PrintDebug("Removing Bridge\n"); // remove bridge if it was added if (vnet_state.bridge) { Vnet_Free(vnet_state.bridge); } PrintDebug("Deleting lock\n"); // eliminate the lock vnet_lock_deinit(&(vnet_state.lock)); }
25.468262
108
0.651318
c8e6d45481a04b770fb8be5ce19a50593f0ae640
1,953
c
C
firmware/coreboot/src/northbridge/intel/fsp_rangeley/acpi.c
fabiojna02/OpenCellular
45b6a202d6b2e2485c89955b9a6da920c4d56ddb
[ "CC-BY-4.0", "BSD-3-Clause" ]
1
2019-11-04T07:11:25.000Z
2019-11-04T07:11:25.000Z
firmware/coreboot/src/northbridge/intel/fsp_rangeley/acpi.c
fabiojna02/OpenCellular
45b6a202d6b2e2485c89955b9a6da920c4d56ddb
[ "CC-BY-4.0", "BSD-3-Clause" ]
13
2018-10-12T21:29:09.000Z
2018-10-25T20:06:51.000Z
firmware/coreboot/src/northbridge/intel/fsp_rangeley/acpi.c
fabiojna02/OpenCellular
45b6a202d6b2e2485c89955b9a6da920c4d56ddb
[ "CC-BY-4.0", "BSD-3-Clause" ]
null
null
null
/* * This file is part of the coreboot project. * * Copyright (C) 2007-2009 coresystems GmbH * Copyright (C) 2012 The Chromium OS Authors * Copyright (C) 2013 Sage Electronic Engineering, LLC * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2 of * the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <types.h> #include <string.h> #include <console/console.h> #include <arch/io.h> #include <arch/acpi.h> #include <device/device.h> #include <device/pci.h> #include <device/pci_ids.h> #include <arch/acpi.h> #include <arch/acpigen.h> #include "northbridge.h" unsigned long acpi_fill_mcfg(unsigned long current) { struct device *dev; u32 pciexbar = 0; u32 pciexbar_reg; int max_buses; int pci_dev_id; for (pci_dev_id = PCI_DEVICE_ID_RG_MIN; pci_dev_id <= PCI_DEVICE_ID_RG_MAX; pci_dev_id++) { dev = dev_find_device(PCI_VENDOR_ID_INTEL, pci_dev_id, 0); if (dev) break; } if (!dev) return current; pciexbar_reg = sideband_read(B_UNIT, BECREG); /* MMCFG not supported or not enabled. */ if (!(pciexbar_reg & (1 << 0))) return current; /* 256MB ECAM range */ pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); max_buses = 256; current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, pciexbar, 0x0, 0x0, max_buses - 1); return current; } void northbridge_acpi_fill_ssdt_generator(struct device *device) { u32 bmbound; char pscope[] = "\\_SB.PCI0"; bmbound = sideband_read(B_UNIT, BMBOUND); acpigen_write_scope(pscope); acpigen_write_name_dword("BMBD", bmbound); acpigen_pop_len(); generate_cpu_entries(device); }
26.04
92
0.722478
bd88b464e3b8d436952bfd38c69c458cb6cfb011
456,390
c
C
WolfSSL-BESSPIN/src/internal.c
draperlaboratory/hope-FreeRTOS-RISC-V_Galois_demo
8607c3d80a8e3e2e0be2570a09eb1623eff7ec31
[ "Apache-2.0" ]
null
null
null
WolfSSL-BESSPIN/src/internal.c
draperlaboratory/hope-FreeRTOS-RISC-V_Galois_demo
8607c3d80a8e3e2e0be2570a09eb1623eff7ec31
[ "Apache-2.0" ]
2
2021-03-10T23:53:15.000Z
2021-04-15T19:17:32.000Z
WolfSSL-BESSPIN/src/internal.c
draperlaboratory/hope-FreeRTOS-RISC-V_Galois_demo
8607c3d80a8e3e2e0be2570a09eb1623eff7ec31
[ "Apache-2.0" ]
1
2021-02-19T15:24:54.000Z
2021-02-19T15:24:54.000Z
/* internal.c * * Copyright (C) 2006-2015 wolfSSL Inc. * * This file is part of wolfSSL. (formerly known as CyaSSL) * * wolfSSL is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * wolfSSL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <wolfssl/wolfcrypt/settings.h> #include <wolfssl/internal.h> #include <wolfssl/error-ssl.h> #include <wolfssl/wolfcrypt/asn.h> #include <wolfssl/wolfcrypt/dh.h> #ifdef NO_INLINE #include <wolfssl/wolfcrypt/misc.h> #else #include <wolfcrypt/src/misc.c> #endif #ifdef HAVE_LIBZ #include "zlib.h" #endif #ifdef HAVE_NTRU #include "ntru_crypto.h" #endif #if defined(DEBUG_WOLFSSL) || defined(SHOW_SECRETS) || defined(CHACHA_AEAD_TEST) #ifdef FREESCALE_MQX #include <fio.h> #else #include <stdio.h> #endif #endif #ifdef __sun #include <sys/filio.h> #endif #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifdef _MSC_VER /* disable for while(0) cases at the .c level for now */ #pragma warning(disable:4127) #endif #if defined(WOLFSSL_CALLBACKS) && !defined(LARGE_STATIC_BUFFERS) #error \ WOLFSSL_CALLBACKS needs LARGE_STATIC_BUFFERS, please add LARGE_STATIC_BUFFERS #endif #if defined(HAVE_SECURE_RENEGOTIATION) && defined(HAVE_RENEGOTIATION_INDICATION) #error Cannot use both secure-renegotiation and renegotiation-indication #endif static int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input, int inSz, int type); #ifndef NO_WOLFSSL_CLIENT static int DoHelloVerifyRequest(WOLFSSL* ssl, const byte* input, word32*, word32); static int DoServerHello(WOLFSSL* ssl, const byte* input, word32*, word32); static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input, word32*, word32); #ifndef NO_CERTS static int DoCertificateRequest(WOLFSSL* ssl, const byte* input, word32*, word32); #endif #ifdef HAVE_SESSION_TICKET static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32*, word32); #endif #endif #ifndef NO_WOLFSSL_SERVER static int DoClientHello(WOLFSSL* ssl, const byte* input, word32*, word32); static int DoClientKeyExchange(WOLFSSL* ssl, byte* input, word32*, word32); #if !defined(NO_RSA) || defined(HAVE_ECC) static int DoCertificateVerify(WOLFSSL* ssl, byte*, word32*, word32); #endif #endif #ifdef WOLFSSL_DTLS static INLINE int DtlsCheckWindow(DtlsState* state); static INLINE int DtlsUpdateWindow(DtlsState* state); #endif typedef enum { doProcessInit = 0, #ifndef NO_WOLFSSL_SERVER runProcessOldClientHello, #endif getRecordLayerHeader, getData, runProcessingOneMessage } processReply; #ifndef NO_OLD_TLS static int SSL_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int content, int verify); #endif #ifndef NO_CERTS static int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes); #endif static void PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz); #ifndef WOLFSSL_HAVE_MIN #define WOLFSSL_HAVE_MIN static INLINE word32 min(word32 a, word32 b) { return a > b ? b : a; } #endif /* WOLFSSL_HAVE_MIN */ int IsTLS(const WOLFSSL* ssl) { if (ssl->version.major == SSLv3_MAJOR && ssl->version.minor >=TLSv1_MINOR) return 1; return 0; } int IsAtLeastTLSv1_2(const WOLFSSL* ssl) { if (ssl->version.major == SSLv3_MAJOR && ssl->version.minor >=TLSv1_2_MINOR) return 1; if (ssl->version.major == DTLS_MAJOR && ssl->version.minor <= DTLSv1_2_MINOR) return 1; return 0; } #ifdef HAVE_NTRU static byte GetEntropy(ENTROPY_CMD cmd, byte* out) { /* TODO: add locking? */ static RNG rng; if (cmd == INIT) return (wc_InitRng(&rng) == 0) ? 1 : 0; if (out == NULL) return 0; if (cmd == GET_BYTE_OF_ENTROPY) return (wc_RNG_GenerateBlock(&rng, out, 1) == 0) ? 1 : 0; if (cmd == GET_NUM_BYTES_PER_BYTE_OF_ENTROPY) { *out = 1; return 1; } return 0; } #endif /* HAVE_NTRU */ /* used by ssl.c too */ void c32to24(word32 in, word24 out) { out[0] = (in >> 16) & 0xff; out[1] = (in >> 8) & 0xff; out[2] = in & 0xff; } #ifdef WOLFSSL_DTLS static INLINE void c32to48(word32 in, byte out[6]) { out[0] = 0; out[1] = 0; out[2] = (in >> 24) & 0xff; out[3] = (in >> 16) & 0xff; out[4] = (in >> 8) & 0xff; out[5] = in & 0xff; } #endif /* WOLFSSL_DTLS */ /* convert 16 bit integer to opaque */ static INLINE void c16toa(word16 u16, byte* c) { c[0] = (u16 >> 8) & 0xff; c[1] = u16 & 0xff; } #if !defined(NO_OLD_TLS) || defined(HAVE_CHACHA) || defined(HAVE_AESCCM) \ || defined(HAVE_AESGCM) /* convert 32 bit integer to opaque */ static INLINE void c32toa(word32 u32, byte* c) { c[0] = (u32 >> 24) & 0xff; c[1] = (u32 >> 16) & 0xff; c[2] = (u32 >> 8) & 0xff; c[3] = u32 & 0xff; } #endif /* convert a 24 bit integer into a 32 bit one */ static INLINE void c24to32(const word24 u24, word32* u32) { *u32 = (u24[0] << 16) | (u24[1] << 8) | u24[2]; } /* convert opaque to 16 bit integer */ static INLINE void ato16(const byte* c, word16* u16) { *u16 = (word16) ((c[0] << 8) | (c[1])); } #if defined(WOLFSSL_DTLS) || defined(HAVE_SESSION_TICKET) /* convert opaque to 32 bit integer */ static INLINE void ato32(const byte* c, word32* u32) { *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; } #endif /* WOLFSSL_DTLS */ #ifdef HAVE_LIBZ /* alloc user allocs to work with zlib */ static void* myAlloc(void* opaque, unsigned int item, unsigned int size) { (void)opaque; return XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ); } static void myFree(void* opaque, void* memory) { (void)opaque; XFREE(memory, opaque, DYNAMIC_TYPE_LIBZ); } /* init zlib comp/decomp streams, 0 on success */ static int InitStreams(WOLFSSL* ssl) { ssl->c_stream.zalloc = (alloc_func)myAlloc; ssl->c_stream.zfree = (free_func)myFree; ssl->c_stream.opaque = (voidpf)ssl->heap; if (deflateInit(&ssl->c_stream, Z_DEFAULT_COMPRESSION) != Z_OK) return ZLIB_INIT_ERROR; ssl->didStreamInit = 1; ssl->d_stream.zalloc = (alloc_func)myAlloc; ssl->d_stream.zfree = (free_func)myFree; ssl->d_stream.opaque = (voidpf)ssl->heap; if (inflateInit(&ssl->d_stream) != Z_OK) return ZLIB_INIT_ERROR; return 0; } static void FreeStreams(WOLFSSL* ssl) { if (ssl->didStreamInit) { deflateEnd(&ssl->c_stream); inflateEnd(&ssl->d_stream); } } /* compress in to out, return out size or error */ static int myCompress(WOLFSSL* ssl, byte* in, int inSz, byte* out, int outSz) { int err; int currTotal = (int)ssl->c_stream.total_out; ssl->c_stream.next_in = in; ssl->c_stream.avail_in = inSz; ssl->c_stream.next_out = out; ssl->c_stream.avail_out = outSz; err = deflate(&ssl->c_stream, Z_SYNC_FLUSH); if (err != Z_OK && err != Z_STREAM_END) return ZLIB_COMPRESS_ERROR; return (int)ssl->c_stream.total_out - currTotal; } /* decompress in to out, returnn out size or error */ static int myDeCompress(WOLFSSL* ssl, byte* in,int inSz, byte* out,int outSz) { int err; int currTotal = (int)ssl->d_stream.total_out; ssl->d_stream.next_in = in; ssl->d_stream.avail_in = inSz; ssl->d_stream.next_out = out; ssl->d_stream.avail_out = outSz; err = inflate(&ssl->d_stream, Z_SYNC_FLUSH); if (err != Z_OK && err != Z_STREAM_END) return ZLIB_DECOMPRESS_ERROR; return (int)ssl->d_stream.total_out - currTotal; } #endif /* HAVE_LIBZ */ void InitSSL_Method(WOLFSSL_METHOD* method, ProtocolVersion pv) { method->version = pv; method->side = WOLFSSL_CLIENT_END; method->downgrade = 0; } /* Initialze SSL context, return 0 on success */ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method) { XMEMSET(ctx, 0, sizeof(WOLFSSL_CTX)); ctx->method = method; ctx->refCount = 1; /* so either CTX_free or SSL_free can release */ ctx->heap = ctx; /* defaults to self */ ctx->timeout = WOLFSSL_SESSION_TIMEOUT; ctx->minDowngrade = TLSv1_MINOR; /* current default */ if (InitMutex(&ctx->countMutex) < 0) { WOLFSSL_MSG("Mutex error on CTX init"); return BAD_MUTEX_E; } #ifndef NO_DH ctx->minDhKeySz = MIN_DHKEY_SZ; #endif #ifdef HAVE_ECC ctx->eccTempKeySz = ECDHE_SIZE; #endif #ifndef WOLFSSL_USER_IO ctx->CBIORecv = EmbedReceive; ctx->CBIOSend = EmbedSend; #ifdef WOLFSSL_DTLS if (method->version.major == DTLS_MAJOR) { ctx->CBIORecv = EmbedReceiveFrom; ctx->CBIOSend = EmbedSendTo; ctx->CBIOCookie = EmbedGenerateCookie; } #endif #endif /* WOLFSSL_USER_IO */ #ifdef HAVE_NETX ctx->CBIORecv = NetX_Receive; ctx->CBIOSend = NetX_Send; #endif #ifdef HAVE_NTRU if (method->side == WOLFSSL_CLIENT_END) ctx->haveNTRU = 1; /* always on cliet side */ /* server can turn on by loading key */ #endif #ifdef HAVE_ECC if (method->side == WOLFSSL_CLIENT_END) { ctx->haveECDSAsig = 1; /* always on cliet side */ ctx->haveStaticECC = 1; /* server can turn on by loading key */ } #endif #ifdef HAVE_CAVIUM ctx->devId = NO_CAVIUM_DEVICE; #endif #ifndef NO_CERTS ctx->cm = wolfSSL_CertManagerNew(); if (ctx->cm == NULL) { WOLFSSL_MSG("Bad Cert Manager New"); return BAD_CERT_MANAGER_ERROR; } #endif #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) ctx->ticketHint = SESSION_TICKET_HINT_DEFAULT; #endif return 0; } /* In case contexts are held in array and don't want to free actual ctx */ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx) { XFREE(ctx->method, ctx->heap, DYNAMIC_TYPE_METHOD); if (ctx->suites) XFREE(ctx->suites, ctx->heap, DYNAMIC_TYPE_SUITES); #ifndef NO_DH XFREE(ctx->serverDH_G.buffer, ctx->heap, DYNAMIC_TYPE_DH); XFREE(ctx->serverDH_P.buffer, ctx->heap, DYNAMIC_TYPE_DH); #endif #ifndef NO_CERTS XFREE(ctx->privateKey.buffer, ctx->heap, DYNAMIC_TYPE_KEY); XFREE(ctx->certificate.buffer, ctx->heap, DYNAMIC_TYPE_CERT); XFREE(ctx->certChain.buffer, ctx->heap, DYNAMIC_TYPE_CERT); wolfSSL_CertManagerFree(ctx->cm); #endif #ifdef HAVE_TLS_EXTENSIONS TLSX_FreeAll(ctx->extensions); #endif } void FreeSSL_Ctx(WOLFSSL_CTX* ctx) { int doFree = 0; if (LockMutex(&ctx->countMutex) != 0) { WOLFSSL_MSG("Couldn't lock count mutex"); return; } ctx->refCount--; if (ctx->refCount == 0) doFree = 1; UnLockMutex(&ctx->countMutex); if (doFree) { WOLFSSL_MSG("CTX ref count down to 0, doing full free"); SSL_CtxResourceFree(ctx); FreeMutex(&ctx->countMutex); XFREE(ctx, ctx->heap, DYNAMIC_TYPE_CTX); } else { (void)ctx; WOLFSSL_MSG("CTX ref count not 0 yet, no free"); } } /* Set cipher pointers to null */ void InitCiphers(WOLFSSL* ssl) { #ifdef BUILD_ARC4 ssl->encrypt.arc4 = NULL; ssl->decrypt.arc4 = NULL; #endif #ifdef BUILD_DES3 ssl->encrypt.des3 = NULL; ssl->decrypt.des3 = NULL; #endif #ifdef BUILD_AES ssl->encrypt.aes = NULL; ssl->decrypt.aes = NULL; #endif #ifdef HAVE_CAMELLIA ssl->encrypt.cam = NULL; ssl->decrypt.cam = NULL; #endif #ifdef HAVE_HC128 ssl->encrypt.hc128 = NULL; ssl->decrypt.hc128 = NULL; #endif #ifdef BUILD_RABBIT ssl->encrypt.rabbit = NULL; ssl->decrypt.rabbit = NULL; #endif #ifdef HAVE_CHACHA ssl->encrypt.chacha = NULL; ssl->decrypt.chacha = NULL; #endif #ifdef HAVE_POLY1305 ssl->auth.poly1305 = NULL; #endif ssl->encrypt.setup = 0; ssl->decrypt.setup = 0; #ifdef HAVE_ONE_TIME_AUTH ssl->auth.setup = 0; #endif } /* Free ciphers */ void FreeCiphers(WOLFSSL* ssl) { (void)ssl; #ifdef BUILD_ARC4 #ifdef HAVE_CAVIUM if (ssl->devId != NO_CAVIUM_DEVICE) { wc_Arc4FreeCavium(ssl->encrypt.arc4); wc_Arc4FreeCavium(ssl->decrypt.arc4); } #endif XFREE(ssl->encrypt.arc4, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.arc4, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef BUILD_DES3 #ifdef HAVE_CAVIUM if (ssl->devId != NO_CAVIUM_DEVICE) { wc_Des3_FreeCavium(ssl->encrypt.des3); wc_Des3_FreeCavium(ssl->decrypt.des3); } #endif XFREE(ssl->encrypt.des3, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.des3, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef BUILD_AES #ifdef HAVE_CAVIUM if (ssl->devId != NO_CAVIUM_DEVICE) { wc_AesFreeCavium(ssl->encrypt.aes); wc_AesFreeCavium(ssl->decrypt.aes); } #endif XFREE(ssl->encrypt.aes, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.aes, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef HAVE_CAMELLIA XFREE(ssl->encrypt.cam, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.cam, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef HAVE_HC128 XFREE(ssl->encrypt.hc128, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.hc128, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef BUILD_RABBIT XFREE(ssl->encrypt.rabbit, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.rabbit, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef HAVE_CHACHA XFREE(ssl->encrypt.chacha, ssl->heap, DYNAMIC_TYPE_CIPHER); XFREE(ssl->decrypt.chacha, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif #ifdef HAVE_POLY1305 XFREE(ssl->auth.poly1305, ssl->heap, DYNAMIC_TYPE_CIPHER); #endif } void InitCipherSpecs(CipherSpecs* cs) { cs->bulk_cipher_algorithm = INVALID_BYTE; cs->cipher_type = INVALID_BYTE; cs->mac_algorithm = INVALID_BYTE; cs->kea = INVALID_BYTE; cs->sig_algo = INVALID_BYTE; cs->hash_size = 0; cs->static_ecdh = 0; cs->key_size = 0; cs->iv_size = 0; cs->block_size = 0; } static void InitSuitesHashSigAlgo(Suites* suites, int haveECDSAsig, int haveRSAsig, int haveAnon) { int idx = 0; if (haveECDSAsig) { #ifdef WOLFSSL_SHA512 suites->hashSigAlgo[idx++] = sha512_mac; suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; #endif #ifdef WOLFSSL_SHA384 suites->hashSigAlgo[idx++] = sha384_mac; suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; #endif #ifndef NO_SHA256 suites->hashSigAlgo[idx++] = sha256_mac; suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; #endif #ifndef NO_SHA suites->hashSigAlgo[idx++] = sha_mac; suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; #endif } if (haveRSAsig) { #ifdef WOLFSSL_SHA512 suites->hashSigAlgo[idx++] = sha512_mac; suites->hashSigAlgo[idx++] = rsa_sa_algo; #endif #ifdef WOLFSSL_SHA384 suites->hashSigAlgo[idx++] = sha384_mac; suites->hashSigAlgo[idx++] = rsa_sa_algo; #endif #ifndef NO_SHA256 suites->hashSigAlgo[idx++] = sha256_mac; suites->hashSigAlgo[idx++] = rsa_sa_algo; #endif #ifndef NO_SHA suites->hashSigAlgo[idx++] = sha_mac; suites->hashSigAlgo[idx++] = rsa_sa_algo; #endif } if (haveAnon) { #ifdef HAVE_ANON suites->hashSigAlgo[idx++] = sha_mac; suites->hashSigAlgo[idx++] = anonymous_sa_algo; #endif } suites->hashSigAlgoSz = (word16)idx; } void InitSuites(Suites* suites, ProtocolVersion pv, word16 haveRSA, word16 havePSK, word16 haveDH, word16 haveNTRU, word16 haveECDSAsig, word16 haveStaticECC, int side) { word16 idx = 0; int tls = pv.major == SSLv3_MAJOR && pv.minor >= TLSv1_MINOR; int tls1_2 = pv.major == SSLv3_MAJOR && pv.minor >= TLSv1_2_MINOR; int haveRSAsig = 1; (void)tls; /* shut up compiler */ (void)tls1_2; (void)haveDH; (void)havePSK; (void)haveNTRU; (void)haveStaticECC; if (suites == NULL) { WOLFSSL_MSG("InitSuites pointer error"); return; } if (suites->setSuites) return; /* trust user settings, don't override */ if (side == WOLFSSL_SERVER_END && haveStaticECC) { haveRSA = 0; /* can't do RSA with ECDSA key */ (void)haveRSA; /* some builds won't read */ } if (side == WOLFSSL_SERVER_END && haveECDSAsig) { haveRSAsig = 0; /* can't have RSA sig if signed by ECDSA */ (void)haveRSAsig; /* non ecc builds won't read */ } #ifdef WOLFSSL_DTLS if (pv.major == DTLS_MAJOR) { tls = 1; tls1_2 = pv.minor <= DTLSv1_2_MINOR; } #endif #ifdef HAVE_RENEGOTIATION_INDICATION if (side == WOLFSSL_CLIENT_END) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_EMPTY_RENEGOTIATION_INFO_SCSV; } #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA if (tls && haveNTRU && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_NTRU_RSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA if (tls && haveNTRU && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_NTRU_RSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA if (tls && haveNTRU && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_NTRU_RSA_WITH_RC4_128_SHA; } #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA if (tls && haveNTRU && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 if (tls1_2 && haveDH && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_PSK_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 if (tls1_2 && haveDH && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_PSK_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384 if (tls1_2 && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_AES_256_GCM_SHA384; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256 if (tls1_2 && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_AES_128_GCM_SHA256; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = CHACHA_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 if (tls && haveRSA) { suites->suites[idx++] = CHACHA_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 if (tls && haveRSA) { suites->suites[idx++] = CHACHA_BYTE; suites->suites[idx++] = TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveRSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 if (tls1_2 && haveRSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 if (tls1_2 && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 if (tls1_2 && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA if (tls && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA if (tls && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA if (tls && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA if (tls && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA if (tls && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_RC4_128_SHA; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA if (tls && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_RC4_128_SHA; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA if (tls && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA if (tls && haveECDSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA if (tls && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA if (tls && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA if (tls && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_RC4_128_SHA; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA if (tls && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_RC4_128_SHA; } #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA if (tls && haveRSAsig && haveStaticECC) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8; } #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 if (tls1_2 && haveECDSAsig) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 if (tls1_2 && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_RSA_WITH_AES_128_CCM_8; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 if (tls1_2 && haveRSA) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_RSA_WITH_AES_256_CCM_8; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 if (tls1_2 && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA256; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 if (tls1_2 && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_256_CBC_SHA256; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_NULL_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_NULL_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_NULL_SHA256; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_AES_256_CBC_SHA; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 if (tls && haveDH && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_PSK_WITH_AES_256_CBC_SHA384; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384 if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_AES_256_CBC_SHA384; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 if (tls && haveDH && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_PSK_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_AES_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_AES_128_CBC_SHA; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CCM if (tls && haveDH && havePSK) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_DHE_PSK_WITH_AES_128_CCM; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CCM if (tls && haveDH && havePSK) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_DHE_PSK_WITH_AES_256_CCM; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM if (tls && havePSK) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_PSK_WITH_AES_128_CCM; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM if (tls && havePSK) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_PSK_WITH_AES_256_CCM; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 if (tls && havePSK) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_PSK_WITH_AES_128_CCM_8; } #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 if (tls && havePSK) { suites->suites[idx++] = ECC_BYTE; suites->suites[idx++] = TLS_PSK_WITH_AES_256_CCM_8; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA384 if (tls && haveDH && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_PSK_WITH_NULL_SHA384; } #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA384 if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_NULL_SHA384; } #endif #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA256 if (tls && haveDH && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_PSK_WITH_NULL_SHA256; } #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_NULL_SHA256; } #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA if (tls && havePSK) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_PSK_WITH_NULL_SHA; } #endif #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA if (haveRSA ) { suites->suites[idx++] = 0; suites->suites[idx++] = SSL_RSA_WITH_RC4_128_SHA; } #endif #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 if (haveRSA ) { suites->suites[idx++] = 0; suites->suites[idx++] = SSL_RSA_WITH_RC4_128_MD5; } #endif #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA if (haveRSA ) { suites->suites[idx++] = 0; suites->suites[idx++] = SSL_RSA_WITH_3DES_EDE_CBC_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_MD5 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_HC_128_MD5; } #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_HC_128_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_B2B256 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_HC_128_B2B256; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_128_CBC_B2B256; } #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_AES_256_CBC_B2B256; } #endif #ifdef BUILD_TLS_RSA_WITH_RABBIT_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_RABBIT_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_128_CBC_SHA; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_256_CBC_SHA; } #endif #ifdef BUILD_TLS_DHE_WITH_RSA_CAMELLIA_256_CBC_SHA if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA; } #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256; } #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 if (tls && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256; } #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256; } #endif suites->suiteSz = idx; InitSuitesHashSigAlgo(suites, haveECDSAsig, haveRSAsig, 0); } #ifndef NO_CERTS void InitX509Name(WOLFSSL_X509_NAME* name, int dynamicFlag) { (void)dynamicFlag; if (name != NULL) { name->name = name->staticName; name->dynamicName = 0; #ifdef OPENSSL_EXTRA XMEMSET(&name->fullName, 0, sizeof(DecodedName)); #endif /* OPENSSL_EXTRA */ } } void FreeX509Name(WOLFSSL_X509_NAME* name) { if (name != NULL) { if (name->dynamicName) XFREE(name->name, NULL, DYNAMIC_TYPE_SUBJECT_CN); #ifdef OPENSSL_EXTRA if (name->fullName.fullName != NULL) XFREE(name->fullName.fullName, NULL, DYNAMIC_TYPE_X509); #endif /* OPENSSL_EXTRA */ } } /* Initialize wolfSSL X509 type */ void InitX509(WOLFSSL_X509* x509, int dynamicFlag) { InitX509Name(&x509->issuer, 0); InitX509Name(&x509->subject, 0); x509->version = 0; x509->pubKey.buffer = NULL; x509->sig.buffer = NULL; x509->derCert.buffer = NULL; x509->altNames = NULL; x509->altNamesNext = NULL; x509->dynamicMemory = (byte)dynamicFlag; x509->isCa = 0; #ifdef HAVE_ECC x509->pkCurveOID = 0; #endif /* HAVE_ECC */ #ifdef OPENSSL_EXTRA x509->pathLength = 0; x509->basicConstSet = 0; x509->basicConstCrit = 0; x509->basicConstPlSet = 0; x509->subjAltNameSet = 0; x509->subjAltNameCrit = 0; x509->authKeyIdSet = 0; x509->authKeyIdCrit = 0; x509->authKeyId = NULL; x509->authKeyIdSz = 0; x509->subjKeyIdSet = 0; x509->subjKeyIdCrit = 0; x509->subjKeyId = NULL; x509->subjKeyIdSz = 0; x509->keyUsageSet = 0; x509->keyUsageCrit = 0; x509->keyUsage = 0; #ifdef WOLFSSL_SEP x509->certPolicySet = 0; x509->certPolicyCrit = 0; #endif /* WOLFSSL_SEP */ #endif /* OPENSSL_EXTRA */ } /* Free wolfSSL X509 type */ void FreeX509(WOLFSSL_X509* x509) { if (x509 == NULL) return; FreeX509Name(&x509->issuer); FreeX509Name(&x509->subject); if (x509->pubKey.buffer) XFREE(x509->pubKey.buffer, NULL, DYNAMIC_TYPE_PUBLIC_KEY); XFREE(x509->derCert.buffer, NULL, DYNAMIC_TYPE_SUBJECT_CN); XFREE(x509->sig.buffer, NULL, DYNAMIC_TYPE_SIGNATURE); #ifdef OPENSSL_EXTRA XFREE(x509->authKeyId, NULL, 0); XFREE(x509->subjKeyId, NULL, 0); #endif /* OPENSSL_EXTRA */ if (x509->altNames) FreeAltNames(x509->altNames, NULL); if (x509->dynamicMemory) XFREE(x509, NULL, DYNAMIC_TYPE_X509); } #endif /* NO_CERTS */ /* init everything to 0, NULL, default values before calling anything that may fail so that desctructor has a "good" state to cleanup */ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) { int ret; byte haveRSA = 0; byte havePSK = 0; byte haveAnon = 0; (void) haveAnon; XMEMSET(ssl, 0, sizeof(WOLFSSL)); ssl->ctx = ctx; /* only for passing to calls, options could change */ ssl->version = ctx->method->version; #ifndef NO_RSA haveRSA = 1; #endif ssl->buffers.inputBuffer.buffer = ssl->buffers.inputBuffer.staticBuffer; ssl->buffers.inputBuffer.bufferSize = STATIC_BUFFER_LEN; ssl->buffers.outputBuffer.buffer = ssl->buffers.outputBuffer.staticBuffer; ssl->buffers.outputBuffer.bufferSize = STATIC_BUFFER_LEN; #ifdef KEEP_PEER_CERT InitX509(&ssl->peerCert, 0); #endif #ifdef HAVE_ECC ssl->eccTempKeySz = ctx->eccTempKeySz; ssl->pkCurveOID = ctx->pkCurveOID; #endif ssl->timeout = ctx->timeout; ssl->rfd = (WOLFSSL_FD)-1; /* set to invalid descriptor */ ssl->wfd = (WOLFSSL_FD)-1; ssl->IOCB_ReadCtx = &ssl->rfd; /* prevent invalid pointer access if not */ ssl->IOCB_WriteCtx = &ssl->wfd; /* correctly set */ #ifdef HAVE_NETX ssl->IOCB_ReadCtx = &ssl->nxCtx; /* default NetX IO ctx, same for read */ ssl->IOCB_WriteCtx = &ssl->nxCtx; /* and write */ #endif #ifdef WOLFSSL_DTLS ssl->dtls_expected_rx = MAX_MTU; #endif ssl->verifyCallback = ctx->verifyCallback; ssl->options.side = ctx->method->side; ssl->options.downgrade = ctx->method->downgrade; ssl->options.minDowngrade = ctx->minDowngrade; if (ssl->options.side == WOLFSSL_SERVER_END) ssl->options.haveDH = ctx->haveDH; ssl->options.haveNTRU = ctx->haveNTRU; ssl->options.haveECDSAsig = ctx->haveECDSAsig; ssl->options.haveStaticECC = ctx->haveStaticECC; #ifndef NO_PSK havePSK = ctx->havePSK; ssl->options.havePSK = ctx->havePSK; ssl->options.client_psk_cb = ctx->client_psk_cb; ssl->options.server_psk_cb = ctx->server_psk_cb; #endif /* NO_PSK */ #ifdef HAVE_ANON haveAnon = ctx->haveAnon; ssl->options.haveAnon = ctx->haveAnon; #endif ssl->options.serverState = NULL_STATE; ssl->options.clientState = NULL_STATE; ssl->options.connectState = CONNECT_BEGIN; ssl->options.acceptState = ACCEPT_BEGIN; ssl->options.handShakeState = NULL_STATE; ssl->options.processReply = doProcessInit; #ifndef NO_DH ssl->options.minDhKeySz = ctx->minDhKeySz; #endif #ifdef WOLFSSL_DTLS ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT; ssl->dtls_timeout_max = DTLS_TIMEOUT_MAX; ssl->dtls_timeout = ssl->dtls_timeout_init; #endif ssl->options.sessionCacheOff = ctx->sessionCacheOff; ssl->options.sessionCacheFlushOff = ctx->sessionCacheFlushOff; ssl->options.verifyPeer = ctx->verifyPeer; ssl->options.verifyNone = ctx->verifyNone; ssl->options.failNoCert = ctx->failNoCert; ssl->options.sendVerify = ctx->sendVerify; #ifndef NO_OLD_TLS ssl->hmac = SSL_hmac; /* default to SSLv3 */ #else ssl->hmac = TLS_hmac; #endif ssl->heap = ctx->heap; /* defaults to self */ ssl->options.dtls = ssl->version.major == DTLS_MAJOR; ssl->options.partialWrite = ctx->partialWrite; ssl->options.quietShutdown = ctx->quietShutdown; ssl->options.groupMessages = ctx->groupMessages; #ifndef NO_DH if (ssl->options.side == WOLFSSL_SERVER_END) { ssl->buffers.serverDH_P = ctx->serverDH_P; ssl->buffers.serverDH_G = ctx->serverDH_G; } #endif #ifndef NO_CERTS /* ctx still owns certificate, certChain, key, dh, and cm */ ssl->buffers.certificate = ctx->certificate; ssl->buffers.certChain = ctx->certChain; ssl->buffers.key = ctx->privateKey; #endif #ifdef WOLFSSL_DTLS ssl->buffers.dtlsCtx.fd = -1; #endif ssl->cipher.ssl = ssl; #ifdef HAVE_CAVIUM ssl->devId = ctx->devId; #endif #ifdef HAVE_TLS_EXTENSIONS #ifdef HAVE_MAX_FRAGMENT ssl->max_fragment = MAX_RECORD_SIZE; #endif #endif /* default alert state (none) */ ssl->alert_history.last_rx.code = -1; ssl->alert_history.last_rx.level = -1; ssl->alert_history.last_tx.code = -1; ssl->alert_history.last_tx.level = -1; InitCiphers(ssl); InitCipherSpecs(&ssl->specs); /* all done with init, now can return errors, call other stuff */ /* hsHashes */ ssl->hsHashes = (HS_Hashes*)XMALLOC(sizeof(HS_Hashes), ssl->heap, DYNAMIC_TYPE_HASHES); if (ssl->hsHashes == NULL) { WOLFSSL_MSG("HS_Hashes Memory error"); return MEMORY_E; } #ifndef NO_OLD_TLS #ifndef NO_MD5 wc_InitMd5(&ssl->hsHashes->hashMd5); #endif #ifndef NO_SHA ret = wc_InitSha(&ssl->hsHashes->hashSha); if (ret != 0) { return ret; } #endif #endif #ifndef NO_SHA256 ret = wc_InitSha256(&ssl->hsHashes->hashSha256); if (ret != 0) { return ret; } #endif #ifdef WOLFSSL_SHA384 ret = wc_InitSha384(&ssl->hsHashes->hashSha384); if (ret != 0) { return ret; } #endif #ifdef WOLFSSL_SHA512 ret = wc_InitSha512(&ssl->hsHashes->hashSha512); if (ret != 0) { return ret; } #endif /* increment CTX reference count */ if (LockMutex(&ctx->countMutex) != 0) { WOLFSSL_MSG("Couldn't lock CTX count mutex"); return BAD_MUTEX_E; } ctx->refCount++; UnLockMutex(&ctx->countMutex); /* arrays */ ssl->arrays = (Arrays*)XMALLOC(sizeof(Arrays), ssl->heap, DYNAMIC_TYPE_ARRAYS); if (ssl->arrays == NULL) { WOLFSSL_MSG("Arrays Memory error"); return MEMORY_E; } XMEMSET(ssl->arrays, 0, sizeof(Arrays)); #ifndef NO_PSK if (ctx->server_hint[0]) { /* set in CTX */ XSTRNCPY(ssl->arrays->server_hint, ctx->server_hint, MAX_PSK_ID_LEN); ssl->arrays->server_hint[MAX_PSK_ID_LEN - 1] = '\0'; } #endif /* NO_PSK */ /* RNG */ ssl->rng = (RNG*)XMALLOC(sizeof(RNG), ssl->heap, DYNAMIC_TYPE_RNG); if (ssl->rng == NULL) { WOLFSSL_MSG("RNG Memory error"); return MEMORY_E; } if ( (ret = wc_InitRng(ssl->rng)) != 0) { WOLFSSL_MSG("RNG Init error"); return ret; } /* suites */ ssl->suites = (Suites*)XMALLOC(sizeof(Suites), ssl->heap, DYNAMIC_TYPE_SUITES); if (ssl->suites == NULL) { WOLFSSL_MSG("Suites Memory error"); return MEMORY_E; } if (ctx->suites) *ssl->suites = *ctx->suites; else XMEMSET(ssl->suites, 0, sizeof(Suites)); #ifndef NO_CERTS /* make sure server has cert and key unless using PSK or Anon */ if (ssl->options.side == WOLFSSL_SERVER_END && !havePSK && !haveAnon) if (!ssl->buffers.certificate.buffer || !ssl->buffers.key.buffer) { WOLFSSL_MSG("Server missing certificate and/or private key"); return NO_PRIVATE_KEY; } #endif #ifdef HAVE_SECRET_CALLBACK ssl->sessionSecretCb = NULL; ssl->sessionSecretCtx = NULL; #endif /* make sure server has DH parms, and add PSK if there, add NTRU too */ if (ssl->options.side == WOLFSSL_SERVER_END) InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, ssl->options.haveDH, ssl->options.haveNTRU, ssl->options.haveECDSAsig, ssl->options.haveStaticECC, ssl->options.side); else InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, TRUE, ssl->options.haveNTRU, ssl->options.haveECDSAsig, ssl->options.haveStaticECC, ssl->options.side); return 0; } /* free use of temporary arrays */ void FreeArrays(WOLFSSL* ssl, int keep) { if (ssl->arrays && keep) { /* keeps session id for user retrieval */ XMEMCPY(ssl->session.sessionID, ssl->arrays->sessionID, ID_LEN); ssl->session.sessionIDSz = ssl->arrays->sessionIDSz; } XFREE(ssl->arrays, ssl->heap, DYNAMIC_TYPE_ARRAYS); ssl->arrays = NULL; } /* In case holding SSL object in array and don't want to free actual ssl */ void SSL_ResourceFree(WOLFSSL* ssl) { /* Note: any resources used during the handshake should be released in the * function FreeHandshakeResources(). Be careful with the special cases * like the RNG which may optionally be kept for the whole session. (For * example with the RNG, it isn't used beyond the handshake except when * using stream ciphers where it is retained. */ FreeCiphers(ssl); FreeArrays(ssl, 0); wc_FreeRng(ssl->rng); XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG); XFREE(ssl->suites, ssl->heap, DYNAMIC_TYPE_SUITES); XFREE(ssl->hsHashes, ssl->heap, DYNAMIC_TYPE_HASHES); XFREE(ssl->buffers.domainName.buffer, ssl->heap, DYNAMIC_TYPE_DOMAIN); #ifndef NO_DH XFREE(ssl->buffers.serverDH_Priv.buffer, ssl->heap, DYNAMIC_TYPE_DH); XFREE(ssl->buffers.serverDH_Pub.buffer, ssl->heap, DYNAMIC_TYPE_DH); /* parameters (p,g) may be owned by ctx */ if (ssl->buffers.weOwnDH || ssl->options.side == WOLFSSL_CLIENT_END) { XFREE(ssl->buffers.serverDH_G.buffer, ssl->heap, DYNAMIC_TYPE_DH); XFREE(ssl->buffers.serverDH_P.buffer, ssl->heap, DYNAMIC_TYPE_DH); } #endif #ifndef NO_CERTS if (ssl->buffers.weOwnCert) XFREE(ssl->buffers.certificate.buffer, ssl->heap, DYNAMIC_TYPE_CERT); if (ssl->buffers.weOwnCertChain) XFREE(ssl->buffers.certChain.buffer, ssl->heap, DYNAMIC_TYPE_CERT); if (ssl->buffers.weOwnKey) XFREE(ssl->buffers.key.buffer, ssl->heap, DYNAMIC_TYPE_KEY); #endif #ifndef NO_RSA if (ssl->peerRsaKey) { wc_FreeRsaKey(ssl->peerRsaKey); XFREE(ssl->peerRsaKey, ssl->heap, DYNAMIC_TYPE_RSA); } #endif if (ssl->buffers.inputBuffer.dynamicFlag) ShrinkInputBuffer(ssl, FORCED_FREE); if (ssl->buffers.outputBuffer.dynamicFlag) ShrinkOutputBuffer(ssl); #ifdef WOLFSSL_DTLS if (ssl->dtls_pool != NULL) { DtlsPoolReset(ssl); XFREE(ssl->dtls_pool, ssl->heap, DYNAMIC_TYPE_NONE); } if (ssl->dtls_msg_list != NULL) { DtlsMsgListDelete(ssl->dtls_msg_list, ssl->heap); ssl->dtls_msg_list = NULL; } XFREE(ssl->buffers.dtlsCtx.peer.sa, ssl->heap, DYNAMIC_TYPE_SOCKADDR); ssl->buffers.dtlsCtx.peer.sa = NULL; #endif #if defined(KEEP_PEER_CERT) || defined(GOAHEAD_WS) FreeX509(&ssl->peerCert); #endif #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) wolfSSL_BIO_free(ssl->biord); if (ssl->biord != ssl->biowr) /* in case same as write */ wolfSSL_BIO_free(ssl->biowr); #endif #ifdef HAVE_LIBZ FreeStreams(ssl); #endif #ifdef HAVE_ECC if (ssl->peerEccKey) { if (ssl->peerEccKeyPresent) wc_ecc_free(ssl->peerEccKey); XFREE(ssl->peerEccKey, ssl->heap, DYNAMIC_TYPE_ECC); } if (ssl->peerEccDsaKey) { if (ssl->peerEccDsaKeyPresent) wc_ecc_free(ssl->peerEccDsaKey); XFREE(ssl->peerEccDsaKey, ssl->heap, DYNAMIC_TYPE_ECC); } if (ssl->eccTempKey) { if (ssl->eccTempKeyPresent) wc_ecc_free(ssl->eccTempKey); XFREE(ssl->eccTempKey, ssl->heap, DYNAMIC_TYPE_ECC); } #endif #ifdef HAVE_PK_CALLBACKS #ifdef HAVE_ECC XFREE(ssl->buffers.peerEccDsaKey.buffer, ssl->heap, DYNAMIC_TYPE_ECC); #endif /* HAVE_ECC */ #ifndef NO_RSA XFREE(ssl->buffers.peerRsaKey.buffer, ssl->heap, DYNAMIC_TYPE_RSA); #endif /* NO_RSA */ #endif /* HAVE_PK_CALLBACKS */ #ifdef HAVE_TLS_EXTENSIONS TLSX_FreeAll(ssl->extensions); #endif #ifdef HAVE_NETX if (ssl->nxCtx.nxPacket) nx_packet_release(ssl->nxCtx.nxPacket); #endif } #ifdef WOLFSSL_TI_HASH static void HashFinal(WOLFSSL * ssl) { byte dummyHash[32] ; #ifndef NO_MD5 wc_Md5Final(&(ssl->hsHashes->hashMd5), dummyHash) ; #endif #ifndef NO_SHA wc_ShaFinal(&(ssl->hsHashes->hashSha), dummyHash) ; #endif #ifndef NO_SHA256 wc_Sha256Final(&(ssl->hsHashes->hashSha256), dummyHash) ; #endif } #else #define HashFinal(ssl) #endif /* Free any handshake resources no longer needed */ void FreeHandshakeResources(WOLFSSL* ssl) { HashFinal(ssl) ; #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation && ssl->secure_renegotiation->enabled) { WOLFSSL_MSG("Secure Renegotiation needs to retain handshake resources"); return; } #endif /* input buffer */ if (ssl->buffers.inputBuffer.dynamicFlag) ShrinkInputBuffer(ssl, NO_FORCED_FREE); /* suites */ XFREE(ssl->suites, ssl->heap, DYNAMIC_TYPE_SUITES); ssl->suites = NULL; /* hsHashes */ XFREE(ssl->hsHashes, ssl->heap, DYNAMIC_TYPE_HASHES); ssl->hsHashes = NULL; /* RNG */ if (ssl->specs.cipher_type == stream || ssl->options.tls1_1 == 0) { wc_FreeRng(ssl->rng); XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG); ssl->rng = NULL; } #ifdef WOLFSSL_DTLS /* DTLS_POOL */ if (ssl->options.dtls && ssl->dtls_pool != NULL) { DtlsPoolReset(ssl); XFREE(ssl->dtls_pool, ssl->heap, DYNAMIC_TYPE_DTLS_POOL); ssl->dtls_pool = NULL; } #endif /* arrays */ if (ssl->options.saveArrays == 0) FreeArrays(ssl, 1); #ifndef NO_RSA /* peerRsaKey */ if (ssl->peerRsaKey) { wc_FreeRsaKey(ssl->peerRsaKey); XFREE(ssl->peerRsaKey, ssl->heap, DYNAMIC_TYPE_RSA); ssl->peerRsaKey = NULL; } #endif #ifdef HAVE_ECC if (ssl->peerEccKey) { if (ssl->peerEccKeyPresent) { wc_ecc_free(ssl->peerEccKey); ssl->peerEccKeyPresent = 0; } XFREE(ssl->peerEccKey, ssl->heap, DYNAMIC_TYPE_ECC); ssl->peerEccKey = NULL; } if (ssl->peerEccDsaKey) { if (ssl->peerEccDsaKeyPresent) { wc_ecc_free(ssl->peerEccDsaKey); ssl->peerEccDsaKeyPresent = 0; } XFREE(ssl->peerEccDsaKey, ssl->heap, DYNAMIC_TYPE_ECC); ssl->peerEccDsaKey = NULL; } if (ssl->eccTempKey) { if (ssl->eccTempKeyPresent) { wc_ecc_free(ssl->eccTempKey); ssl->eccTempKeyPresent = 0; } XFREE(ssl->eccTempKey, ssl->heap, DYNAMIC_TYPE_ECC); ssl->eccTempKey = NULL; } #endif #ifndef NO_DH XFREE(ssl->buffers.serverDH_Priv.buffer, ssl->heap, DYNAMIC_TYPE_DH); ssl->buffers.serverDH_Priv.buffer = NULL; XFREE(ssl->buffers.serverDH_Pub.buffer, ssl->heap, DYNAMIC_TYPE_DH); ssl->buffers.serverDH_Pub.buffer = NULL; /* parameters (p,g) may be owned by ctx */ if (ssl->buffers.weOwnDH || ssl->options.side == WOLFSSL_CLIENT_END) { XFREE(ssl->buffers.serverDH_G.buffer, ssl->heap, DYNAMIC_TYPE_DH); ssl->buffers.serverDH_G.buffer = NULL; XFREE(ssl->buffers.serverDH_P.buffer, ssl->heap, DYNAMIC_TYPE_DH); ssl->buffers.serverDH_P.buffer = NULL; } #endif #ifndef NO_CERTS if (ssl->buffers.weOwnCert) { XFREE(ssl->buffers.certificate.buffer, ssl->heap, DYNAMIC_TYPE_CERT); ssl->buffers.certificate.buffer = NULL; } if (ssl->buffers.weOwnCertChain) { XFREE(ssl->buffers.certChain.buffer, ssl->heap, DYNAMIC_TYPE_CERT); ssl->buffers.certChain.buffer = NULL; } if (ssl->buffers.weOwnKey) { XFREE(ssl->buffers.key.buffer, ssl->heap, DYNAMIC_TYPE_KEY); ssl->buffers.key.buffer = NULL; } #endif #ifdef HAVE_PK_CALLBACKS #ifdef HAVE_ECC XFREE(ssl->buffers.peerEccDsaKey.buffer, ssl->heap, DYNAMIC_TYPE_ECC); ssl->buffers.peerEccDsaKey.buffer = NULL; #endif /* HAVE_ECC */ #ifndef NO_RSA XFREE(ssl->buffers.peerRsaKey.buffer, ssl->heap, DYNAMIC_TYPE_RSA); ssl->buffers.peerRsaKey.buffer = NULL; #endif /* NO_RSA */ #endif /* HAVE_PK_CALLBACKS */ } void FreeSSL(WOLFSSL* ssl) { FreeSSL_Ctx(ssl->ctx); /* will decrement and free underyling CTX if 0 */ SSL_ResourceFree(ssl); XFREE(ssl, ssl->heap, DYNAMIC_TYPE_SSL); } #ifdef WOLFSSL_DTLS int DtlsPoolInit(WOLFSSL* ssl) { if (ssl->dtls_pool == NULL) { DtlsPool *pool = (DtlsPool*)XMALLOC(sizeof(DtlsPool), ssl->heap, DYNAMIC_TYPE_DTLS_POOL); if (pool == NULL) { WOLFSSL_MSG("DTLS Buffer Pool Memory error"); return MEMORY_E; } else { int i; for (i = 0; i < DTLS_POOL_SZ; i++) { pool->buf[i].length = 0; pool->buf[i].buffer = NULL; } pool->used = 0; ssl->dtls_pool = pool; } } return 0; } int DtlsPoolSave(WOLFSSL* ssl, const byte *src, int sz) { DtlsPool *pool = ssl->dtls_pool; if (pool != NULL && pool->used < DTLS_POOL_SZ) { buffer *pBuf = &pool->buf[pool->used]; pBuf->buffer = (byte*)XMALLOC(sz, ssl->heap, DYNAMIC_TYPE_DTLS_POOL); if (pBuf->buffer == NULL) { WOLFSSL_MSG("DTLS Buffer Memory error"); return MEMORY_ERROR; } XMEMCPY(pBuf->buffer, src, sz); pBuf->length = (word32)sz; pool->used++; } return 0; } void DtlsPoolReset(WOLFSSL* ssl) { DtlsPool *pool = ssl->dtls_pool; if (pool != NULL) { buffer *pBuf; int i, used; used = pool->used; for (i = 0, pBuf = &pool->buf[0]; i < used; i++, pBuf++) { XFREE(pBuf->buffer, ssl->heap, DYNAMIC_TYPE_DTLS_POOL); pBuf->buffer = NULL; pBuf->length = 0; } pool->used = 0; } ssl->dtls_timeout = ssl->dtls_timeout_init; } int DtlsPoolTimeout(WOLFSSL* ssl) { int result = -1; if (ssl->dtls_timeout < ssl->dtls_timeout_max) { ssl->dtls_timeout *= DTLS_TIMEOUT_MULTIPLIER; result = 0; } return result; } int DtlsPoolSend(WOLFSSL* ssl) { int ret; DtlsPool *pool = ssl->dtls_pool; if (pool != NULL && pool->used > 0) { int i; for (i = 0; i < pool->used; i++) { int sendResult; buffer* buf = &pool->buf[i]; DtlsRecordLayerHeader* dtls = (DtlsRecordLayerHeader*)buf->buffer; word16 message_epoch; ato16(dtls->epoch, &message_epoch); if (message_epoch == ssl->keys.dtls_epoch) { /* Increment record sequence number on retransmitted handshake * messages */ c32to48(ssl->keys.dtls_sequence_number, dtls->sequence_number); ssl->keys.dtls_sequence_number++; } else { /* The Finished message is sent with the next epoch, keep its * sequence number */ } if ((ret = CheckAvailableSize(ssl, buf->length)) != 0) return ret; XMEMCPY(ssl->buffers.outputBuffer.buffer, buf->buffer, buf->length); ssl->buffers.outputBuffer.idx = 0; ssl->buffers.outputBuffer.length = buf->length; sendResult = SendBuffered(ssl); if (sendResult < 0) { return sendResult; } } } return 0; } /* functions for managing DTLS datagram reordering */ /* Need to allocate space for the handshake message header. The hashing * routines assume the message pointer is still within the buffer that * has the headers, and will include those headers in the hash. The store * routines need to take that into account as well. New will allocate * extra space for the headers. */ DtlsMsg* DtlsMsgNew(word32 sz, void* heap) { DtlsMsg* msg = NULL; msg = (DtlsMsg*)XMALLOC(sizeof(DtlsMsg), heap, DYNAMIC_TYPE_DTLS_MSG); if (msg != NULL) { msg->buf = (byte*)XMALLOC(sz + DTLS_HANDSHAKE_HEADER_SZ, heap, DYNAMIC_TYPE_NONE); if (msg->buf != NULL) { msg->next = NULL; msg->seq = 0; msg->sz = sz; msg->fragSz = 0; msg->msg = msg->buf + DTLS_HANDSHAKE_HEADER_SZ; } else { XFREE(msg, heap, DYNAMIC_TYPE_DTLS_MSG); msg = NULL; } } return msg; } void DtlsMsgDelete(DtlsMsg* item, void* heap) { (void)heap; if (item != NULL) { if (item->buf != NULL) XFREE(item->buf, heap, DYNAMIC_TYPE_NONE); XFREE(item, heap, DYNAMIC_TYPE_DTLS_MSG); } } void DtlsMsgListDelete(DtlsMsg* head, void* heap) { DtlsMsg* next; while (head) { next = head->next; DtlsMsgDelete(head, heap); head = next; } } void DtlsMsgSet(DtlsMsg* msg, word32 seq, const byte* data, byte type, word32 fragOffset, word32 fragSz) { if (msg != NULL && data != NULL && msg->fragSz <= msg->sz && fragOffset <= msg->sz && (fragOffset + fragSz) <= msg->sz) { msg->seq = seq; msg->type = type; msg->fragSz += fragSz; /* If fragOffset is zero, this is either a full message that is out * of order, or the first fragment of a fragmented message. Copy the * handshake message header with the message data. Zero length messages * like Server Hello Done should be saved as well. */ if (fragOffset == 0) XMEMCPY(msg->buf, data - DTLS_HANDSHAKE_HEADER_SZ, fragSz + DTLS_HANDSHAKE_HEADER_SZ); else { /* If fragOffet is non-zero, this is an additional fragment that * needs to be copied to its location in the message buffer. Also * copy the total size of the message over the fragment size. The * hash routines look at a defragmented message if it had actually * come across as a single handshake message. */ XMEMCPY(msg->msg + fragOffset, data, fragSz); } c32to24(msg->sz, msg->msg - DTLS_HANDSHAKE_FRAG_SZ); } } DtlsMsg* DtlsMsgFind(DtlsMsg* head, word32 seq) { while (head != NULL && head->seq != seq) { head = head->next; } return head; } DtlsMsg* DtlsMsgStore(DtlsMsg* head, word32 seq, const byte* data, word32 dataSz, byte type, word32 fragOffset, word32 fragSz, void* heap) { /* See if seq exists in the list. If it isn't in the list, make * a new item of size dataSz, copy fragSz bytes from data to msg->msg * starting at offset fragOffset, and add fragSz to msg->fragSz. If * the seq is in the list and it isn't full, copy fragSz bytes from * data to msg->msg starting at offset fragOffset, and add fragSz to * msg->fragSz. The new item should be inserted into the list in its * proper position. * * 1. Find seq in list, or where seq should go in list. If seq not in * list, create new item and insert into list. Either case, keep * pointer to item. * 2. If msg->fragSz + fragSz < sz, copy data to msg->msg at offset * fragOffset. Add fragSz to msg->fragSz. */ if (head != NULL) { DtlsMsg* cur = DtlsMsgFind(head, seq); if (cur == NULL) { cur = DtlsMsgNew(dataSz, heap); if (cur != NULL) { DtlsMsgSet(cur, seq, data, type, fragOffset, fragSz); head = DtlsMsgInsert(head, cur); } } else { DtlsMsgSet(cur, seq, data, type, fragOffset, fragSz); } } else { head = DtlsMsgNew(dataSz, heap); DtlsMsgSet(head, seq, data, type, fragOffset, fragSz); } return head; } /* DtlsMsgInsert() is an in-order insert. */ DtlsMsg* DtlsMsgInsert(DtlsMsg* head, DtlsMsg* item) { if (head == NULL || item->seq < head->seq) { item->next = head; head = item; } else if (head->next == NULL) { head->next = item; } else { DtlsMsg* cur = head->next; DtlsMsg* prev = head; while (cur) { if (item->seq < cur->seq) { item->next = cur; prev->next = item; break; } prev = cur; cur = cur->next; } if (cur == NULL) { prev->next = item; } } return head; } #endif /* WOLFSSL_DTLS */ #ifndef NO_OLD_TLS #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Waggregate-return" ProtocolVersion MakeSSLv3(void) { ProtocolVersion pv; pv.major = SSLv3_MAJOR; pv.minor = SSLv3_MINOR; return pv; } #pragma GCC diagnostic pop #endif /* NO_OLD_TLS */ #ifdef WOLFSSL_DTLS ProtocolVersion MakeDTLSv1(void) { ProtocolVersion pv; pv.major = DTLS_MAJOR; pv.minor = DTLS_MINOR; return pv; } ProtocolVersion MakeDTLSv1_2(void) { ProtocolVersion pv; pv.major = DTLS_MAJOR; pv.minor = DTLSv1_2_MINOR; return pv; } #endif /* WOLFSSL_DTLS */ #ifdef USE_WINDOWS_API word32 LowResTimer(void) { static int init = 0; static LARGE_INTEGER freq; LARGE_INTEGER count; if (!init) { QueryPerformanceFrequency(&freq); init = 1; } QueryPerformanceCounter(&count); return (word32)(count.QuadPart / freq.QuadPart); } #elif defined(HAVE_RTP_SYS) #include "rtptime.h" word32 LowResTimer(void) { return (word32)rtp_get_system_sec(); } #elif defined(MICRIUM) word32 LowResTimer(void) { NET_SECURE_OS_TICK clk; #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) clk = NetSecure_OS_TimeGet(); #endif return (word32)clk; } #elif defined(MICROCHIP_TCPIP_V5) word32 LowResTimer(void) { return (word32) TickGet(); } #elif defined(MICROCHIP_TCPIP) #if defined(MICROCHIP_MPLAB_HARMONY) #include <system/tmr/sys_tmr.h> word32 LowResTimer(void) { return (word32) SYS_TMR_TickCountGet(); } #else word32 LowResTimer(void) { return (word32) SYS_TICK_Get(); } #endif #elif defined(FREESCALE_MQX) word32 LowResTimer(void) { TIME_STRUCT mqxTime; _time_get_elapsed(&mqxTime); return (word32) mqxTime.SECONDS; } #elif defined(WOLFSSL_TIRTOS) word32 LowResTimer(void) { return (word32) Seconds_get(); } #elif defined(USER_TICKS) #if 0 word32 LowResTimer(void) { /* write your own clock tick function if don't want time(0) needs second accuracy but doesn't have to correlated to EPOCH */ } #endif #elif defined(TIME_OVERRIDES) /* use same asn time overrides unless user wants tick override above */ #ifndef HAVE_TIME_T_TYPE typedef long time_t; #endif extern time_t XTIME(time_t * timer); word32 LowResTimer(void) { return (word32) XTIME(0); } #else /* !USE_WINDOWS_API && !HAVE_RTP_SYS && !MICRIUM && !USER_TICKS */ #include <time.h> word32 LowResTimer(void) { return (word32)time(0); } #endif /* USE_WINDOWS_API */ /* add output to md5 and sha handshake hashes, exclude record header */ static int HashOutput(WOLFSSL* ssl, const byte* output, int sz, int ivSz) { const byte* adj = output + RECORD_HEADER_SZ + ivSz; sz -= RECORD_HEADER_SZ; #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, output, sz, FUZZ_HASH, ssl->fuzzerCtx); #endif #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { adj += DTLS_RECORD_EXTRA; sz -= DTLS_RECORD_EXTRA; } #endif #ifndef NO_OLD_TLS #ifndef NO_SHA wc_ShaUpdate(&ssl->hsHashes->hashSha, adj, sz); #endif #ifndef NO_MD5 wc_Md5Update(&ssl->hsHashes->hashMd5, adj, sz); #endif #endif if (IsAtLeastTLSv1_2(ssl)) { int ret; #ifndef NO_SHA256 ret = wc_Sha256Update(&ssl->hsHashes->hashSha256, adj, sz); if (ret != 0) return ret; #endif #ifdef WOLFSSL_SHA384 ret = wc_Sha384Update(&ssl->hsHashes->hashSha384, adj, sz); if (ret != 0) return ret; #endif #ifdef WOLFSSL_SHA512 ret = wc_Sha512Update(&ssl->hsHashes->hashSha512, adj, sz); if (ret != 0) return ret; #endif } return 0; } /* add input to md5 and sha handshake hashes, include handshake header */ static int HashInput(WOLFSSL* ssl, const byte* input, int sz) { const byte* adj = input - HANDSHAKE_HEADER_SZ; sz += HANDSHAKE_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { adj -= DTLS_HANDSHAKE_EXTRA; sz += DTLS_HANDSHAKE_EXTRA; } #endif #ifndef NO_OLD_TLS #ifndef NO_SHA wc_ShaUpdate(&ssl->hsHashes->hashSha, adj, sz); #endif #ifndef NO_MD5 wc_Md5Update(&ssl->hsHashes->hashMd5, adj, sz); #endif #endif if (IsAtLeastTLSv1_2(ssl)) { int ret; #ifndef NO_SHA256 ret = wc_Sha256Update(&ssl->hsHashes->hashSha256, adj, sz); if (ret != 0) return ret; #endif #ifdef WOLFSSL_SHA384 ret = wc_Sha384Update(&ssl->hsHashes->hashSha384, adj, sz); if (ret != 0) return ret; #endif #ifdef WOLFSSL_SHA512 ret = wc_Sha512Update(&ssl->hsHashes->hashSha512, adj, sz); if (ret != 0) return ret; #endif } return 0; } /* add record layer header for message */ static void AddRecordHeader(byte* output, word32 length, byte type, WOLFSSL* ssl) { RecordLayerHeader* rl; /* record layer header */ rl = (RecordLayerHeader*)output; rl->type = type; rl->pvMajor = ssl->version.major; /* type and version same in each */ rl->pvMinor = ssl->version.minor; if (!ssl->options.dtls) c16toa((word16)length, rl->length); else { #ifdef WOLFSSL_DTLS DtlsRecordLayerHeader* dtls; /* dtls record layer header extensions */ dtls = (DtlsRecordLayerHeader*)output; c16toa(ssl->keys.dtls_epoch, dtls->epoch); c32to48(ssl->keys.dtls_sequence_number++, dtls->sequence_number); c16toa((word16)length, dtls->length); #endif } } /* add handshake header for message */ static void AddHandShakeHeader(byte* output, word32 length, byte type, WOLFSSL* ssl) { HandShakeHeader* hs; (void)ssl; /* handshake header */ hs = (HandShakeHeader*)output; hs->type = type; c32to24(length, hs->length); /* type and length same for each */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { DtlsHandShakeHeader* dtls; /* dtls handshake header extensions */ dtls = (DtlsHandShakeHeader*)output; c16toa(ssl->keys.dtls_handshake_number++, dtls->message_seq); c32to24(0, dtls->fragment_offset); c32to24(length, dtls->fragment_length); } #endif } /* add both headers for handshake message */ static void AddHeaders(byte* output, word32 length, byte type, WOLFSSL* ssl) { if (!ssl->options.dtls) { AddRecordHeader(output, length + HANDSHAKE_HEADER_SZ, handshake, ssl); AddHandShakeHeader(output + RECORD_HEADER_SZ, length, type, ssl); } #ifdef WOLFSSL_DTLS else { AddRecordHeader(output, length+DTLS_HANDSHAKE_HEADER_SZ, handshake,ssl); AddHandShakeHeader(output + DTLS_RECORD_HEADER_SZ, length, type, ssl); } #endif } /* return bytes received, -1 on error */ static int Receive(WOLFSSL* ssl, byte* buf, word32 sz) { int recvd; if (ssl->ctx->CBIORecv == NULL) { WOLFSSL_MSG("Your IO Recv callback is null, please set"); return -1; } retry: recvd = ssl->ctx->CBIORecv(ssl, (char *)buf, (int)sz, ssl->IOCB_ReadCtx); if (recvd < 0) switch (recvd) { case WOLFSSL_CBIO_ERR_GENERAL: /* general/unknown error */ return -1; case WOLFSSL_CBIO_ERR_WANT_READ: /* want read, would block */ return WANT_READ; case WOLFSSL_CBIO_ERR_CONN_RST: /* connection reset */ #ifdef USE_WINDOWS_API if (ssl->options.dtls) { goto retry; } #endif ssl->options.connReset = 1; return -1; case WOLFSSL_CBIO_ERR_ISR: /* interrupt */ /* see if we got our timeout */ #ifdef WOLFSSL_CALLBACKS if (ssl->toInfoOn) { struct itimerval timeout; getitimer(ITIMER_REAL, &timeout); if (timeout.it_value.tv_sec == 0 && timeout.it_value.tv_usec == 0) { XSTRNCPY(ssl->timeoutInfo.timeoutName, "recv() timeout", MAX_TIMEOUT_NAME_SZ); WOLFSSL_MSG("Got our timeout"); return WANT_READ; } } #endif goto retry; case WOLFSSL_CBIO_ERR_CONN_CLOSE: /* peer closed connection */ ssl->options.isClosed = 1; return -1; case WOLFSSL_CBIO_ERR_TIMEOUT: #ifdef WOLFSSL_DTLS if (DtlsPoolTimeout(ssl) == 0 && DtlsPoolSend(ssl) == 0) goto retry; else #endif return -1; default: return recvd; } return recvd; } /* Switch dynamic output buffer back to static, buffer is assumed clear */ void ShrinkOutputBuffer(WOLFSSL* ssl) { WOLFSSL_MSG("Shrinking output buffer\n"); XFREE(ssl->buffers.outputBuffer.buffer - ssl->buffers.outputBuffer.offset, ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); ssl->buffers.outputBuffer.buffer = ssl->buffers.outputBuffer.staticBuffer; ssl->buffers.outputBuffer.bufferSize = STATIC_BUFFER_LEN; ssl->buffers.outputBuffer.dynamicFlag = 0; ssl->buffers.outputBuffer.offset = 0; } /* Switch dynamic input buffer back to static, keep any remaining input */ /* forced free means cleaning up */ void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree) { int usedLength = ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx; if (!forcedFree && usedLength > STATIC_BUFFER_LEN) return; WOLFSSL_MSG("Shrinking input buffer\n"); if (!forcedFree && usedLength) XMEMCPY(ssl->buffers.inputBuffer.staticBuffer, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, usedLength); XFREE(ssl->buffers.inputBuffer.buffer - ssl->buffers.inputBuffer.offset, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); ssl->buffers.inputBuffer.buffer = ssl->buffers.inputBuffer.staticBuffer; ssl->buffers.inputBuffer.bufferSize = STATIC_BUFFER_LEN; ssl->buffers.inputBuffer.dynamicFlag = 0; ssl->buffers.inputBuffer.offset = 0; ssl->buffers.inputBuffer.idx = 0; ssl->buffers.inputBuffer.length = usedLength; } int SendBuffered(WOLFSSL* ssl) { if (ssl->ctx->CBIOSend == NULL) { WOLFSSL_MSG("Your IO Send callback is null, please set"); return SOCKET_ERROR_E; } while (ssl->buffers.outputBuffer.length > 0) { int sent = ssl->ctx->CBIOSend(ssl, (char*)ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.idx, (int)ssl->buffers.outputBuffer.length, ssl->IOCB_WriteCtx); if (sent < 0) { switch (sent) { case WOLFSSL_CBIO_ERR_WANT_WRITE: /* would block */ return WANT_WRITE; case WOLFSSL_CBIO_ERR_CONN_RST: /* connection reset */ ssl->options.connReset = 1; break; case WOLFSSL_CBIO_ERR_ISR: /* interrupt */ /* see if we got our timeout */ #ifdef WOLFSSL_CALLBACKS if (ssl->toInfoOn) { struct itimerval timeout; getitimer(ITIMER_REAL, &timeout); if (timeout.it_value.tv_sec == 0 && timeout.it_value.tv_usec == 0) { XSTRNCPY(ssl->timeoutInfo.timeoutName, "send() timeout", MAX_TIMEOUT_NAME_SZ); WOLFSSL_MSG("Got our timeout"); return WANT_WRITE; } } #endif continue; case WOLFSSL_CBIO_ERR_CONN_CLOSE: /* epipe / conn closed */ ssl->options.connReset = 1; /* treat same as reset */ break; default: return SOCKET_ERROR_E; } return SOCKET_ERROR_E; } if (sent > (int)ssl->buffers.outputBuffer.length) { WOLFSSL_MSG("SendBuffered() out of bounds read"); return SEND_OOB_READ_E; } ssl->buffers.outputBuffer.idx += sent; ssl->buffers.outputBuffer.length -= sent; } ssl->buffers.outputBuffer.idx = 0; if (ssl->buffers.outputBuffer.dynamicFlag) ShrinkOutputBuffer(ssl); return 0; } /* Grow the output buffer */ static INLINE int GrowOutputBuffer(WOLFSSL* ssl, int size) { byte* tmp; byte hdrSz = ssl->options.dtls ? DTLS_RECORD_HEADER_SZ : RECORD_HEADER_SZ; byte align = WOLFSSL_GENERAL_ALIGNMENT; /* the encrypted data will be offset from the front of the buffer by the header, if the user wants encrypted alignment they need to define their alignment requirement */ if (align) { while (align < hdrSz) align *= 2; } tmp = (byte*) XMALLOC(size + ssl->buffers.outputBuffer.length + align, ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); WOLFSSL_MSG("growing output buffer\n"); if (!tmp) return MEMORY_E; if (align) tmp += align - hdrSz; if (ssl->buffers.outputBuffer.length) XMEMCPY(tmp, ssl->buffers.outputBuffer.buffer, ssl->buffers.outputBuffer.length); if (ssl->buffers.outputBuffer.dynamicFlag) XFREE(ssl->buffers.outputBuffer.buffer - ssl->buffers.outputBuffer.offset, ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); ssl->buffers.outputBuffer.dynamicFlag = 1; if (align) ssl->buffers.outputBuffer.offset = align - hdrSz; else ssl->buffers.outputBuffer.offset = 0; ssl->buffers.outputBuffer.buffer = tmp; ssl->buffers.outputBuffer.bufferSize = size + ssl->buffers.outputBuffer.length; return 0; } /* Grow the input buffer, should only be to read cert or big app data */ int GrowInputBuffer(WOLFSSL* ssl, int size, int usedLength) { byte* tmp; byte hdrSz = DTLS_RECORD_HEADER_SZ; byte align = ssl->options.dtls ? WOLFSSL_GENERAL_ALIGNMENT : 0; /* the encrypted data will be offset from the front of the buffer by the dtls record header, if the user wants encrypted alignment they need to define their alignment requirement. in tls we read record header to get size of record and put actual data back at front, so don't need */ if (align) { while (align < hdrSz) align *= 2; } tmp = (byte*) XMALLOC(size + usedLength + align, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); WOLFSSL_MSG("growing input buffer\n"); if (!tmp) return MEMORY_E; if (align) tmp += align - hdrSz; if (usedLength) XMEMCPY(tmp, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, usedLength); if (ssl->buffers.inputBuffer.dynamicFlag) XFREE(ssl->buffers.inputBuffer.buffer - ssl->buffers.inputBuffer.offset, ssl->heap,DYNAMIC_TYPE_IN_BUFFER); ssl->buffers.inputBuffer.dynamicFlag = 1; if (align) ssl->buffers.inputBuffer.offset = align - hdrSz; else ssl->buffers.inputBuffer.offset = 0; ssl->buffers.inputBuffer.buffer = tmp; ssl->buffers.inputBuffer.bufferSize = size + usedLength; ssl->buffers.inputBuffer.idx = 0; ssl->buffers.inputBuffer.length = usedLength; return 0; } /* check available size into output buffer, make room if needed */ int CheckAvailableSize(WOLFSSL *ssl, int size) { if (size < 0) { WOLFSSL_MSG("CheckAvailableSize() called with negative number"); return BAD_FUNC_ARG; } if (ssl->buffers.outputBuffer.bufferSize - ssl->buffers.outputBuffer.length < (word32)size) { if (GrowOutputBuffer(ssl, size) < 0) return MEMORY_E; } return 0; } /* do all verify and sanity checks on record header */ static int GetRecordHeader(WOLFSSL* ssl, const byte* input, word32* inOutIdx, RecordLayerHeader* rh, word16 *size) { if (!ssl->options.dtls) { #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, input + *inOutIdx, RECORD_HEADER_SZ, FUZZ_HEAD, ssl->fuzzerCtx); #endif XMEMCPY(rh, input + *inOutIdx, RECORD_HEADER_SZ); *inOutIdx += RECORD_HEADER_SZ; ato16(rh->length, size); } else { #ifdef WOLFSSL_DTLS /* type and version in same sport */ XMEMCPY(rh, input + *inOutIdx, ENUM_LEN + VERSION_SZ); *inOutIdx += ENUM_LEN + VERSION_SZ; ato16(input + *inOutIdx, &ssl->keys.dtls_state.curEpoch); *inOutIdx += 4; /* advance past epoch, skip first 2 seq bytes for now */ ato32(input + *inOutIdx, &ssl->keys.dtls_state.curSeq); *inOutIdx += 4; /* advance past rest of seq */ ato16(input + *inOutIdx, size); *inOutIdx += LENGTH_SZ; #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, input + *inOutIdx - LENGTH_SZ - 8 - ENUM_LEN - VERSION_SZ, ENUM_LEN + VERSION_SZ + 8 + LENGTH_SZ, FUZZ_HEAD, ssl->fuzzerCtx); #endif #endif } /* catch version mismatch */ if (rh->pvMajor != ssl->version.major || rh->pvMinor != ssl->version.minor){ if (ssl->options.side == WOLFSSL_SERVER_END && ssl->options.acceptState == ACCEPT_BEGIN) WOLFSSL_MSG("Client attempting to connect with different version"); else if (ssl->options.side == WOLFSSL_CLIENT_END && ssl->options.downgrade && ssl->options.connectState < FIRST_REPLY_DONE) WOLFSSL_MSG("Server attempting to accept with different version"); else { WOLFSSL_MSG("SSL version error"); return VERSION_ERROR; /* only use requested version */ } } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if (DtlsCheckWindow(&ssl->keys.dtls_state) != 1) return SEQUENCE_ERROR; } #endif /* record layer length check */ #ifdef HAVE_MAX_FRAGMENT if (*size > (ssl->max_fragment + MAX_COMP_EXTRA + MAX_MSG_EXTRA)) { SendAlert(ssl, alert_fatal, record_overflow); return LENGTH_ERROR; } #else if (*size > (MAX_RECORD_SIZE + MAX_COMP_EXTRA + MAX_MSG_EXTRA)) return LENGTH_ERROR; #endif /* verify record type here as well */ switch (rh->type) { case handshake: case change_cipher_spec: case application_data: case alert: break; case no_type: default: WOLFSSL_MSG("Unknown Record Type"); return UNKNOWN_RECORD_TYPE; } /* haven't decrypted this record yet */ ssl->keys.decryptedCur = 0; return 0; } static int GetHandShakeHeader(WOLFSSL* ssl, const byte* input, word32* inOutIdx, byte *type, word32 *size, word32 totalSz) { const byte *ptr = input + *inOutIdx; (void)ssl; *inOutIdx += HANDSHAKE_HEADER_SZ; if (*inOutIdx > totalSz) return BUFFER_E; *type = ptr[0]; c24to32(&ptr[1], size); return 0; } #ifdef WOLFSSL_DTLS static int GetDtlsHandShakeHeader(WOLFSSL* ssl, const byte* input, word32* inOutIdx, byte *type, word32 *size, word32 *fragOffset, word32 *fragSz, word32 totalSz) { word32 idx = *inOutIdx; *inOutIdx += HANDSHAKE_HEADER_SZ + DTLS_HANDSHAKE_EXTRA; if (*inOutIdx > totalSz) return BUFFER_E; *type = input[idx++]; c24to32(input + idx, size); idx += BYTE3_LEN; ato16(input + idx, &ssl->keys.dtls_peer_handshake_number); idx += DTLS_HANDSHAKE_SEQ_SZ; c24to32(input + idx, fragOffset); idx += DTLS_HANDSHAKE_FRAG_SZ; c24to32(input + idx, fragSz); return 0; } #endif #ifndef NO_OLD_TLS /* fill with MD5 pad size since biggest required */ static const byte PAD1[PAD_MD5] = { 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 }; static const byte PAD2[PAD_MD5] = { 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c }; /* calculate MD5 hash for finished */ #ifdef WOLFSSL_TI_HASH #include <wolfssl/wolfcrypt/hash.h> #endif static void BuildMD5(WOLFSSL* ssl, Hashes* hashes, const byte* sender) { byte md5_result[MD5_DIGEST_SIZE]; #ifdef WOLFSSL_SMALL_STACK Md5* md5 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); Md5* md5_2 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); #else Md5 md5[1]; Md5 md5_2[1]; #endif /* make md5 inner */ md5[0] = ssl->hsHashes->hashMd5 ; /* Save current position */ wc_Md5Update(&ssl->hsHashes->hashMd5, sender, SIZEOF_SENDER); wc_Md5Update(&ssl->hsHashes->hashMd5, ssl->arrays->masterSecret,SECRET_LEN); wc_Md5Update(&ssl->hsHashes->hashMd5, PAD1, PAD_MD5); wc_Md5GetHash(&ssl->hsHashes->hashMd5, md5_result); wc_Md5RestorePos(&ssl->hsHashes->hashMd5, md5) ; /* Restore current position */ /* make md5 outer */ wc_InitMd5(md5_2) ; wc_Md5Update(md5_2, ssl->arrays->masterSecret,SECRET_LEN); wc_Md5Update(md5_2, PAD2, PAD_MD5); wc_Md5Update(md5_2, md5_result, MD5_DIGEST_SIZE); wc_Md5Final(md5_2, hashes->md5); #ifdef WOLFSSL_SMALL_STACK XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(md5_2, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } /* calculate SHA hash for finished */ static void BuildSHA(WOLFSSL* ssl, Hashes* hashes, const byte* sender) { byte sha_result[SHA_DIGEST_SIZE]; #ifdef WOLFSSL_SMALL_STACK Sha* sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); Sha* sha2 = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); #else Sha sha[1]; Sha sha2[1] ; #endif /* make sha inner */ sha[0] = ssl->hsHashes->hashSha ; /* Save current position */ wc_ShaUpdate(&ssl->hsHashes->hashSha, sender, SIZEOF_SENDER); wc_ShaUpdate(&ssl->hsHashes->hashSha, ssl->arrays->masterSecret,SECRET_LEN); wc_ShaUpdate(&ssl->hsHashes->hashSha, PAD1, PAD_SHA); wc_ShaGetHash(&ssl->hsHashes->hashSha, sha_result); wc_ShaRestorePos(&ssl->hsHashes->hashSha, sha) ; /* Restore current position */ /* make sha outer */ wc_InitSha(sha2) ; wc_ShaUpdate(sha2, ssl->arrays->masterSecret,SECRET_LEN); wc_ShaUpdate(sha2, PAD2, PAD_SHA); wc_ShaUpdate(sha2, sha_result, SHA_DIGEST_SIZE); wc_ShaFinal(sha2, hashes->sha); #ifdef WOLFSSL_SMALL_STACK XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(sha2, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } #endif /* Finished doesn't support SHA512, not SHA512 cipher suites yet */ static int BuildFinished(WOLFSSL* ssl, Hashes* hashes, const byte* sender) { int ret = 0; #ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SHA384 Sha384* sha384 = (Sha384*)XMALLOC(sizeof(Sha384), NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #else #ifdef WOLFSSL_SHA384 Sha384 sha384[1]; #endif #endif #ifdef WOLFSSL_SMALL_STACK if (ssl == NULL #ifdef WOLFSSL_SHA384 || sha384 == NULL #endif ) { #ifdef WOLFSSL_SHA384 XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return MEMORY_E; } #endif /* store current states, building requires get_digest which resets state */ #ifdef WOLFSSL_SHA384 sha384[0] = ssl->hsHashes->hashSha384; #endif #ifndef NO_TLS if (ssl->options.tls) { ret = BuildTlsFinished(ssl, hashes, sender); } #endif #ifndef NO_OLD_TLS if (!ssl->options.tls) { BuildMD5(ssl, hashes, sender); BuildSHA(ssl, hashes, sender); } #endif /* restore */ if (IsAtLeastTLSv1_2(ssl)) { #ifdef WOLFSSL_SHA384 ssl->hsHashes->hashSha384 = sha384[0]; #endif } #ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SHA384 XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #endif return ret; } /* cipher requirements */ enum { REQUIRES_RSA, REQUIRES_DHE, REQUIRES_ECC_DSA, REQUIRES_ECC_STATIC, REQUIRES_PSK, REQUIRES_NTRU, REQUIRES_RSA_SIG }; /* Does this cipher suite (first, second) have the requirement an ephemeral key exchange will still require the key for signing the key exchange so ECHDE_RSA requires an rsa key thus rsa_kea */ static int CipherRequires(byte first, byte second, int requirement) { if (first == CHACHA_BYTE) { switch (second) { case TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_DHE) return 1; break; } } /* ECC extensions */ if (first == ECC_BYTE) { switch (second) { #ifndef NO_RSA case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; #ifndef NO_DES3 case TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; #endif #ifndef NO_RC4 case TLS_ECDHE_RSA_WITH_RC4_128_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDH_RSA_WITH_RC4_128_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; #endif #endif /* NO_RSA */ #ifndef NO_DES3 case TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; break; #endif #ifndef NO_RC4 case TLS_ECDHE_ECDSA_WITH_RC4_128_SHA : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDH_ECDSA_WITH_RC4_128_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; break; #endif #ifndef NO_RSA case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; #endif case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; break; case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_ECC_STATIC) return 1; break; case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 : if (requirement == REQUIRES_ECC_STATIC) return 1; break; case TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 : if (requirement == REQUIRES_ECC_STATIC) return 1; break; #ifndef NO_RSA case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 : if (requirement == REQUIRES_ECC_STATIC) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; case TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 : if (requirement == REQUIRES_ECC_STATIC) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; case TLS_RSA_WITH_AES_128_CCM_8 : case TLS_RSA_WITH_AES_256_CCM_8 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 : case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; break; case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 : case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 : if (requirement == REQUIRES_RSA_SIG) return 1; if (requirement == REQUIRES_ECC_STATIC) return 1; break; #endif case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 : case TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 : case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 : if (requirement == REQUIRES_ECC_DSA) return 1; break; case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 : case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 : if (requirement == REQUIRES_ECC_DSA) return 1; if (requirement == REQUIRES_ECC_STATIC) return 1; break; case TLS_PSK_WITH_AES_128_CCM: case TLS_PSK_WITH_AES_256_CCM: case TLS_PSK_WITH_AES_128_CCM_8: case TLS_PSK_WITH_AES_256_CCM_8: if (requirement == REQUIRES_PSK) return 1; break; case TLS_DHE_PSK_WITH_AES_128_CCM: case TLS_DHE_PSK_WITH_AES_256_CCM: if (requirement == REQUIRES_PSK) return 1; if (requirement == REQUIRES_DHE) return 1; break; default: WOLFSSL_MSG("Unsupported cipher suite, CipherRequires ECC"); return 0; } /* switch */ } /* if */ if (first != ECC_BYTE) { /* normal suites */ switch (second) { #ifndef NO_RSA case SSL_RSA_WITH_RC4_128_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_NTRU_RSA_WITH_RC4_128_SHA : if (requirement == REQUIRES_NTRU) return 1; break; case SSL_RSA_WITH_RC4_128_MD5 : if (requirement == REQUIRES_RSA) return 1; break; case SSL_RSA_WITH_3DES_EDE_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA : if (requirement == REQUIRES_NTRU) return 1; break; case TLS_RSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_AES_128_CBC_SHA256 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_NTRU_RSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_NTRU) return 1; break; case TLS_RSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_AES_256_CBC_SHA256 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_NULL_SHA : case TLS_RSA_WITH_NULL_SHA256 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_NTRU_RSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_NTRU) return 1; break; #endif case TLS_PSK_WITH_AES_128_GCM_SHA256 : case TLS_PSK_WITH_AES_256_GCM_SHA384 : case TLS_PSK_WITH_AES_128_CBC_SHA256 : case TLS_PSK_WITH_AES_256_CBC_SHA384 : case TLS_PSK_WITH_AES_128_CBC_SHA : case TLS_PSK_WITH_AES_256_CBC_SHA : case TLS_PSK_WITH_NULL_SHA384 : case TLS_PSK_WITH_NULL_SHA256 : case TLS_PSK_WITH_NULL_SHA : if (requirement == REQUIRES_PSK) return 1; break; case TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 : case TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 : case TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 : case TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 : case TLS_DHE_PSK_WITH_NULL_SHA384 : case TLS_DHE_PSK_WITH_NULL_SHA256 : if (requirement == REQUIRES_DHE) return 1; if (requirement == REQUIRES_PSK) return 1; break; #ifndef NO_RSA case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_DHE) return 1; break; case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_DHE) return 1; break; case TLS_DHE_RSA_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_DHE) return 1; break; case TLS_DHE_RSA_WITH_AES_256_CBC_SHA : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_DHE) return 1; break; case TLS_RSA_WITH_HC_128_MD5 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_HC_128_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_HC_128_B2B256: if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_AES_128_CBC_B2B256: case TLS_RSA_WITH_AES_256_CBC_B2B256: if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_RABBIT_SHA : if (requirement == REQUIRES_RSA) return 1; break; case TLS_RSA_WITH_AES_128_GCM_SHA256 : case TLS_RSA_WITH_AES_256_GCM_SHA384 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 : case TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_DHE) return 1; break; case TLS_RSA_WITH_CAMELLIA_128_CBC_SHA : case TLS_RSA_WITH_CAMELLIA_256_CBC_SHA : case TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 : case TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 : if (requirement == REQUIRES_RSA) return 1; break; case TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA : case TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA : case TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 : case TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 : if (requirement == REQUIRES_RSA) return 1; if (requirement == REQUIRES_RSA_SIG) return 1; if (requirement == REQUIRES_DHE) return 1; break; #endif #ifdef HAVE_ANON case TLS_DH_anon_WITH_AES_128_CBC_SHA : if (requirement == REQUIRES_DHE) return 1; break; #endif default: WOLFSSL_MSG("Unsupported cipher suite, CipherRequires"); return 0; } /* switch */ } /* if ECC / Normal suites else */ return 0; } #ifndef NO_CERTS /* Match names with wildcards, each wildcard can represent a single name component or fragment but not mulitple names, i.e., *.z.com matches y.z.com but not x.y.z.com return 1 on success */ static int MatchDomainName(const char* pattern, int len, const char* str) { char p, s; if (pattern == NULL || str == NULL || len <= 0) return 0; while (len > 0) { p = (char)XTOLOWER((unsigned char)*pattern++); if (p == 0) break; if (p == '*') { while (--len > 0 && (p = (char)XTOLOWER((unsigned char)*pattern++)) == '*') ; if (len == 0) p = '\0'; while ( (s = (char)XTOLOWER((unsigned char) *str)) != '\0') { if (s == p) break; if (s == '.') return 0; str++; } } else { if (p != (char)XTOLOWER((unsigned char) *str)) return 0; } if (*str != '\0') str++; if (len > 0) len--; } return *str == '\0'; } /* try to find an altName match to domain, return 1 on success */ static int CheckAltNames(DecodedCert* dCert, char* domain) { int match = 0; DNS_entry* altName = NULL; WOLFSSL_MSG("Checking AltNames"); if (dCert) altName = dCert->altNames; while (altName) { WOLFSSL_MSG(" individual AltName check"); if (MatchDomainName(altName->name,(int)XSTRLEN(altName->name), domain)){ match = 1; break; } altName = altName->next; } return match; } #if defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) /* Copy parts X509 needs from Decoded cert, 0 on success */ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert) { int ret = 0; if (x509 == NULL || dCert == NULL) return BAD_FUNC_ARG; x509->version = dCert->version + 1; XSTRNCPY(x509->issuer.name, dCert->issuer, ASN_NAME_MAX); x509->issuer.name[ASN_NAME_MAX - 1] = '\0'; x509->issuer.sz = (int)XSTRLEN(x509->issuer.name) + 1; #ifdef OPENSSL_EXTRA if (dCert->issuerName.fullName != NULL) { XMEMCPY(&x509->issuer.fullName, &dCert->issuerName, sizeof(DecodedName)); x509->issuer.fullName.fullName = (char*)XMALLOC( dCert->issuerName.fullNameLen, NULL, DYNAMIC_TYPE_X509); if (x509->issuer.fullName.fullName != NULL) XMEMCPY(x509->issuer.fullName.fullName, dCert->issuerName.fullName, dCert->issuerName.fullNameLen); } #endif /* OPENSSL_EXTRA */ XSTRNCPY(x509->subject.name, dCert->subject, ASN_NAME_MAX); x509->subject.name[ASN_NAME_MAX - 1] = '\0'; x509->subject.sz = (int)XSTRLEN(x509->subject.name) + 1; #ifdef OPENSSL_EXTRA if (dCert->subjectName.fullName != NULL) { XMEMCPY(&x509->subject.fullName, &dCert->subjectName, sizeof(DecodedName)); x509->subject.fullName.fullName = (char*)XMALLOC( dCert->subjectName.fullNameLen, NULL, DYNAMIC_TYPE_X509); if (x509->subject.fullName.fullName != NULL) XMEMCPY(x509->subject.fullName.fullName, dCert->subjectName.fullName, dCert->subjectName.fullNameLen); } #endif /* OPENSSL_EXTRA */ XMEMCPY(x509->serial, dCert->serial, EXTERNAL_SERIAL_SIZE); x509->serialSz = dCert->serialSz; if (dCert->subjectCNLen < ASN_NAME_MAX) { XMEMCPY(x509->subjectCN, dCert->subjectCN, dCert->subjectCNLen); x509->subjectCN[dCert->subjectCNLen] = '\0'; } else x509->subjectCN[0] = '\0'; #ifdef WOLFSSL_SEP { int minSz = min(dCert->deviceTypeSz, EXTERNAL_SERIAL_SIZE); if (minSz > 0) { x509->deviceTypeSz = minSz; XMEMCPY(x509->deviceType, dCert->deviceType, minSz); } else x509->deviceTypeSz = 0; minSz = min(dCert->hwTypeSz, EXTERNAL_SERIAL_SIZE); if (minSz != 0) { x509->hwTypeSz = minSz; XMEMCPY(x509->hwType, dCert->hwType, minSz); } else x509->hwTypeSz = 0; minSz = min(dCert->hwSerialNumSz, EXTERNAL_SERIAL_SIZE); if (minSz != 0) { x509->hwSerialNumSz = minSz; XMEMCPY(x509->hwSerialNum, dCert->hwSerialNum, minSz); } else x509->hwSerialNumSz = 0; } #endif /* WOLFSSL_SEP */ { int minSz = min(dCert->beforeDateLen, MAX_DATE_SZ); if (minSz != 0) { x509->notBeforeSz = minSz; XMEMCPY(x509->notBefore, dCert->beforeDate, minSz); } else x509->notBeforeSz = 0; minSz = min(dCert->afterDateLen, MAX_DATE_SZ); if (minSz != 0) { x509->notAfterSz = minSz; XMEMCPY(x509->notAfter, dCert->afterDate, minSz); } else x509->notAfterSz = 0; } if (dCert->publicKey != NULL && dCert->pubKeySize != 0) { x509->pubKey.buffer = (byte*)XMALLOC( dCert->pubKeySize, NULL, DYNAMIC_TYPE_PUBLIC_KEY); if (x509->pubKey.buffer != NULL) { x509->pubKeyOID = dCert->keyOID; x509->pubKey.length = dCert->pubKeySize; XMEMCPY(x509->pubKey.buffer, dCert->publicKey, dCert->pubKeySize); } else ret = MEMORY_E; } if (dCert->signature != NULL && dCert->sigLength != 0) { x509->sig.buffer = (byte*)XMALLOC( dCert->sigLength, NULL, DYNAMIC_TYPE_SIGNATURE); if (x509->sig.buffer == NULL) { ret = MEMORY_E; } else { XMEMCPY(x509->sig.buffer, dCert->signature, dCert->sigLength); x509->sig.length = dCert->sigLength; x509->sigOID = dCert->signatureOID; } } /* store cert for potential retrieval */ x509->derCert.buffer = (byte*)XMALLOC(dCert->maxIdx, NULL, DYNAMIC_TYPE_CERT); if (x509->derCert.buffer == NULL) { ret = MEMORY_E; } else { XMEMCPY(x509->derCert.buffer, dCert->source, dCert->maxIdx); x509->derCert.length = dCert->maxIdx; } x509->altNames = dCert->altNames; dCert->weOwnAltNames = 0; x509->altNamesNext = x509->altNames; /* index hint */ x509->isCa = dCert->isCA; #ifdef OPENSSL_EXTRA x509->pathLength = dCert->pathLength; x509->keyUsage = dCert->extKeyUsage; x509->basicConstSet = dCert->extBasicConstSet; x509->basicConstCrit = dCert->extBasicConstCrit; x509->basicConstPlSet = dCert->extBasicConstPlSet; x509->subjAltNameSet = dCert->extSubjAltNameSet; x509->subjAltNameCrit = dCert->extSubjAltNameCrit; x509->authKeyIdSet = dCert->extAuthKeyIdSet; x509->authKeyIdCrit = dCert->extAuthKeyIdCrit; if (dCert->extAuthKeyIdSrc != NULL && dCert->extAuthKeyIdSz != 0) { x509->authKeyId = (byte*)XMALLOC(dCert->extAuthKeyIdSz, NULL, 0); if (x509->authKeyId != NULL) { XMEMCPY(x509->authKeyId, dCert->extAuthKeyIdSrc, dCert->extAuthKeyIdSz); x509->authKeyIdSz = dCert->extAuthKeyIdSz; } else ret = MEMORY_E; } x509->subjKeyIdSet = dCert->extSubjKeyIdSet; x509->subjKeyIdCrit = dCert->extSubjKeyIdCrit; if (dCert->extSubjKeyIdSrc != NULL && dCert->extSubjKeyIdSz != 0) { x509->subjKeyId = (byte*)XMALLOC(dCert->extSubjKeyIdSz, NULL, 0); if (x509->subjKeyId != NULL) { XMEMCPY(x509->subjKeyId, dCert->extSubjKeyIdSrc, dCert->extSubjKeyIdSz); x509->subjKeyIdSz = dCert->extSubjKeyIdSz; } else ret = MEMORY_E; } x509->keyUsageSet = dCert->extKeyUsageSet; x509->keyUsageCrit = dCert->extKeyUsageCrit; #ifdef WOLFSSL_SEP x509->certPolicySet = dCert->extCertPolicySet; x509->certPolicyCrit = dCert->extCertPolicyCrit; #endif /* WOLFSSL_SEP */ #endif /* OPENSSL_EXTRA */ #ifdef HAVE_ECC x509->pkCurveOID = dCert->pkCurveOID; #endif /* HAVE_ECC */ return ret; } #endif /* KEEP_PEER_CERT || SESSION_CERTS */ static int DoCertificate(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size) { word32 listSz; word32 begin = *inOutIdx; int ret = 0; int anyError = 0; int totalCerts = 0; /* number of certs in certs buffer */ int count; buffer certs[MAX_CHAIN_DEPTH]; #ifdef WOLFSSL_SMALL_STACK char* domain = NULL; DecodedCert* dCert = NULL; WOLFSSL_X509_STORE_CTX* store = NULL; #else char domain[ASN_NAME_MAX]; DecodedCert dCert[1]; WOLFSSL_X509_STORE_CTX store[1]; #endif #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Certificate", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("Certificate", &ssl->timeoutInfo); #endif if ((*inOutIdx - begin) + OPAQUE24_LEN > size) return BUFFER_ERROR; c24to32(input + *inOutIdx, &listSz); *inOutIdx += OPAQUE24_LEN; #ifdef HAVE_MAX_FRAGMENT if (listSz > ssl->max_fragment) { SendAlert(ssl, alert_fatal, record_overflow); return BUFFER_E; } #else if (listSz > MAX_RECORD_SIZE) return BUFFER_E; #endif if ((*inOutIdx - begin) + listSz != size) return BUFFER_ERROR; WOLFSSL_MSG("Loading peer's cert chain"); /* first put cert chain into buffer so can verify top down we're sent bottom up */ while (listSz) { word32 certSz; if (totalCerts >= MAX_CHAIN_DEPTH) return MAX_CHAIN_ERROR; if ((*inOutIdx - begin) + OPAQUE24_LEN > size) return BUFFER_ERROR; c24to32(input + *inOutIdx, &certSz); *inOutIdx += OPAQUE24_LEN; if ((*inOutIdx - begin) + certSz > size) return BUFFER_ERROR; certs[totalCerts].length = certSz; certs[totalCerts].buffer = input + *inOutIdx; #ifdef SESSION_CERTS if (ssl->session.chain.count < MAX_CHAIN_DEPTH && certSz < MAX_X509_SIZE) { ssl->session.chain.certs[ssl->session.chain.count].length = certSz; XMEMCPY(ssl->session.chain.certs[ssl->session.chain.count].buffer, input + *inOutIdx, certSz); ssl->session.chain.count++; } else { WOLFSSL_MSG("Couldn't store chain cert for session"); } #endif *inOutIdx += certSz; listSz -= certSz + CERT_HEADER_SZ; totalCerts++; WOLFSSL_MSG(" Put another cert into chain"); } count = totalCerts; #ifdef WOLFSSL_SMALL_STACK dCert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (dCert == NULL) return MEMORY_E; #endif /* verify up to peer's first */ while (count > 1) { buffer myCert = certs[count - 1]; byte* subjectHash; InitDecodedCert(dCert, myCert.buffer, myCert.length, ssl->heap); ret = ParseCertRelative(dCert, CERT_TYPE, !ssl->options.verifyNone, ssl->ctx->cm); #ifndef NO_SKID subjectHash = dCert->extSubjKeyId; #else subjectHash = dCert->subjectHash; #endif if (ret == 0 && dCert->isCA == 0) { WOLFSSL_MSG("Chain cert is not a CA, not adding as one"); } else if (ret == 0 && ssl->options.verifyNone) { WOLFSSL_MSG("Chain cert not verified by option, not adding as CA"); } else if (ret == 0 && !AlreadySigner(ssl->ctx->cm, subjectHash)) { buffer add; add.length = myCert.length; add.buffer = (byte*)XMALLOC(myCert.length, ssl->heap, DYNAMIC_TYPE_CA); WOLFSSL_MSG("Adding CA from chain"); if (add.buffer == NULL) return MEMORY_E; XMEMCPY(add.buffer, myCert.buffer, myCert.length); ret = AddCA(ssl->ctx->cm, add, WOLFSSL_CHAIN_CA, ssl->ctx->verifyPeer); if (ret == 1) ret = 0; /* SSL_SUCCESS for external */ } else if (ret != 0) { WOLFSSL_MSG("Failed to verify CA from chain"); } else { WOLFSSL_MSG("Verified CA from chain and already had it"); } #if defined(HAVE_OCSP) || defined(HAVE_CRL) if (ret == 0) { int doCrlLookup = 1; (void)doCrlLookup; #ifdef HAVE_OCSP if (ssl->ctx->cm->ocspEnabled && ssl->ctx->cm->ocspCheckAll) { WOLFSSL_MSG("Doing Non Leaf OCSP check"); ret = CheckCertOCSP(ssl->ctx->cm->ocsp, dCert); doCrlLookup = (ret == OCSP_CERT_UNKNOWN); if (ret != 0) { doCrlLookup = 0; WOLFSSL_MSG("\tOCSP Lookup not ok"); } } #endif /* HAVE_OCSP */ #ifdef HAVE_CRL if (doCrlLookup && ssl->ctx->cm->crlEnabled && ssl->ctx->cm->crlCheckAll) { WOLFSSL_MSG("Doing Non Leaf CRL check"); ret = CheckCertCRL(ssl->ctx->cm->crl, dCert); if (ret != 0) { WOLFSSL_MSG("\tCRL check not ok"); } } #endif /* HAVE_CRL */ } #endif /* HAVE_OCSP || HAVE_CRL */ if (ret != 0 && anyError == 0) anyError = ret; /* save error from last time */ FreeDecodedCert(dCert); count--; } /* peer's, may not have one if blank client cert sent by TLSv1.2 */ if (count) { buffer myCert = certs[0]; int fatal = 0; WOLFSSL_MSG("Verifying Peer's cert"); InitDecodedCert(dCert, myCert.buffer, myCert.length, ssl->heap); ret = ParseCertRelative(dCert, CERT_TYPE, !ssl->options.verifyNone, ssl->ctx->cm); if (ret == 0) { WOLFSSL_MSG("Verified Peer's cert"); fatal = 0; } else if (ret == ASN_PARSE_E) { WOLFSSL_MSG("Got Peer cert ASN PARSE ERROR, fatal"); fatal = 1; } else { WOLFSSL_MSG("Failed to verify Peer's cert"); if (ssl->verifyCallback) { WOLFSSL_MSG("\tCallback override available, will continue"); fatal = 0; } else { WOLFSSL_MSG("\tNo callback override available, fatal"); fatal = 1; } } #ifdef HAVE_SECURE_RENEGOTIATION if (fatal == 0 && ssl->secure_renegotiation && ssl->secure_renegotiation->enabled) { if (ssl->keys.encryptionOn) { /* compare against previous time */ if (XMEMCMP(dCert->subjectHash, ssl->secure_renegotiation->subject_hash, SHA_DIGEST_SIZE) != 0) { WOLFSSL_MSG("Peer sent different cert during scr, fatal"); fatal = 1; ret = SCR_DIFFERENT_CERT_E; } } /* cache peer's hash */ if (fatal == 0) { XMEMCPY(ssl->secure_renegotiation->subject_hash, dCert->subjectHash, SHA_DIGEST_SIZE); } } #endif #if defined(HAVE_OCSP) || defined(HAVE_CRL) if (fatal == 0) { int doCrlLookup = 1; (void)doCrlLookup; #ifdef HAVE_OCSP if (ssl->ctx->cm->ocspEnabled) { ret = CheckCertOCSP(ssl->ctx->cm->ocsp, dCert); doCrlLookup = (ret == OCSP_CERT_UNKNOWN); if (ret != 0) { WOLFSSL_MSG("\tOCSP Lookup not ok"); fatal = 0; } } #endif /* HAVE_OCSP */ #ifdef HAVE_CRL if (doCrlLookup && ssl->ctx->cm->crlEnabled) { WOLFSSL_MSG("Doing Leaf CRL check"); ret = CheckCertCRL(ssl->ctx->cm->crl, dCert); if (ret != 0) { WOLFSSL_MSG("\tCRL check not ok"); fatal = 0; } } #endif /* HAVE_CRL */ } #endif /* HAVE_OCSP || HAVE_CRL */ #ifdef KEEP_PEER_CERT { /* set X509 format for peer cert even if fatal */ int copyRet = CopyDecodedToX509(&ssl->peerCert, dCert); if (copyRet == MEMORY_E) fatal = 1; } #endif #ifndef IGNORE_KEY_EXTENSIONS if (dCert->extKeyUsageSet) { if ((ssl->specs.kea == rsa_kea) && (dCert->extKeyUsage & KEYUSE_KEY_ENCIPHER) == 0) { ret = KEYUSE_ENCIPHER_E; } if ((ssl->specs.sig_algo == rsa_sa_algo || (ssl->specs.sig_algo == ecc_dsa_sa_algo && !ssl->specs.static_ecdh)) && (dCert->extKeyUsage & KEYUSE_DIGITAL_SIG) == 0) { WOLFSSL_MSG("KeyUse Digital Sig not set"); ret = KEYUSE_SIGNATURE_E; } } if (dCert->extExtKeyUsageSet) { if (ssl->options.side == WOLFSSL_CLIENT_END) { if ((dCert->extExtKeyUsage & (EXTKEYUSE_ANY | EXTKEYUSE_SERVER_AUTH)) == 0) { WOLFSSL_MSG("ExtKeyUse Server Auth not set"); ret = EXTKEYUSE_AUTH_E; } } else { if ((dCert->extExtKeyUsage & (EXTKEYUSE_ANY | EXTKEYUSE_CLIENT_AUTH)) == 0) { WOLFSSL_MSG("ExtKeyUse Client Auth not set"); ret = EXTKEYUSE_AUTH_E; } } } #endif /* IGNORE_KEY_EXTENSIONS */ if (fatal) { FreeDecodedCert(dCert); #ifdef WOLFSSL_SMALL_STACK XFREE(dCert, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif ssl->error = ret; return ret; } ssl->options.havePeerCert = 1; #ifdef WOLFSSL_SMALL_STACK domain = (char*)XMALLOC(ASN_NAME_MAX, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (domain == NULL) { FreeDecodedCert(dCert); XFREE(dCert, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } #endif /* store for callback use */ if (dCert->subjectCNLen < ASN_NAME_MAX) { XMEMCPY(domain, dCert->subjectCN, dCert->subjectCNLen); domain[dCert->subjectCNLen] = '\0'; } else domain[0] = '\0'; if (!ssl->options.verifyNone && ssl->buffers.domainName.buffer) { if (MatchDomainName(dCert->subjectCN, dCert->subjectCNLen, (char*)ssl->buffers.domainName.buffer) == 0) { WOLFSSL_MSG("DomainName match on common name failed"); if (CheckAltNames(dCert, (char*)ssl->buffers.domainName.buffer) == 0 ) { WOLFSSL_MSG("DomainName match on alt names failed too"); ret = DOMAIN_NAME_MISMATCH; /* try to get peer key still */ } } } /* decode peer key */ switch (dCert->keyOID) { #ifndef NO_RSA case RSAk: { word32 idx = 0; int keyRet = 0; if (ssl->peerRsaKey == NULL) { ssl->peerRsaKey = (RsaKey*)XMALLOC(sizeof(RsaKey), ssl->heap, DYNAMIC_TYPE_RSA); if (ssl->peerRsaKey == NULL) { WOLFSSL_MSG("PeerRsaKey Memory error"); keyRet = MEMORY_E; } else { keyRet = wc_InitRsaKey(ssl->peerRsaKey, ssl->ctx->heap); } } else if (ssl->peerRsaKeyPresent) { /* don't leak on reuse */ wc_FreeRsaKey(ssl->peerRsaKey); ssl->peerRsaKeyPresent = 0; keyRet = wc_InitRsaKey(ssl->peerRsaKey, ssl->heap); } if (keyRet != 0 || wc_RsaPublicKeyDecode(dCert->publicKey, &idx, ssl->peerRsaKey, dCert->pubKeySize) != 0) { ret = PEER_KEY_ERROR; } else { ssl->peerRsaKeyPresent = 1; #ifdef HAVE_PK_CALLBACKS #ifndef NO_RSA ssl->buffers.peerRsaKey.buffer = (byte*)XMALLOC(dCert->pubKeySize, ssl->heap, DYNAMIC_TYPE_RSA); if (ssl->buffers.peerRsaKey.buffer == NULL) ret = MEMORY_ERROR; else { XMEMCPY(ssl->buffers.peerRsaKey.buffer, dCert->publicKey, dCert->pubKeySize); ssl->buffers.peerRsaKey.length = dCert->pubKeySize; } #endif /* NO_RSA */ #endif /*HAVE_PK_CALLBACKS */ } } break; #endif /* NO_RSA */ #ifdef HAVE_NTRU case NTRUk: { if (dCert->pubKeySize > sizeof(ssl->peerNtruKey)) { ret = PEER_KEY_ERROR; } else { XMEMCPY(ssl->peerNtruKey, dCert->publicKey, dCert->pubKeySize); ssl->peerNtruKeyLen = (word16)dCert->pubKeySize; ssl->peerNtruKeyPresent = 1; } } break; #endif /* HAVE_NTRU */ #ifdef HAVE_ECC case ECDSAk: { if (ssl->peerEccDsaKey == NULL) { /* alloc/init on demand */ ssl->peerEccDsaKey = (ecc_key*)XMALLOC(sizeof(ecc_key), ssl->ctx->heap, DYNAMIC_TYPE_ECC); if (ssl->peerEccDsaKey == NULL) { WOLFSSL_MSG("PeerEccDsaKey Memory error"); return MEMORY_E; } wc_ecc_init(ssl->peerEccDsaKey); } else if (ssl->peerEccDsaKeyPresent) { /* don't leak on reuse */ wc_ecc_free(ssl->peerEccDsaKey); ssl->peerEccDsaKeyPresent = 0; wc_ecc_init(ssl->peerEccDsaKey); } if (wc_ecc_import_x963(dCert->publicKey, dCert->pubKeySize, ssl->peerEccDsaKey) != 0) { ret = PEER_KEY_ERROR; } else { ssl->peerEccDsaKeyPresent = 1; #ifdef HAVE_PK_CALLBACKS #ifdef HAVE_ECC ssl->buffers.peerEccDsaKey.buffer = (byte*)XMALLOC(dCert->pubKeySize, ssl->heap, DYNAMIC_TYPE_ECC); if (ssl->buffers.peerEccDsaKey.buffer == NULL) ret = MEMORY_ERROR; else { XMEMCPY(ssl->buffers.peerEccDsaKey.buffer, dCert->publicKey, dCert->pubKeySize); ssl->buffers.peerEccDsaKey.length = dCert->pubKeySize; } #endif /* HAVE_ECC */ #endif /*HAVE_PK_CALLBACKS */ } } break; #endif /* HAVE_ECC */ default: break; } FreeDecodedCert(dCert); } #ifdef WOLFSSL_SMALL_STACK XFREE(dCert, NULL, DYNAMIC_TYPE_TMP_BUFFER); store = (WOLFSSL_X509_STORE_CTX*)XMALLOC(sizeof(WOLFSSL_X509_STORE_CTX), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (store == NULL) { XFREE(domain, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } #endif if (anyError != 0 && ret == 0) ret = anyError; if (ret != 0) { if (!ssl->options.verifyNone) { int why = bad_certificate; if (ret == ASN_AFTER_DATE_E || ret == ASN_BEFORE_DATE_E) why = certificate_expired; if (ssl->verifyCallback) { int ok; store->error = ret; store->error_depth = totalCerts; store->discardSessionCerts = 0; store->domain = domain; store->userCtx = ssl->verifyCbCtx; #ifdef KEEP_PEER_CERT store->current_cert = &ssl->peerCert; #else store->current_cert = NULL; #endif #ifdef FORTRESS store->ex_data = ssl; #endif ok = ssl->verifyCallback(0, store); if (ok) { WOLFSSL_MSG("Verify callback overriding error!"); ret = 0; } #ifdef SESSION_CERTS if (store->discardSessionCerts) { WOLFSSL_MSG("Verify callback requested discard sess certs"); ssl->session.chain.count = 0; } #endif } if (ret != 0) { SendAlert(ssl, alert_fatal, why); /* try to send */ ssl->options.isClosed = 1; } } ssl->error = ret; } #ifdef WOLFSSL_ALWAYS_VERIFY_CB else { if (ssl->verifyCallback) { int ok; store->error = ret; store->error_depth = totalCerts; store->discardSessionCerts = 0; store->domain = domain; store->userCtx = ssl->verifyCbCtx; #ifdef KEEP_PEER_CERT store->current_cert = &ssl->peerCert; #endif store->ex_data = ssl; ok = ssl->verifyCallback(1, store); if (!ok) { WOLFSSL_MSG("Verify callback overriding valid certificate!"); ret = -1; SendAlert(ssl, alert_fatal, bad_certificate); ssl->options.isClosed = 1; } #ifdef SESSION_CERTS if (store->discardSessionCerts) { WOLFSSL_MSG("Verify callback requested discard sess certs"); ssl->session.chain.count = 0; } #endif } } #endif if (ssl->options.verifyNone && (ret == CRL_MISSING || ret == CRL_CERT_REVOKED)) { WOLFSSL_MSG("Ignoring CRL problem based on verify setting"); ret = ssl->error = 0; } if (ret == 0 && ssl->options.side == WOLFSSL_CLIENT_END) ssl->options.serverState = SERVER_CERT_COMPLETE; if (ssl->keys.encryptionOn) { *inOutIdx += ssl->keys.padSz; } #ifdef WOLFSSL_SMALL_STACK XFREE(store, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(domain, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } #endif /* !NO_CERTS */ static int DoHelloRequest(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 size, word32 totalSz) { (void)input; if (size) /* must be 0 */ return BUFFER_ERROR; if (ssl->keys.encryptionOn) { /* access beyond input + size should be checked against totalSz */ if (*inOutIdx + ssl->keys.padSz > totalSz) return BUFFER_E; *inOutIdx += ssl->keys.padSz; } if (ssl->options.side == WOLFSSL_SERVER_END) { SendAlert(ssl, alert_fatal, unexpected_message); /* try */ return FATAL_ERROR; } #ifdef HAVE_SECURE_RENEGOTIATION else if (ssl->secure_renegotiation && ssl->secure_renegotiation->enabled) { ssl->secure_renegotiation->startScr = 1; return 0; } #endif else { return SendAlert(ssl, alert_warning, no_renegotiation); } } int DoFinished(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 size, word32 totalSz, int sniff) { word32 finishedSz = (ssl->options.tls ? TLS_FINISHED_SZ : FINISHED_SZ); if (finishedSz != size) return BUFFER_ERROR; /* check against totalSz */ if (*inOutIdx + size + ssl->keys.padSz > totalSz) return BUFFER_E; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Finished", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("Finished", &ssl->timeoutInfo); #endif if (sniff == NO_SNIFF) { if (XMEMCMP(input + *inOutIdx, &ssl->hsHashes->verifyHashes,size) != 0){ WOLFSSL_MSG("Verify finished error on hashes"); return VERIFY_FINISHED_ERROR; } } #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation) { /* save peer's state */ if (ssl->options.side == WOLFSSL_CLIENT_END) XMEMCPY(ssl->secure_renegotiation->server_verify_data, input + *inOutIdx, TLS_FINISHED_SZ); else XMEMCPY(ssl->secure_renegotiation->client_verify_data, input + *inOutIdx, TLS_FINISHED_SZ); } #endif /* force input exhaustion at ProcessReply consuming padSz */ *inOutIdx += size + ssl->keys.padSz; if (ssl->options.side == WOLFSSL_CLIENT_END) { ssl->options.serverState = SERVER_FINISHED_COMPLETE; if (!ssl->options.resuming) { ssl->options.handShakeState = HANDSHAKE_DONE; ssl->options.handShakeDone = 1; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { /* Other side has received our Finished, go to next epoch */ ssl->keys.dtls_epoch++; ssl->keys.dtls_sequence_number = 1; } #endif } } else { ssl->options.clientState = CLIENT_FINISHED_COMPLETE; if (ssl->options.resuming) { ssl->options.handShakeState = HANDSHAKE_DONE; ssl->options.handShakeDone = 1; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { /* Other side has received our Finished, go to next epoch */ ssl->keys.dtls_epoch++; ssl->keys.dtls_sequence_number = 1; } #endif } } return 0; } /* Make sure no duplicates, no fast forward, or other problems; 0 on success */ static int SanityCheckMsgReceived(WOLFSSL* ssl, byte type) { /* verify not a duplicate, mark received, check state */ switch (type) { #ifndef NO_WOLFSSL_CLIENT case hello_request: if (ssl->msgsReceived.got_hello_request) { WOLFSSL_MSG("Duplicate HelloRequest received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_hello_request = 1; break; #endif #ifndef NO_WOLFSSL_SERVER case client_hello: if (ssl->msgsReceived.got_client_hello) { WOLFSSL_MSG("Duplicate ClientHello received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_client_hello = 1; break; #endif #ifndef NO_WOLFSSL_CLIENT case server_hello: if (ssl->msgsReceived.got_server_hello) { WOLFSSL_MSG("Duplicate ServerHello received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_server_hello = 1; break; #endif #ifndef NO_WOLFSSL_CLIENT case hello_verify_request: if (ssl->msgsReceived.got_hello_verify_request) { WOLFSSL_MSG("Duplicate HelloVerifyRequest received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_hello_verify_request = 1; break; #endif #ifndef NO_WOLFSSL_CLIENT case session_ticket: if (ssl->msgsReceived.got_session_ticket) { WOLFSSL_MSG("Duplicate SessionTicket received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_session_ticket = 1; break; #endif case certificate: if (ssl->msgsReceived.got_certificate) { WOLFSSL_MSG("Duplicate Certificate received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_certificate = 1; #ifndef NO_WOLFSSL_CLIENT if (ssl->options.side == WOLFSSL_CLIENT_END) { if ( ssl->msgsReceived.got_server_hello == 0) { WOLFSSL_MSG("No ServerHello before Cert"); return OUT_OF_ORDER_E; } } #endif #ifndef NO_WOLFSSL_SERVER if (ssl->options.side == WOLFSSL_SERVER_END) { if ( ssl->msgsReceived.got_client_hello == 0) { WOLFSSL_MSG("No ClientHello before Cert"); return OUT_OF_ORDER_E; } } #endif break; #ifndef NO_WOLFSSL_CLIENT case server_key_exchange: if (ssl->msgsReceived.got_server_key_exchange) { WOLFSSL_MSG("Duplicate ServerKeyExchange received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_server_key_exchange = 1; if ( ssl->msgsReceived.got_server_hello == 0) { WOLFSSL_MSG("No ServerHello before Cert"); return OUT_OF_ORDER_E; } break; #endif #ifndef NO_WOLFSSL_CLIENT case certificate_request: if (ssl->msgsReceived.got_certificate_request) { WOLFSSL_MSG("Duplicate CertificateRequest received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_certificate_request = 1; break; #endif #ifndef NO_WOLFSSL_CLIENT case server_hello_done: if (ssl->msgsReceived.got_server_hello_done) { WOLFSSL_MSG("Duplicate ServerHelloDone received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_server_hello_done = 1; if (ssl->msgsReceived.got_certificate == 0) { if (ssl->specs.kea == psk_kea || ssl->specs.kea == dhe_psk_kea || ssl->options.usingAnon_cipher) { WOLFSSL_MSG("No Cert required"); } else { WOLFSSL_MSG("No Certificate before ServerHelloDone"); return OUT_OF_ORDER_E; } } if (ssl->msgsReceived.got_server_key_exchange == 0) { if (ssl->specs.static_ecdh == 1 || ssl->specs.kea == rsa_kea || ssl->specs.kea == ntru_kea) { WOLFSSL_MSG("No KeyExchange required"); } else { WOLFSSL_MSG("No ServerKeyExchange before ServerDone"); return OUT_OF_ORDER_E; } } break; #endif #ifndef NO_WOLFSSL_SERVER case certificate_verify: if (ssl->msgsReceived.got_certificate_verify) { WOLFSSL_MSG("Duplicate CertificateVerify received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_certificate_verify = 1; if ( ssl->msgsReceived.got_certificate == 0) { WOLFSSL_MSG("No Cert before CertVerify"); return OUT_OF_ORDER_E; } break; #endif #ifndef NO_WOLFSSL_SERVER case client_key_exchange: if (ssl->msgsReceived.got_client_key_exchange) { WOLFSSL_MSG("Duplicate ClientKeyExchange received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_client_key_exchange = 1; if (ssl->msgsReceived.got_client_hello == 0) { WOLFSSL_MSG("No ClientHello before ClientKeyExchange"); return OUT_OF_ORDER_E; } break; #endif case finished: if (ssl->msgsReceived.got_finished) { WOLFSSL_MSG("Duplicate Finished received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_finished = 1; if (ssl->msgsReceived.got_change_cipher == 0) { WOLFSSL_MSG("Finished received before ChangeCipher"); return NO_CHANGE_CIPHER_E; } break; case change_cipher_hs: if (ssl->msgsReceived.got_change_cipher) { WOLFSSL_MSG("Duplicate ChangeCipher received"); return DUPLICATE_MSG_E; } ssl->msgsReceived.got_change_cipher = 1; #ifndef NO_WOLFSSL_CLIENT if (ssl->options.side == WOLFSSL_CLIENT_END) { if (!ssl->options.resuming && ssl->msgsReceived.got_server_hello_done == 0) { WOLFSSL_MSG("No ServerHelloDone before ChangeCipher"); return OUT_OF_ORDER_E; } } #endif #ifndef NO_WOLFSSL_SERVER if (ssl->options.side == WOLFSSL_SERVER_END) { if (!ssl->options.resuming && ssl->msgsReceived.got_client_key_exchange == 0) { WOLFSSL_MSG("No ClientKeyExchange before ChangeCipher"); return OUT_OF_ORDER_E; } } #endif break; default: WOLFSSL_MSG("Unknown message type"); return SANITY_MSG_E; } return 0; } static int DoHandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx, byte type, word32 size, word32 totalSz) { int ret = 0; (void)totalSz; WOLFSSL_ENTER("DoHandShakeMsgType"); /* make sure can read the message */ if (*inOutIdx + size > totalSz) return INCOMPLETE_DATA; /* sanity check msg received */ if ( (ret = SanityCheckMsgReceived(ssl, type)) != 0) { WOLFSSL_MSG("Sanity Check on handshake message type received failed"); return ret; } #ifdef WOLFSSL_CALLBACKS /* add name later, add on record and handshake header part back on */ if (ssl->toInfoOn) { int add = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; AddPacketInfo(0, &ssl->timeoutInfo, input + *inOutIdx - add, size + add, ssl->heap); AddLateRecordHeader(&ssl->curRL, &ssl->timeoutInfo); } #endif if (ssl->options.handShakeState == HANDSHAKE_DONE && type != hello_request){ WOLFSSL_MSG("HandShake message after handshake complete"); SendAlert(ssl, alert_fatal, unexpected_message); return OUT_OF_ORDER_E; } if (ssl->options.side == WOLFSSL_CLIENT_END && ssl->options.dtls == 0 && ssl->options.serverState == NULL_STATE && type != server_hello) { WOLFSSL_MSG("First server message not server hello"); SendAlert(ssl, alert_fatal, unexpected_message); return OUT_OF_ORDER_E; } if (ssl->options.side == WOLFSSL_CLIENT_END && ssl->options.dtls && type == server_hello_done && ssl->options.serverState < SERVER_HELLO_COMPLETE) { WOLFSSL_MSG("Server hello done received before server hello in DTLS"); SendAlert(ssl, alert_fatal, unexpected_message); return OUT_OF_ORDER_E; } if (ssl->options.side == WOLFSSL_SERVER_END && ssl->options.clientState == NULL_STATE && type != client_hello) { WOLFSSL_MSG("First client message not client hello"); SendAlert(ssl, alert_fatal, unexpected_message); return OUT_OF_ORDER_E; } /* above checks handshake state */ /* hello_request not hashed */ if (type != hello_request) { ret = HashInput(ssl, input + *inOutIdx, size); if (ret != 0) return ret; } switch (type) { case hello_request: WOLFSSL_MSG("processing hello request"); ret = DoHelloRequest(ssl, input, inOutIdx, size, totalSz); break; #ifndef NO_WOLFSSL_CLIENT case hello_verify_request: WOLFSSL_MSG("processing hello verify request"); ret = DoHelloVerifyRequest(ssl, input,inOutIdx, size); break; case server_hello: WOLFSSL_MSG("processing server hello"); ret = DoServerHello(ssl, input, inOutIdx, size); break; #ifndef NO_CERTS case certificate_request: WOLFSSL_MSG("processing certificate request"); ret = DoCertificateRequest(ssl, input, inOutIdx, size); break; #endif case server_key_exchange: WOLFSSL_MSG("processing server key exchange"); ret = DoServerKeyExchange(ssl, input, inOutIdx, size); break; #ifdef HAVE_SESSION_TICKET case session_ticket: WOLFSSL_MSG("processing session ticket"); ret = DoSessionTicket(ssl, input, inOutIdx, size); break; #endif /* HAVE_SESSION_TICKET */ #endif #ifndef NO_CERTS case certificate: WOLFSSL_MSG("processing certificate"); ret = DoCertificate(ssl, input, inOutIdx, size); break; #endif case server_hello_done: WOLFSSL_MSG("processing server hello done"); #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerHelloDone", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("ServerHelloDone", &ssl->timeoutInfo); #endif ssl->options.serverState = SERVER_HELLODONE_COMPLETE; if (ssl->keys.encryptionOn) { *inOutIdx += ssl->keys.padSz; } if (ssl->options.resuming) { WOLFSSL_MSG("Not resuming as thought"); ssl->options.resuming = 0; } break; case finished: WOLFSSL_MSG("processing finished"); ret = DoFinished(ssl, input, inOutIdx, size, totalSz, NO_SNIFF); break; #ifndef NO_WOLFSSL_SERVER case client_hello: WOLFSSL_MSG("processing client hello"); ret = DoClientHello(ssl, input, inOutIdx, size); break; case client_key_exchange: WOLFSSL_MSG("processing client key exchange"); ret = DoClientKeyExchange(ssl, input, inOutIdx, size); break; #if !defined(NO_RSA) || defined(HAVE_ECC) case certificate_verify: WOLFSSL_MSG("processing certificate verify"); ret = DoCertificateVerify(ssl, input, inOutIdx, size); break; #endif /* !NO_RSA || HAVE_ECC */ #endif /* !NO_WOLFSSL_SERVER */ default: WOLFSSL_MSG("Unknown handshake message type"); ret = UNKNOWN_HANDSHAKE_TYPE; break; } WOLFSSL_LEAVE("DoHandShakeMsgType()", ret); return ret; } static int DoHandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 totalSz) { byte type; word32 size; int ret = 0; WOLFSSL_ENTER("DoHandShakeMsg()"); if (GetHandShakeHeader(ssl, input, inOutIdx, &type, &size, totalSz) != 0) return PARSE_ERROR; ret = DoHandShakeMsgType(ssl, input, inOutIdx, type, size, totalSz); WOLFSSL_LEAVE("DoHandShakeMsg()", ret); return ret; } #ifdef WOLFSSL_DTLS static INLINE int DtlsCheckWindow(DtlsState* state) { word32 cur; word32 next; DtlsSeq window; if (state->curEpoch == state->nextEpoch) { next = state->nextSeq; window = state->window; } else if (state->curEpoch < state->nextEpoch) { next = state->prevSeq; window = state->prevWindow; } else { return 0; } cur = state->curSeq; if ((next > DTLS_SEQ_BITS) && (cur < next - DTLS_SEQ_BITS)) { return 0; } else if ((cur < next) && (window & ((DtlsSeq)1 << (next - cur - 1)))) { return 0; } return 1; } static INLINE int DtlsUpdateWindow(DtlsState* state) { word32 cur; word32* next; DtlsSeq* window; if (state->curEpoch == state->nextEpoch) { next = &state->nextSeq; window = &state->window; } else { next = &state->prevSeq; window = &state->prevWindow; } cur = state->curSeq; if (cur < *next) { *window |= ((DtlsSeq)1 << (*next - cur - 1)); } else { *window <<= (1 + cur - *next); *window |= 1; *next = cur + 1; } return 1; } static int DtlsMsgDrain(WOLFSSL* ssl) { DtlsMsg* item = ssl->dtls_msg_list; int ret = 0; /* While there is an item in the store list, and it is the expected * message, and it is complete, and there hasn't been an error in the * last messge... */ while (item != NULL && ssl->keys.dtls_expected_peer_handshake_number == item->seq && item->fragSz == item->sz && ret == 0) { word32 idx = 0; ssl->keys.dtls_expected_peer_handshake_number++; ret = DoHandShakeMsgType(ssl, item->msg, &idx, item->type, item->sz, item->sz); ssl->dtls_msg_list = item->next; DtlsMsgDelete(item, ssl->heap); item = ssl->dtls_msg_list; } return ret; } static int DoDtlsHandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 totalSz) { byte type; word32 size; word32 fragOffset, fragSz; int ret = 0; WOLFSSL_ENTER("DoDtlsHandShakeMsg()"); if (GetDtlsHandShakeHeader(ssl, input, inOutIdx, &type, &size, &fragOffset, &fragSz, totalSz) != 0) return PARSE_ERROR; if (*inOutIdx + fragSz > totalSz) return INCOMPLETE_DATA; /* Check the handshake sequence number first. If out of order, * add the current message to the list. If the message is in order, * but it is a fragment, add the current message to the list, then * check the head of the list to see if it is complete, if so, pop * it out as the current message. If the message is complete and in * order, process it. Check the head of the list to see if it is in * order, if so, process it. (Repeat until list exhausted.) If the * head is out of order, return for more processing. */ if (ssl->keys.dtls_peer_handshake_number > ssl->keys.dtls_expected_peer_handshake_number) { /* Current message is out of order. It will get stored in the list. * Storing also takes care of defragmentation. */ ssl->dtls_msg_list = DtlsMsgStore(ssl->dtls_msg_list, ssl->keys.dtls_peer_handshake_number, input + *inOutIdx, size, type, fragOffset, fragSz, ssl->heap); *inOutIdx += fragSz; ret = 0; } else if (ssl->keys.dtls_peer_handshake_number < ssl->keys.dtls_expected_peer_handshake_number) { /* Already saw this message and processed it. It can be ignored. */ *inOutIdx += fragSz; ret = 0; } else if (fragSz < size) { /* Since this branch is in order, but fragmented, dtls_msg_list will be * pointing to the message with this fragment in it. Check it to see * if it is completed. */ ssl->dtls_msg_list = DtlsMsgStore(ssl->dtls_msg_list, ssl->keys.dtls_peer_handshake_number, input + *inOutIdx, size, type, fragOffset, fragSz, ssl->heap); *inOutIdx += fragSz; ret = 0; if (ssl->dtls_msg_list != NULL && ssl->dtls_msg_list->fragSz >= ssl->dtls_msg_list->sz) ret = DtlsMsgDrain(ssl); } else { /* This branch is in order next, and a complete message. */ ssl->keys.dtls_expected_peer_handshake_number++; ret = DoHandShakeMsgType(ssl, input, inOutIdx, type, size, totalSz); if (ret == 0 && ssl->dtls_msg_list != NULL) ret = DtlsMsgDrain(ssl); } WOLFSSL_LEAVE("DoDtlsHandShakeMsg()", ret); return ret; } #endif #if !defined(NO_OLD_TLS) || defined(HAVE_CHACHA) || defined(HAVE_AESCCM) \ || defined(HAVE_AESGCM) static INLINE word32 GetSEQIncrement(WOLFSSL* ssl, int verify) { #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if (verify) return ssl->keys.dtls_state.curSeq; /* explicit from peer */ else return ssl->keys.dtls_sequence_number - 1; /* already incremented */ } #endif if (verify) return ssl->keys.peer_sequence_number++; else return ssl->keys.sequence_number++; } #endif #ifdef HAVE_AEAD static INLINE void AeadIncrementExpIV(WOLFSSL* ssl) { int i; for (i = AEAD_EXP_IV_SZ-1; i >= 0; i--) { if (++ssl->keys.aead_exp_IV[i]) return; } } #if defined(HAVE_POLY1305) && defined(HAVE_CHACHA) /*more recent rfc's concatonate input for poly1305 differently*/ static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out, byte* cipher, word16 sz, byte* tag) { int ret = 0; int paddingSz = 0; int msglen = (sz - ssl->specs.aead_mac_size); word32 keySz = 32; int blockSz = 16; byte padding[16]; if (msglen < 0) return INPUT_CASE_ERROR; XMEMSET(padding, 0, sizeof(padding)); if ((ret = wc_Poly1305SetKey(ssl->auth.poly1305, cipher, keySz)) != 0) return ret; /* additional input to poly1305 */ if ((ret = wc_Poly1305Update(ssl->auth.poly1305, additional, blockSz)) != 0) return ret; /* cipher input */ if ((ret = wc_Poly1305Update(ssl->auth.poly1305, out, msglen)) != 0) return ret; /* handle padding for cipher input to make it 16 bytes long */ if (msglen % 16 != 0) { paddingSz = (16 - (sz - ssl->specs.aead_mac_size) % 16); if (paddingSz < 0) return INPUT_CASE_ERROR; if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, paddingSz)) != 0) return ret; } /* add size of AD and size of cipher to poly input */ XMEMSET(padding, 0, sizeof(padding)); padding[0] = blockSz; /* 32 bit size of cipher to 64 bit endian */ padding[8] = msglen & 0xff; padding[9] = (msglen >> 8) & 0xff; padding[10] = (msglen >>16) & 0xff; padding[11] = (msglen >>24) & 0xff; if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) != 0) return ret; /* generate tag */ if ((ret = wc_Poly1305Final(ssl->auth.poly1305, tag)) != 0) return ret; return ret; } /* Used for the older version of creating AEAD tags with Poly1305 */ static int Poly1305TagOld(WOLFSSL* ssl, byte* additional, const byte* out, byte* cipher, word16 sz, byte* tag) { int ret = 0; int msglen = (sz - ssl->specs.aead_mac_size); word32 keySz = 32; byte padding[8]; /* used to temporarly store lengths */ #ifdef CHACHA_AEAD_TEST printf("Using old version of poly1305 input.\n"); #endif if (msglen < 0) return INPUT_CASE_ERROR; if ((ret = wc_Poly1305SetKey(ssl->auth.poly1305, cipher, keySz)) != 0) return ret; /* add TLS compressed length and additional input to poly1305 */ additional[AEAD_AUTH_DATA_SZ - 2] = (msglen >> 8) & 0xff; additional[AEAD_AUTH_DATA_SZ - 1] = msglen & 0xff; if ((ret = wc_Poly1305Update(ssl->auth.poly1305, additional, AEAD_AUTH_DATA_SZ)) != 0) return ret; /* length of additional input plus padding */ XMEMSET(padding, 0, sizeof(padding)); padding[0] = AEAD_AUTH_DATA_SZ; if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) != 0) return ret; /* add cipher info and then its length */ XMEMSET(padding, 0, sizeof(padding)); if ((ret = wc_Poly1305Update(ssl->auth.poly1305, out, msglen)) != 0) return ret; /* 32 bit size of cipher to 64 bit endian */ padding[0] = msglen & 0xff; padding[1] = (msglen >> 8) & 0xff; padding[2] = (msglen >> 16) & 0xff; padding[3] = (msglen >> 24) & 0xff; if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) != 0) return ret; /* generate tag */ if ((ret = wc_Poly1305Final(ssl->auth.poly1305, tag)) != 0) return ret; return ret; } static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz) { const byte* additionalSrc = input - RECORD_HEADER_SZ; int ret = 0; byte tag[POLY1305_AUTH_SZ]; byte additional[CHACHA20_BLOCK_SIZE]; byte nonce[AEAD_NONCE_SZ]; byte cipher[CHACHA20_256_KEY_SIZE]; /* generated key for poly1305 */ #ifdef CHACHA_AEAD_TEST int i; #endif XMEMSET(tag, 0, sizeof(tag)); XMEMSET(nonce, 0, AEAD_NONCE_SZ); XMEMSET(cipher, 0, sizeof(cipher)); XMEMSET(additional, 0, CHACHA20_BLOCK_SIZE); /* get nonce */ c32toa(ssl->keys.sequence_number, nonce + AEAD_IMP_IV_SZ + AEAD_SEQ_OFFSET); /* opaque SEQ number stored for AD */ c32toa(GetSEQIncrement(ssl, 0), additional + AEAD_SEQ_OFFSET); /* Store the type, version. Unfortunately, they are in * the input buffer ahead of the plaintext. */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { c16toa(ssl->keys.dtls_epoch, additional); additionalSrc -= DTLS_HANDSHAKE_EXTRA; } #endif XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); #ifdef CHACHA_AEAD_TEST printf("Encrypt Additional : "); for (i = 0; i < CHACHA20_BLOCK_SIZE; i++) { printf("%02x", additional[i]); } printf("\n\n"); printf("input before encryption :\n"); for (i = 0; i < sz; i++) { printf("%02x", input[i]); if ((i + 1) % 16 == 0) printf("\n"); } printf("\n"); #endif /* set the nonce for chacha and get poly1305 key */ if ((ret = wc_Chacha_SetIV(ssl->encrypt.chacha, nonce, 0)) != 0) return ret; if ((ret = wc_Chacha_Process(ssl->encrypt.chacha, cipher, cipher, sizeof(cipher))) != 0) return ret; /* encrypt the plain text */ if ((ret = wc_Chacha_Process(ssl->encrypt.chacha, out, input, sz - ssl->specs.aead_mac_size)) != 0) return ret; /* get the tag : future use of hmac could go here*/ if (ssl->options.oldPoly == 1) { if ((ret = Poly1305TagOld(ssl, additional, (const byte* )out, cipher, sz, tag)) != 0) return ret; } else { if ((ret = Poly1305Tag(ssl, additional, (const byte* )out, cipher, sz, tag)) != 0) return ret; } /* append tag to ciphertext */ XMEMCPY(out + sz - ssl->specs.aead_mac_size, tag, sizeof(tag)); AeadIncrementExpIV(ssl); ForceZero(nonce, AEAD_NONCE_SZ); #ifdef CHACHA_AEAD_TEST printf("mac tag :\n"); for (i = 0; i < 16; i++) { printf("%02x", tag[i]); if ((i + 1) % 16 == 0) printf("\n"); } printf("\n\noutput after encrypt :\n"); for (i = 0; i < sz; i++) { printf("%02x", out[i]); if ((i + 1) % 16 == 0) printf("\n"); } printf("\n"); #endif return ret; } static int ChachaAEADDecrypt(WOLFSSL* ssl, byte* plain, const byte* input, word16 sz) { byte additional[CHACHA20_BLOCK_SIZE]; byte nonce[AEAD_NONCE_SZ]; byte tag[POLY1305_AUTH_SZ]; byte cipher[CHACHA20_256_KEY_SIZE]; /* generated key for mac */ int ret = 0; XMEMSET(tag, 0, sizeof(tag)); XMEMSET(cipher, 0, sizeof(cipher)); XMEMSET(nonce, 0, AEAD_NONCE_SZ); XMEMSET(additional, 0, CHACHA20_BLOCK_SIZE); #ifdef CHACHA_AEAD_TEST int i; printf("input before decrypt :\n"); for (i = 0; i < sz; i++) { printf("%02x", input[i]); if ((i + 1) % 16 == 0) printf("\n"); } printf("\n"); #endif /* get nonce */ c32toa(ssl->keys.peer_sequence_number, nonce + AEAD_IMP_IV_SZ + AEAD_SEQ_OFFSET); /* sequence number field is 64-bits, we only use 32-bits */ c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); /* get AD info */ additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor; additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor; /* Store the type, version. */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) c16toa(ssl->keys.dtls_state.curEpoch, additional); #endif #ifdef CHACHA_AEAD_TEST printf("Decrypt Additional : "); for (i = 0; i < CHACHA20_BLOCK_SIZE; i++) { printf("%02x", additional[i]); } printf("\n\n"); #endif /* set nonce and get poly1305 key */ if ((ret = wc_Chacha_SetIV(ssl->decrypt.chacha, nonce, 0)) != 0) return ret; if ((ret = wc_Chacha_Process(ssl->decrypt.chacha, cipher, cipher, sizeof(cipher))) != 0) return ret; /* get the tag : future use of hmac could go here*/ if (ssl->options.oldPoly == 1) { if ((ret = Poly1305TagOld(ssl, additional, input, cipher, sz, tag)) != 0) return ret; } else { if ((ret = Poly1305Tag(ssl, additional, input, cipher, sz, tag)) != 0) return ret; } /* check mac sent along with packet */ if (ConstantCompare(input + sz - ssl->specs.aead_mac_size, tag, ssl->specs.aead_mac_size) != 0) { WOLFSSL_MSG("Mac did not match"); SendAlert(ssl, alert_fatal, bad_record_mac); ForceZero(nonce, AEAD_NONCE_SZ); return VERIFY_MAC_ERROR; } /* if mac was good decrypt message */ if ((ret = wc_Chacha_Process(ssl->decrypt.chacha, plain, input, sz - ssl->specs.aead_mac_size)) != 0) return ret; #ifdef CHACHA_AEAD_TEST printf("plain after decrypt :\n"); for (i = 0; i < sz; i++) { printf("%02x", plain[i]); if ((i + 1) % 16 == 0) printf("\n"); } printf("\n"); #endif return ret; } #endif /* HAVE_CHACHA && HAVE_POLY1305 */ #endif /* HAVE_AEAD */ static INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz) { int ret = 0; (void)out; (void)input; (void)sz; if (ssl->encrypt.setup == 0) { WOLFSSL_MSG("Encrypt ciphers not setup"); return ENCRYPT_ERROR; } #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, input, sz, FUZZ_ENCRYPT, ssl->fuzzerCtx); #endif switch (ssl->specs.bulk_cipher_algorithm) { #ifdef BUILD_ARC4 case wolfssl_rc4: wc_Arc4Process(ssl->encrypt.arc4, out, input, sz); break; #endif #ifdef BUILD_DES3 case wolfssl_triple_des: ret = wc_Des3_CbcEncrypt(ssl->encrypt.des3, out, input, sz); break; #endif #ifdef BUILD_AES case wolfssl_aes: ret = wc_AesCbcEncrypt(ssl->encrypt.aes, out, input, sz); break; #endif #ifdef BUILD_AESGCM case wolfssl_aes_gcm: { byte additional[AEAD_AUTH_DATA_SZ]; byte nonce[AEAD_NONCE_SZ]; const byte* additionalSrc = input - 5; XMEMSET(additional, 0, AEAD_AUTH_DATA_SZ); /* sequence number field is 64-bits, we only use 32-bits */ c32toa(GetSEQIncrement(ssl, 0), additional + AEAD_SEQ_OFFSET); /* Store the type, version. Unfortunately, they are in * the input buffer ahead of the plaintext. */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { c16toa(ssl->keys.dtls_epoch, additional); additionalSrc -= DTLS_HANDSHAKE_EXTRA; } #endif XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); /* Store the length of the plain text minus the explicit * IV length minus the authentication tag size. */ c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, additional + AEAD_LEN_OFFSET); XMEMCPY(nonce, ssl->keys.aead_enc_imp_IV, AEAD_IMP_IV_SZ); XMEMCPY(nonce + AEAD_IMP_IV_SZ, ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ); ret = wc_AesGcmEncrypt(ssl->encrypt.aes, out + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ, sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, nonce, AEAD_NONCE_SZ, out + sz - ssl->specs.aead_mac_size, ssl->specs.aead_mac_size, additional, AEAD_AUTH_DATA_SZ); if (ret == 0) AeadIncrementExpIV(ssl); ForceZero(nonce, AEAD_NONCE_SZ); } break; #endif #ifdef HAVE_AESCCM case wolfssl_aes_ccm: { byte additional[AEAD_AUTH_DATA_SZ]; byte nonce[AEAD_NONCE_SZ]; const byte* additionalSrc = input - 5; XMEMSET(additional, 0, AEAD_AUTH_DATA_SZ); /* sequence number field is 64-bits, we only use 32-bits */ c32toa(GetSEQIncrement(ssl, 0), additional + AEAD_SEQ_OFFSET); /* Store the type, version. Unfortunately, they are in * the input buffer ahead of the plaintext. */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { c16toa(ssl->keys.dtls_epoch, additional); additionalSrc -= DTLS_HANDSHAKE_EXTRA; } #endif XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); /* Store the length of the plain text minus the explicit * IV length minus the authentication tag size. */ c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, additional + AEAD_LEN_OFFSET); XMEMCPY(nonce, ssl->keys.aead_enc_imp_IV, AEAD_IMP_IV_SZ); XMEMCPY(nonce + AEAD_IMP_IV_SZ, ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ); wc_AesCcmEncrypt(ssl->encrypt.aes, out + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ, sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, nonce, AEAD_NONCE_SZ, out + sz - ssl->specs.aead_mac_size, ssl->specs.aead_mac_size, additional, AEAD_AUTH_DATA_SZ); AeadIncrementExpIV(ssl); ForceZero(nonce, AEAD_NONCE_SZ); } break; #endif #ifdef HAVE_CAMELLIA case wolfssl_camellia: wc_CamelliaCbcEncrypt(ssl->encrypt.cam, out, input, sz); break; #endif #ifdef HAVE_HC128 case wolfssl_hc128: ret = wc_Hc128_Process(ssl->encrypt.hc128, out, input, sz); break; #endif #ifdef BUILD_RABBIT case wolfssl_rabbit: ret = wc_RabbitProcess(ssl->encrypt.rabbit, out, input, sz); break; #endif #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) case wolfssl_chacha: ret = ChachaAEADEncrypt(ssl, out, input, sz); break; #endif #ifdef HAVE_NULL_CIPHER case wolfssl_cipher_null: if (input != out) { XMEMMOVE(out, input, sz); } break; #endif default: WOLFSSL_MSG("wolfSSL Encrypt programming error"); ret = ENCRYPT_ERROR; } return ret; } static INLINE int Decrypt(WOLFSSL* ssl, byte* plain, const byte* input, word16 sz) { int ret = 0; (void)plain; (void)input; (void)sz; if (ssl->decrypt.setup == 0) { WOLFSSL_MSG("Decrypt ciphers not setup"); return DECRYPT_ERROR; } switch (ssl->specs.bulk_cipher_algorithm) { #ifdef BUILD_ARC4 case wolfssl_rc4: wc_Arc4Process(ssl->decrypt.arc4, plain, input, sz); break; #endif #ifdef BUILD_DES3 case wolfssl_triple_des: ret = wc_Des3_CbcDecrypt(ssl->decrypt.des3, plain, input, sz); break; #endif #ifdef BUILD_AES case wolfssl_aes: ret = wc_AesCbcDecrypt(ssl->decrypt.aes, plain, input, sz); break; #endif #ifdef BUILD_AESGCM case wolfssl_aes_gcm: { byte additional[AEAD_AUTH_DATA_SZ]; byte nonce[AEAD_NONCE_SZ]; XMEMSET(additional, 0, AEAD_AUTH_DATA_SZ); /* sequence number field is 64-bits, we only use 32-bits */ c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); #ifdef WOLFSSL_DTLS if (ssl->options.dtls) c16toa(ssl->keys.dtls_state.curEpoch, additional); #endif additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor; additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor; c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, additional + AEAD_LEN_OFFSET); XMEMCPY(nonce, ssl->keys.aead_dec_imp_IV, AEAD_IMP_IV_SZ); XMEMCPY(nonce + AEAD_IMP_IV_SZ, input, AEAD_EXP_IV_SZ); if (wc_AesGcmDecrypt(ssl->decrypt.aes, plain + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ, sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, nonce, AEAD_NONCE_SZ, input + sz - ssl->specs.aead_mac_size, ssl->specs.aead_mac_size, additional, AEAD_AUTH_DATA_SZ) < 0) { SendAlert(ssl, alert_fatal, bad_record_mac); ret = VERIFY_MAC_ERROR; } ForceZero(nonce, AEAD_NONCE_SZ); } break; #endif #ifdef HAVE_AESCCM case wolfssl_aes_ccm: { byte additional[AEAD_AUTH_DATA_SZ]; byte nonce[AEAD_NONCE_SZ]; XMEMSET(additional, 0, AEAD_AUTH_DATA_SZ); /* sequence number field is 64-bits, we only use 32-bits */ c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); #ifdef WOLFSSL_DTLS if (ssl->options.dtls) c16toa(ssl->keys.dtls_state.curEpoch, additional); #endif additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor; additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor; c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, additional + AEAD_LEN_OFFSET); XMEMCPY(nonce, ssl->keys.aead_dec_imp_IV, AEAD_IMP_IV_SZ); XMEMCPY(nonce + AEAD_IMP_IV_SZ, input, AEAD_EXP_IV_SZ); if (wc_AesCcmDecrypt(ssl->decrypt.aes, plain + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ, sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, nonce, AEAD_NONCE_SZ, input + sz - ssl->specs.aead_mac_size, ssl->specs.aead_mac_size, additional, AEAD_AUTH_DATA_SZ) < 0) { SendAlert(ssl, alert_fatal, bad_record_mac); ret = VERIFY_MAC_ERROR; } ForceZero(nonce, AEAD_NONCE_SZ); } break; #endif #ifdef HAVE_CAMELLIA case wolfssl_camellia: wc_CamelliaCbcDecrypt(ssl->decrypt.cam, plain, input, sz); break; #endif #ifdef HAVE_HC128 case wolfssl_hc128: ret = wc_Hc128_Process(ssl->decrypt.hc128, plain, input, sz); break; #endif #ifdef BUILD_RABBIT case wolfssl_rabbit: ret = wc_RabbitProcess(ssl->decrypt.rabbit, plain, input, sz); break; #endif #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) case wolfssl_chacha: ret = ChachaAEADDecrypt(ssl, plain, input, sz); break; #endif #ifdef HAVE_NULL_CIPHER case wolfssl_cipher_null: if (input != plain) { XMEMMOVE(plain, input, sz); } break; #endif default: WOLFSSL_MSG("wolfSSL Decrypt programming error"); ret = DECRYPT_ERROR; } return ret; } /* check cipher text size for sanity */ static int SanityCheckCipherText(WOLFSSL* ssl, word32 encryptSz) { #ifdef HAVE_TRUNCATED_HMAC word32 minLength = ssl->truncated_hmac ? TRUNCATED_HMAC_SZ : ssl->specs.hash_size; #else word32 minLength = ssl->specs.hash_size; /* covers stream */ #endif if (ssl->specs.cipher_type == block) { if (encryptSz % ssl->specs.block_size) { WOLFSSL_MSG("Block ciphertext not block size"); return SANITY_CIPHER_E; } minLength++; /* pad byte */ if (ssl->specs.block_size > minLength) minLength = ssl->specs.block_size; if (ssl->options.tls1_1) minLength += ssl->specs.block_size; /* explicit IV */ } else if (ssl->specs.cipher_type == aead) { minLength = ssl->specs.aead_mac_size; /* authTag size */ if (ssl->specs.bulk_cipher_algorithm != wolfssl_chacha) minLength += AEAD_EXP_IV_SZ; /* explicit IV */ } if (encryptSz < minLength) { WOLFSSL_MSG("Ciphertext not minimum size"); return SANITY_CIPHER_E; } return 0; } #ifndef NO_OLD_TLS static INLINE void Md5Rounds(int rounds, const byte* data, int sz) { Md5 md5; int i; wc_InitMd5(&md5); for (i = 0; i < rounds; i++) wc_Md5Update(&md5, data, sz); } /* do a dummy sha round */ static INLINE void ShaRounds(int rounds, const byte* data, int sz) { Sha sha; int i; wc_InitSha(&sha); /* no error check on purpose, dummy round */ for (i = 0; i < rounds; i++) wc_ShaUpdate(&sha, data, sz); } #endif #ifndef NO_SHA256 static INLINE void Sha256Rounds(int rounds, const byte* data, int sz) { Sha256 sha256; int i; wc_InitSha256(&sha256); /* no error check on purpose, dummy round */ for (i = 0; i < rounds; i++) { wc_Sha256Update(&sha256, data, sz); /* no error check on purpose, dummy round */ } } #endif #ifdef WOLFSSL_SHA384 static INLINE void Sha384Rounds(int rounds, const byte* data, int sz) { Sha384 sha384; int i; wc_InitSha384(&sha384); /* no error check on purpose, dummy round */ for (i = 0; i < rounds; i++) { wc_Sha384Update(&sha384, data, sz); /* no error check on purpose, dummy round */ } } #endif #ifdef WOLFSSL_SHA512 static INLINE void Sha512Rounds(int rounds, const byte* data, int sz) { Sha512 sha512; int i; wc_InitSha512(&sha512); /* no error check on purpose, dummy round */ for (i = 0; i < rounds; i++) { wc_Sha512Update(&sha512, data, sz); /* no error check on purpose, dummy round */ } } #endif #ifdef WOLFSSL_RIPEMD static INLINE void RmdRounds(int rounds, const byte* data, int sz) { RipeMd ripemd; int i; wc_InitRipeMd(&ripemd); for (i = 0; i < rounds; i++) wc_RipeMdUpdate(&ripemd, data, sz); } #endif /* Do dummy rounds */ static INLINE void DoRounds(int type, int rounds, const byte* data, int sz) { switch (type) { case no_mac : break; #ifndef NO_OLD_TLS #ifndef NO_MD5 case md5_mac : Md5Rounds(rounds, data, sz); break; #endif #ifndef NO_SHA case sha_mac : ShaRounds(rounds, data, sz); break; #endif #endif #ifndef NO_SHA256 case sha256_mac : Sha256Rounds(rounds, data, sz); break; #endif #ifdef WOLFSSL_SHA384 case sha384_mac : Sha384Rounds(rounds, data, sz); break; #endif #ifdef WOLFSSL_SHA512 case sha512_mac : Sha512Rounds(rounds, data, sz); break; #endif #ifdef WOLFSSL_RIPEMD case rmd_mac : RmdRounds(rounds, data, sz); break; #endif default: WOLFSSL_MSG("Bad round type"); break; } } /* do number of compression rounds on dummy data */ static INLINE void CompressRounds(WOLFSSL* ssl, int rounds, const byte* dummy) { if (rounds) DoRounds(ssl->specs.mac_algorithm, rounds, dummy, COMPRESS_LOWER); } /* check all length bytes for the pad value, return 0 on success */ static int PadCheck(const byte* a, byte pad, int length) { int i; int compareSum = 0; for (i = 0; i < length; i++) { compareSum |= a[i] ^ pad; } return compareSum; } /* get compression extra rounds */ static INLINE int GetRounds(int pLen, int padLen, int t) { int roundL1 = 1; /* round up flags */ int roundL2 = 1; int L1 = COMPRESS_CONSTANT + pLen - t; int L2 = COMPRESS_CONSTANT + pLen - padLen - 1 - t; L1 -= COMPRESS_UPPER; L2 -= COMPRESS_UPPER; if ( (L1 % COMPRESS_LOWER) == 0) roundL1 = 0; if ( (L2 % COMPRESS_LOWER) == 0) roundL2 = 0; L1 /= COMPRESS_LOWER; L2 /= COMPRESS_LOWER; L1 += roundL1; L2 += roundL2; return L1 - L2; } /* timing resistant pad/verify check, return 0 on success */ static int TimingPadVerify(WOLFSSL* ssl, const byte* input, int padLen, int t, int pLen, int content) { byte verify[MAX_DIGEST_SIZE]; byte dmy[sizeof(WOLFSSL) >= MAX_PAD_SIZE ? 1 : MAX_PAD_SIZE] = {0}; byte* dummy = sizeof(dmy) < MAX_PAD_SIZE ? (byte*) ssl : dmy; int ret = 0; (void)dmy; if ( (t + padLen + 1) > pLen) { WOLFSSL_MSG("Plain Len not long enough for pad/mac"); PadCheck(dummy, (byte)padLen, MAX_PAD_SIZE); ssl->hmac(ssl, verify, input, pLen - t, content, 1); /* still compare */ ConstantCompare(verify, input + pLen - t, t); return VERIFY_MAC_ERROR; } if (PadCheck(input + pLen - (padLen + 1), (byte)padLen, padLen + 1) != 0) { WOLFSSL_MSG("PadCheck failed"); PadCheck(dummy, (byte)padLen, MAX_PAD_SIZE - padLen - 1); ssl->hmac(ssl, verify, input, pLen - t, content, 1); /* still compare */ ConstantCompare(verify, input + pLen - t, t); return VERIFY_MAC_ERROR; } PadCheck(dummy, (byte)padLen, MAX_PAD_SIZE - padLen - 1); ret = ssl->hmac(ssl, verify, input, pLen - padLen - 1 - t, content, 1); CompressRounds(ssl, GetRounds(pLen, padLen, t), dummy); if (ConstantCompare(verify, input + (pLen - padLen - 1 - t), t) != 0) { WOLFSSL_MSG("Verify MAC compare failed"); return VERIFY_MAC_ERROR; } if (ret != 0) return VERIFY_MAC_ERROR; return 0; } int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx) { word32 msgSz = ssl->keys.encryptSz; word32 idx = *inOutIdx; int dataSz; int ivExtra = 0; byte* rawData = input + idx; /* keep current for hmac */ #ifdef HAVE_LIBZ byte decomp[MAX_RECORD_SIZE + MAX_COMP_EXTRA]; #endif if (ssl->options.handShakeDone == 0) { WOLFSSL_MSG("Received App data before a handshake completed"); SendAlert(ssl, alert_fatal, unexpected_message); return OUT_OF_ORDER_E; } if (ssl->specs.cipher_type == block) { if (ssl->options.tls1_1) ivExtra = ssl->specs.block_size; } else if (ssl->specs.cipher_type == aead) { if (ssl->specs.bulk_cipher_algorithm != wolfssl_chacha) ivExtra = AEAD_EXP_IV_SZ; } dataSz = msgSz - ivExtra - ssl->keys.padSz; if (dataSz < 0) { WOLFSSL_MSG("App data buffer error, malicious input?"); return BUFFER_ERROR; } /* read data */ if (dataSz) { int rawSz = dataSz; /* keep raw size for idx adjustment */ #ifdef HAVE_LIBZ if (ssl->options.usingCompression) { dataSz = myDeCompress(ssl, rawData, dataSz, decomp, sizeof(decomp)); if (dataSz < 0) return dataSz; } #endif idx += rawSz; ssl->buffers.clearOutputBuffer.buffer = rawData; ssl->buffers.clearOutputBuffer.length = dataSz; } idx += ssl->keys.padSz; #ifdef HAVE_LIBZ /* decompress could be bigger, overwrite after verify */ if (ssl->options.usingCompression) XMEMMOVE(rawData, decomp, dataSz); #endif *inOutIdx = idx; return 0; } /* process alert, return level */ static int DoAlert(WOLFSSL* ssl, byte* input, word32* inOutIdx, int* type, word32 totalSz) { byte level; byte code; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Alert", &ssl->handShakeInfo); if (ssl->toInfoOn) /* add record header back on to info + 2 byte level, data */ AddPacketInfo("Alert", &ssl->timeoutInfo, input + *inOutIdx - RECORD_HEADER_SZ, 2 + RECORD_HEADER_SZ, ssl->heap); #endif /* make sure can read the message */ if (*inOutIdx + ALERT_SIZE > totalSz) return BUFFER_E; level = input[(*inOutIdx)++]; code = input[(*inOutIdx)++]; ssl->alert_history.last_rx.code = code; ssl->alert_history.last_rx.level = level; *type = code; if (level == alert_fatal) { ssl->options.isClosed = 1; /* Don't send close_notify */ } WOLFSSL_MSG("Got alert"); if (*type == close_notify) { WOLFSSL_MSG(" close notify"); ssl->options.closeNotify = 1; } WOLFSSL_ERROR(*type); if (ssl->keys.encryptionOn) { if (*inOutIdx + ssl->keys.padSz > totalSz) return BUFFER_E; *inOutIdx += ssl->keys.padSz; } return level; } static int GetInputData(WOLFSSL *ssl, word32 size) { int in; int inSz; int maxLength; int usedLength; int dtlsExtra = 0; /* check max input length */ usedLength = ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx; maxLength = ssl->buffers.inputBuffer.bufferSize - usedLength; inSz = (int)(size - usedLength); /* from last partial read */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if (size < ssl->dtls_expected_rx) dtlsExtra = (int)(ssl->dtls_expected_rx - size); inSz = ssl->dtls_expected_rx; } #endif if (inSz > maxLength) { if (GrowInputBuffer(ssl, size + dtlsExtra, usedLength) < 0) return MEMORY_E; } if (inSz <= 0) return BUFFER_ERROR; /* Put buffer data at start if not there */ if (usedLength > 0 && ssl->buffers.inputBuffer.idx != 0) XMEMMOVE(ssl->buffers.inputBuffer.buffer, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, usedLength); /* remove processed data */ ssl->buffers.inputBuffer.idx = 0; ssl->buffers.inputBuffer.length = usedLength; /* read data from network */ do { in = Receive(ssl, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.length, inSz); if (in == -1) return SOCKET_ERROR_E; if (in == WANT_READ) return WANT_READ; if (in > inSz) return RECV_OVERFLOW_E; ssl->buffers.inputBuffer.length += in; inSz -= in; } while (ssl->buffers.inputBuffer.length < size); return 0; } static INLINE int VerifyMac(WOLFSSL* ssl, const byte* input, word32 msgSz, int content, word32* padSz) { int ivExtra = 0; int ret; word32 pad = 0; word32 padByte = 0; #ifdef HAVE_TRUNCATED_HMAC word32 digestSz = ssl->truncated_hmac ? TRUNCATED_HMAC_SZ : ssl->specs.hash_size; #else word32 digestSz = ssl->specs.hash_size; #endif byte verify[MAX_DIGEST_SIZE]; if (ssl->specs.cipher_type == block) { if (ssl->options.tls1_1) ivExtra = ssl->specs.block_size; pad = *(input + msgSz - ivExtra - 1); padByte = 1; if (ssl->options.tls) { ret = TimingPadVerify(ssl, input, pad, digestSz, msgSz - ivExtra, content); if (ret != 0) return ret; } else { /* sslv3, some implementations have bad padding, but don't * allow bad read */ int badPadLen = 0; byte dmy[sizeof(WOLFSSL) >= MAX_PAD_SIZE ? 1 : MAX_PAD_SIZE] = {0}; byte* dummy = sizeof(dmy) < MAX_PAD_SIZE ? (byte*) ssl : dmy; (void)dmy; if (pad > (msgSz - digestSz - 1)) { WOLFSSL_MSG("Plain Len not long enough for pad/mac"); pad = 0; /* no bad read */ badPadLen = 1; } PadCheck(dummy, (byte)pad, MAX_PAD_SIZE); /* timing only */ ret = ssl->hmac(ssl, verify, input, msgSz - digestSz - pad - 1, content, 1); if (ConstantCompare(verify, input + msgSz - digestSz - pad - 1, digestSz) != 0) return VERIFY_MAC_ERROR; if (ret != 0 || badPadLen) return VERIFY_MAC_ERROR; } } else if (ssl->specs.cipher_type == stream) { ret = ssl->hmac(ssl, verify, input, msgSz - digestSz, content, 1); if (ConstantCompare(verify, input + msgSz - digestSz, digestSz) != 0){ return VERIFY_MAC_ERROR; } if (ret != 0) return VERIFY_MAC_ERROR; } if (ssl->specs.cipher_type == aead) { *padSz = ssl->specs.aead_mac_size; } else { *padSz = digestSz + pad + padByte; } return 0; } /* process input requests, return 0 is done, 1 is call again to complete, and negative number is error */ int ProcessReply(WOLFSSL* ssl) { int ret = 0, type, readSz; int atomicUser = 0; word32 startIdx = 0; #ifdef WOLFSSL_DTLS int used; #endif #ifdef ATOMIC_USER if (ssl->ctx->DecryptVerifyCb) atomicUser = 1; #endif if (ssl->error != 0 && ssl->error != WANT_READ && ssl->error != WANT_WRITE){ WOLFSSL_MSG("ProcessReply retry in error state, not allowed"); return ssl->error; } for (;;) { switch (ssl->options.processReply) { /* in the WOLFSSL_SERVER case, get the first byte for detecting * old client hello */ case doProcessInit: readSz = RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) readSz = DTLS_RECORD_HEADER_SZ; #endif /* get header or return error */ if (!ssl->options.dtls) { if ((ret = GetInputData(ssl, readSz)) < 0) return ret; } else { #ifdef WOLFSSL_DTLS /* read ahead may already have header */ used = ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx; if (used < readSz) if ((ret = GetInputData(ssl, readSz)) < 0) return ret; #endif } #ifdef OLD_HELLO_ALLOWED /* see if sending SSLv2 client hello */ if ( ssl->options.side == WOLFSSL_SERVER_END && ssl->options.clientState == NULL_STATE && ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx] != handshake) { byte b0, b1; ssl->options.processReply = runProcessOldClientHello; /* sanity checks before getting size at front */ if (ssl->buffers.inputBuffer.buffer[ ssl->buffers.inputBuffer.idx + 2] != OLD_HELLO_ID) { WOLFSSL_MSG("Not a valid old client hello"); return PARSE_ERROR; } if (ssl->buffers.inputBuffer.buffer[ ssl->buffers.inputBuffer.idx + 3] != SSLv3_MAJOR && ssl->buffers.inputBuffer.buffer[ ssl->buffers.inputBuffer.idx + 3] != DTLS_MAJOR) { WOLFSSL_MSG("Not a valid version in old client hello"); return PARSE_ERROR; } /* how many bytes need ProcessOldClientHello */ b0 = ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx++]; b1 = ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx++]; ssl->curSize = (word16)(((b0 & 0x7f) << 8) | b1); } else { ssl->options.processReply = getRecordLayerHeader; continue; } /* in the WOLFSSL_SERVER case, run the old client hello */ case runProcessOldClientHello: /* get sz bytes or return error */ if (!ssl->options.dtls) { if ((ret = GetInputData(ssl, ssl->curSize)) < 0) return ret; } else { #ifdef WOLFSSL_DTLS /* read ahead may already have */ used = ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx; if (used < ssl->curSize) if ((ret = GetInputData(ssl, ssl->curSize)) < 0) return ret; #endif /* WOLFSSL_DTLS */ } ret = ProcessOldClientHello(ssl, ssl->buffers.inputBuffer.buffer, &ssl->buffers.inputBuffer.idx, ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx, ssl->curSize); if (ret < 0) return ret; else if (ssl->buffers.inputBuffer.idx == ssl->buffers.inputBuffer.length) { ssl->options.processReply = doProcessInit; return 0; } #endif /* OLD_HELLO_ALLOWED */ /* FALLTHRU */ /* get the record layer header */ case getRecordLayerHeader: ret = GetRecordHeader(ssl, ssl->buffers.inputBuffer.buffer, &ssl->buffers.inputBuffer.idx, &ssl->curRL, &ssl->curSize); #ifdef WOLFSSL_DTLS if (ssl->options.dtls && ret == SEQUENCE_ERROR) { ssl->options.processReply = doProcessInit; ssl->buffers.inputBuffer.length = 0; ssl->buffers.inputBuffer.idx = 0; continue; } #endif if (ret != 0) return ret; ssl->options.processReply = getData; /* FALLTHRU */ /* retrieve record layer data */ case getData: /* get sz bytes or return error */ if (!ssl->options.dtls) { if ((ret = GetInputData(ssl, ssl->curSize)) < 0) return ret; } else { #ifdef WOLFSSL_DTLS /* read ahead may already have */ used = ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx; if (used < ssl->curSize) if ((ret = GetInputData(ssl, ssl->curSize)) < 0) return ret; #endif } ssl->options.processReply = runProcessingOneMessage; startIdx = ssl->buffers.inputBuffer.idx; /* in case > 1 msg per */ /* FALLTHRU */ /* the record layer is here */ case runProcessingOneMessage: #ifdef WOLFSSL_DTLS if (ssl->options.dtls && ssl->keys.dtls_state.curEpoch < ssl->keys.dtls_state.nextEpoch) ssl->keys.decryptedCur = 1; #endif if (ssl->keys.encryptionOn && ssl->keys.decryptedCur == 0) { ret = SanityCheckCipherText(ssl, ssl->curSize); if (ret < 0) return ret; if (atomicUser) { #ifdef ATOMIC_USER ret = ssl->ctx->DecryptVerifyCb(ssl, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, ssl->curSize, ssl->curRL.type, 1, &ssl->keys.padSz, ssl->DecryptVerifyCtx); if (ssl->options.tls1_1 && ssl->specs.cipher_type == block) ssl->buffers.inputBuffer.idx += ssl->specs.block_size; /* go past TLSv1.1 IV */ if (ssl->specs.cipher_type == aead && ssl->specs.bulk_cipher_algorithm != wolfssl_chacha) ssl->buffers.inputBuffer.idx += AEAD_EXP_IV_SZ; #endif /* ATOMIC_USER */ } else { ret = Decrypt(ssl, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, ssl->curSize); if (ret < 0) { WOLFSSL_ERROR(ret); return DECRYPT_ERROR; } if (ssl->options.tls1_1 && ssl->specs.cipher_type == block) ssl->buffers.inputBuffer.idx += ssl->specs.block_size; /* go past TLSv1.1 IV */ if (ssl->specs.cipher_type == aead && ssl->specs.bulk_cipher_algorithm != wolfssl_chacha) ssl->buffers.inputBuffer.idx += AEAD_EXP_IV_SZ; ret = VerifyMac(ssl, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, ssl->curSize, ssl->curRL.type, &ssl->keys.padSz); } if (ret < 0) { WOLFSSL_ERROR(ret); return DECRYPT_ERROR; } ssl->keys.encryptSz = ssl->curSize; ssl->keys.decryptedCur = 1; } if (ssl->options.dtls) { #ifdef WOLFSSL_DTLS DtlsUpdateWindow(&ssl->keys.dtls_state); #endif /* WOLFSSL_DTLS */ } WOLFSSL_MSG("received record layer msg"); switch (ssl->curRL.type) { case handshake : /* debugging in DoHandShakeMsg */ if (!ssl->options.dtls) { ret = DoHandShakeMsg(ssl, ssl->buffers.inputBuffer.buffer, &ssl->buffers.inputBuffer.idx, ssl->buffers.inputBuffer.length); } else { #ifdef WOLFSSL_DTLS ret = DoDtlsHandShakeMsg(ssl, ssl->buffers.inputBuffer.buffer, &ssl->buffers.inputBuffer.idx, ssl->buffers.inputBuffer.length); #endif } if (ret != 0) return ret; break; case change_cipher_spec: WOLFSSL_MSG("got CHANGE CIPHER SPEC"); #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ChangeCipher", &ssl->handShakeInfo); /* add record header back on info */ if (ssl->toInfoOn) { AddPacketInfo("ChangeCipher", &ssl->timeoutInfo, ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx - RECORD_HEADER_SZ, 1 + RECORD_HEADER_SZ, ssl->heap); AddLateRecordHeader(&ssl->curRL, &ssl->timeoutInfo); } #endif ret = SanityCheckMsgReceived(ssl, change_cipher_hs); if (ret != 0) return ret; #ifdef HAVE_SESSION_TICKET if (ssl->options.side == WOLFSSL_CLIENT_END && ssl->expect_session_ticket) { WOLFSSL_MSG("Expected session ticket missing"); return SESSION_TICKET_EXPECT_E; } #endif if (ssl->keys.encryptionOn && ssl->options.handShakeDone) { ssl->buffers.inputBuffer.idx += ssl->keys.padSz; ssl->curSize -= (word16) ssl->buffers.inputBuffer.idx; } if (ssl->curSize != 1) { WOLFSSL_MSG("Malicious or corrupted ChangeCipher msg"); return LENGTH_ERROR; } #ifndef NO_CERTS if (ssl->options.side == WOLFSSL_SERVER_END && ssl->options.verifyPeer && ssl->options.havePeerCert) if (!ssl->options.havePeerVerify) { WOLFSSL_MSG("client didn't send cert verify"); return NO_PEER_VERIFY; } #endif ssl->buffers.inputBuffer.idx++; ssl->keys.encryptionOn = 1; /* setup decrypt keys for following messages */ if ((ret = SetKeysSide(ssl, DECRYPT_SIDE_ONLY)) != 0) return ret; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { DtlsPoolReset(ssl); ssl->keys.dtls_state.nextEpoch++; ssl->keys.dtls_state.nextSeq = 0; } #endif #ifdef HAVE_LIBZ if (ssl->options.usingCompression) if ( (ret = InitStreams(ssl)) != 0) return ret; #endif ret = BuildFinished(ssl, &ssl->hsHashes->verifyHashes, ssl->options.side == WOLFSSL_CLIENT_END ? server : client); if (ret != 0) return ret; break; case application_data: WOLFSSL_MSG("got app DATA"); if ((ret = DoApplicationData(ssl, ssl->buffers.inputBuffer.buffer, &ssl->buffers.inputBuffer.idx)) != 0) { WOLFSSL_ERROR(ret); return ret; } break; case alert: WOLFSSL_MSG("got ALERT!"); ret = DoAlert(ssl, ssl->buffers.inputBuffer.buffer, &ssl->buffers.inputBuffer.idx, &type, ssl->buffers.inputBuffer.length); if (ret == alert_fatal) return FATAL_ERROR; else if (ret < 0) return ret; /* catch warnings that are handled as errors */ if (type == close_notify) return ssl->error = ZERO_RETURN; if (type == decrypt_error) return FATAL_ERROR; break; default: WOLFSSL_ERROR(UNKNOWN_RECORD_TYPE); return UNKNOWN_RECORD_TYPE; } ssl->options.processReply = doProcessInit; /* input exhausted? */ if (ssl->buffers.inputBuffer.idx == ssl->buffers.inputBuffer.length) return 0; /* more messages per record */ else if ((ssl->buffers.inputBuffer.idx - startIdx) < ssl->curSize) { WOLFSSL_MSG("More messages in record"); #ifdef WOLFSSL_DTLS /* read-ahead but dtls doesn't bundle messages per record */ if (ssl->options.dtls) { ssl->options.processReply = doProcessInit; continue; } #endif ssl->options.processReply = runProcessingOneMessage; if (ssl->keys.encryptionOn) { WOLFSSL_MSG("Bundled encrypted messages, remove middle pad"); ssl->buffers.inputBuffer.idx -= ssl->keys.padSz; } continue; } /* more records */ else { WOLFSSL_MSG("More records in input"); ssl->options.processReply = doProcessInit; continue; } default: WOLFSSL_MSG("Bad process input state, programming error"); return INPUT_CASE_ERROR; } } } int SendChangeCipher(WOLFSSL* ssl) { byte *output; int sendSz = RECORD_HEADER_SZ + ENUM_LEN; int idx = RECORD_HEADER_SZ; int ret; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA; idx += DTLS_RECORD_EXTRA; } #endif /* are we in scr */ if (ssl->keys.encryptionOn && ssl->options.handShakeDone) { sendSz += MAX_MSG_EXTRA; } /* check for avalaible size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddRecordHeader(output, 1, change_cipher_spec, ssl); output[idx] = 1; /* turn it on */ if (ssl->keys.encryptionOn && ssl->options.handShakeDone) { byte input[ENUM_LEN]; int inputSz = ENUM_LEN; input[0] = 1; /* turn it on */ sendSz = BuildMessage(ssl, output, sendSz, input, inputSz, change_cipher_spec); if (sendSz < 0) return sendSz; } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ChangeCipher", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ChangeCipher", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) return 0; #ifdef WOLFSSL_DTLS else if (ssl->options.dtls) { /* If using DTLS, force the ChangeCipherSpec message to be in the * same datagram as the finished message. */ return 0; } #endif else return SendBuffered(ssl); } #ifndef NO_OLD_TLS static int SSL_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int content, int verify) { byte result[MAX_DIGEST_SIZE]; word32 digestSz = ssl->specs.hash_size; /* actual sizes */ word32 padSz = ssl->specs.pad_size; int ret = 0; Md5 md5; Sha sha; /* data */ byte seq[SEQ_SZ]; byte conLen[ENUM_LEN + LENGTH_SZ]; /* content & length */ const byte* macSecret = wolfSSL_GetMacSecret(ssl, verify); #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, in, sz, FUZZ_HMAC, ssl->fuzzerCtx); #endif XMEMSET(seq, 0, SEQ_SZ); conLen[0] = (byte)content; c16toa((word16)sz, &conLen[ENUM_LEN]); c32toa(GetSEQIncrement(ssl, verify), &seq[sizeof(word32)]); if (ssl->specs.mac_algorithm == md5_mac) { wc_InitMd5(&md5); /* inner */ wc_Md5Update(&md5, macSecret, digestSz); wc_Md5Update(&md5, PAD1, padSz); wc_Md5Update(&md5, seq, SEQ_SZ); wc_Md5Update(&md5, conLen, sizeof(conLen)); /* in buffer */ wc_Md5Update(&md5, in, sz); wc_Md5Final(&md5, result); /* outer */ wc_Md5Update(&md5, macSecret, digestSz); wc_Md5Update(&md5, PAD2, padSz); wc_Md5Update(&md5, result, digestSz); wc_Md5Final(&md5, digest); } else { ret = wc_InitSha(&sha); if (ret != 0) return ret; /* inner */ wc_ShaUpdate(&sha, macSecret, digestSz); wc_ShaUpdate(&sha, PAD1, padSz); wc_ShaUpdate(&sha, seq, SEQ_SZ); wc_ShaUpdate(&sha, conLen, sizeof(conLen)); /* in buffer */ wc_ShaUpdate(&sha, in, sz); wc_ShaFinal(&sha, result); /* outer */ wc_ShaUpdate(&sha, macSecret, digestSz); wc_ShaUpdate(&sha, PAD2, padSz); wc_ShaUpdate(&sha, result, digestSz); wc_ShaFinal(&sha, digest); } return 0; } #ifndef NO_CERTS static void BuildMD5_CertVerify(WOLFSSL* ssl, byte* digest) { byte md5_result[MD5_DIGEST_SIZE]; #ifdef WOLFSSL_SMALL_STACK Md5* md5 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); Md5* md5_2 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); #else Md5 md5[1]; Md5 md5_2[1]; #endif /* make md5 inner */ md5[0] = ssl->hsHashes->hashMd5 ; /* Save current position */ wc_Md5Update(&ssl->hsHashes->hashMd5, ssl->arrays->masterSecret,SECRET_LEN); wc_Md5Update(&ssl->hsHashes->hashMd5, PAD1, PAD_MD5); wc_Md5GetHash(&ssl->hsHashes->hashMd5, md5_result); wc_Md5RestorePos(&ssl->hsHashes->hashMd5, md5) ; /* Restore current position */ /* make md5 outer */ wc_InitMd5(md5_2) ; wc_Md5Update(md5_2, ssl->arrays->masterSecret, SECRET_LEN); wc_Md5Update(md5_2, PAD2, PAD_MD5); wc_Md5Update(md5_2, md5_result, MD5_DIGEST_SIZE); wc_Md5Final(md5_2, digest); #ifdef WOLFSSL_SMALL_STACK XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(md5_2, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } static void BuildSHA_CertVerify(WOLFSSL* ssl, byte* digest) { byte sha_result[SHA_DIGEST_SIZE]; #ifdef WOLFSSL_SMALL_STACK Sha* sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); Sha* sha2 = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); #else Sha sha[1]; Sha sha2[1]; #endif /* make sha inner */ sha[0] = ssl->hsHashes->hashSha ; /* Save current position */ wc_ShaUpdate(&ssl->hsHashes->hashSha, ssl->arrays->masterSecret,SECRET_LEN); wc_ShaUpdate(&ssl->hsHashes->hashSha, PAD1, PAD_SHA); wc_ShaGetHash(&ssl->hsHashes->hashSha, sha_result); wc_ShaRestorePos(&ssl->hsHashes->hashSha, sha) ; /* Restore current position */ /* make sha outer */ wc_InitSha(sha2) ; wc_ShaUpdate(sha2, ssl->arrays->masterSecret,SECRET_LEN); wc_ShaUpdate(sha2, PAD2, PAD_SHA); wc_ShaUpdate(sha2, sha_result, SHA_DIGEST_SIZE); wc_ShaFinal(sha2, digest); #ifdef WOLFSSL_SMALL_STACK XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(sha2, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } #endif /* NO_CERTS */ #endif /* NO_OLD_TLS */ #ifndef NO_CERTS static int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes) { /* store current states, building requires get_digest which resets state */ #ifdef WOLFSSL_SHA384 Sha384 sha384 = ssl->hsHashes->hashSha384; #endif #ifdef WOLFSSL_SHA512 Sha512 sha512 = ssl->hsHashes->hashSha512; #endif if (ssl->options.tls) { #if ! defined( NO_OLD_TLS ) wc_Md5GetHash(&ssl->hsHashes->hashMd5, hashes->md5); wc_ShaGetHash(&ssl->hsHashes->hashSha, hashes->sha); #endif if (IsAtLeastTLSv1_2(ssl)) { int ret; #ifndef NO_SHA256 ret = wc_Sha256GetHash(&ssl->hsHashes->hashSha256,hashes->sha256); if (ret != 0) return ret; #endif #ifdef WOLFSSL_SHA384 ret = wc_Sha384Final(&ssl->hsHashes->hashSha384,hashes->sha384); if (ret != 0) return ret; #endif #ifdef WOLFSSL_SHA512 ret = wc_Sha512Final(&ssl->hsHashes->hashSha512,hashes->sha512); if (ret != 0) return ret; #endif } } #if ! defined( NO_OLD_TLS ) else { BuildMD5_CertVerify(ssl, hashes->md5); BuildSHA_CertVerify(ssl, hashes->sha); } /* restore */ #endif if (IsAtLeastTLSv1_2(ssl)) { #ifdef WOLFSSL_SHA384 ssl->hsHashes->hashSha384 = sha384; #endif #ifdef WOLFSSL_SHA512 ssl->hsHashes->hashSha512 = sha512; #endif } return 0; } #endif /* WOLFSSL_LEANPSK */ /* Build SSL Message, encrypted */ static int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input, int inSz, int type) { #ifdef HAVE_TRUNCATED_HMAC word32 digestSz = min(ssl->specs.hash_size, ssl->truncated_hmac ? TRUNCATED_HMAC_SZ : ssl->specs.hash_size); #else word32 digestSz = ssl->specs.hash_size; #endif word32 sz = RECORD_HEADER_SZ + inSz + digestSz; word32 pad = 0, i; word32 idx = RECORD_HEADER_SZ; word32 ivSz = 0; /* TLSv1.1 IV */ word32 headerSz = RECORD_HEADER_SZ; word16 size; byte iv[AES_BLOCK_SIZE]; /* max size */ int ret = 0; int atomicUser = 0; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sz += DTLS_RECORD_EXTRA; idx += DTLS_RECORD_EXTRA; headerSz += DTLS_RECORD_EXTRA; } #endif #ifdef ATOMIC_USER if (ssl->ctx->MacEncryptCb) atomicUser = 1; #endif if (ssl->specs.cipher_type == block) { word32 blockSz = ssl->specs.block_size; if (ssl->options.tls1_1) { ivSz = blockSz; sz += ivSz; if (ivSz > (word32)sizeof(iv)) return BUFFER_E; ret = wc_RNG_GenerateBlock(ssl->rng, iv, ivSz); if (ret != 0) return ret; } sz += 1; /* pad byte */ pad = (sz - headerSz) % blockSz; pad = blockSz - pad; sz += pad; } #ifdef HAVE_AEAD if (ssl->specs.cipher_type == aead) { if (ssl->specs.bulk_cipher_algorithm != wolfssl_chacha) ivSz = AEAD_EXP_IV_SZ; sz += (ivSz + ssl->specs.aead_mac_size - digestSz); XMEMCPY(iv, ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ); } #endif if (sz > (word32)outSz) { WOLFSSL_MSG("Oops, want to write past output buffer size"); return BUFFER_E; } size = (word16)(sz - headerSz); /* include mac and digest */ AddRecordHeader(output, size, (byte)type, ssl); /* write to output */ if (ivSz) { XMEMCPY(output + idx, iv, min(ivSz, sizeof(iv))); idx += ivSz; } XMEMCPY(output + idx, input, inSz); idx += inSz; if (type == handshake) { ret = HashOutput(ssl, output, headerSz + inSz, ivSz); if (ret != 0) return ret; } if (ssl->specs.cipher_type == block) { word32 tmpIdx = idx + digestSz; for (i = 0; i <= pad; i++) output[tmpIdx++] = (byte)pad; /* pad byte gets pad value too */ } if (atomicUser) { /* User Record Layer Callback handling */ #ifdef ATOMIC_USER if ( (ret = ssl->ctx->MacEncryptCb(ssl, output + idx, output + headerSz + ivSz, inSz, type, 0, output + headerSz, output + headerSz, size, ssl->MacEncryptCtx)) != 0) return ret; #endif } else { if (ssl->specs.cipher_type != aead) { #ifdef HAVE_TRUNCATED_HMAC if (ssl->truncated_hmac && ssl->specs.hash_size > digestSz) { #ifdef WOLFSSL_SMALL_STACK byte* hmac = NULL; #else byte hmac[MAX_DIGEST_SIZE]; #endif #ifdef WOLFSSL_SMALL_STACK hmac = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hmac == NULL) return MEMORY_E; #endif ret = ssl->hmac(ssl, hmac, output + headerSz + ivSz, inSz, type, 0); XMEMCPY(output + idx, hmac, digestSz); #ifdef WOLFSSL_SMALL_STACK XFREE(hmac, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } else #endif ret = ssl->hmac(ssl, output+idx, output + headerSz + ivSz, inSz, type, 0); } if (ret != 0) return ret; if ( (ret = Encrypt(ssl, output + headerSz, output+headerSz,size)) != 0) return ret; } return sz; } int SendFinished(WOLFSSL* ssl) { int sendSz, finishedSz = ssl->options.tls ? TLS_FINISHED_SZ : FINISHED_SZ; byte input[FINISHED_SZ + DTLS_HANDSHAKE_HEADER_SZ]; /* max */ byte *output; Hashes* hashes; int ret; int headerSz = HANDSHAKE_HEADER_SZ; int outputSz; #ifdef WOLFSSL_DTLS word32 sequence_number = ssl->keys.dtls_sequence_number; word16 epoch = ssl->keys.dtls_epoch; #endif /* setup encrypt keys */ if ((ret = SetKeysSide(ssl, ENCRYPT_SIDE_ONLY)) != 0) return ret; /* check for available size */ outputSz = sizeof(input) + MAX_MSG_EXTRA; if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) return ret; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { /* Send Finished message with the next epoch, but don't commit that * change until the other end confirms its reception. */ headerSz += DTLS_HANDSHAKE_EXTRA; ssl->keys.dtls_epoch++; ssl->keys.dtls_sequence_number = 0; /* reset after epoch change */ } #endif /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHandShakeHeader(input, finishedSz, finished, ssl); /* make finished hashes */ hashes = (Hashes*)&input[headerSz]; ret = BuildFinished(ssl, hashes, ssl->options.side == WOLFSSL_CLIENT_END ? client : server); if (ret != 0) return ret; #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation) { if (ssl->options.side == WOLFSSL_CLIENT_END) XMEMCPY(ssl->secure_renegotiation->client_verify_data, hashes, TLS_FINISHED_SZ); else XMEMCPY(ssl->secure_renegotiation->server_verify_data, hashes, TLS_FINISHED_SZ); } #endif sendSz = BuildMessage(ssl, output, outputSz, input, headerSz + finishedSz, handshake); if (sendSz < 0) return BUILD_MSG_ERROR; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { ssl->keys.dtls_epoch = epoch; ssl->keys.dtls_sequence_number = sequence_number; } #endif if (!ssl->options.resuming) { #ifndef NO_SESSION_CACHE AddSession(ssl); /* just try */ #endif if (ssl->options.side == WOLFSSL_SERVER_END) { ssl->options.handShakeState = HANDSHAKE_DONE; ssl->options.handShakeDone = 1; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { /* Other side will soon receive our Finished, go to next * epoch. */ ssl->keys.dtls_epoch++; ssl->keys.dtls_sequence_number = 1; } #endif } } else { if (ssl->options.side == WOLFSSL_CLIENT_END) { ssl->options.handShakeState = HANDSHAKE_DONE; ssl->options.handShakeDone = 1; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { /* Other side will soon receive our Finished, go to next * epoch. */ ssl->keys.dtls_epoch++; ssl->keys.dtls_sequence_number = 1; } #endif } } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Finished", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("Finished", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; return SendBuffered(ssl); } #ifndef NO_CERTS int SendCertificate(WOLFSSL* ssl) { int sendSz, length, ret = 0; word32 i = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; word32 certSz, listSz; byte* output = 0; if (ssl->options.usingPSK_cipher || ssl->options.usingAnon_cipher) return 0; /* not needed */ if (ssl->options.sendVerify == SEND_BLANK_CERT) { certSz = 0; length = CERT_HEADER_SZ; listSz = 0; } else { certSz = ssl->buffers.certificate.length; /* list + cert size */ length = certSz + 2 * CERT_HEADER_SZ; listSz = certSz + CERT_HEADER_SZ; /* may need to send rest of chain, already has leading size(s) */ if (ssl->buffers.certChain.buffer) { length += ssl->buffers.certChain.length; listSz += ssl->buffers.certChain.length; } } sendSz = length + RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; i += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; } #endif if (ssl->keys.encryptionOn) sendSz += MAX_MSG_EXTRA; /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, certificate, ssl); /* list total */ c32to24(listSz, output + i); i += CERT_HEADER_SZ; /* member */ if (certSz) { c32to24(certSz, output + i); i += CERT_HEADER_SZ; XMEMCPY(output + i, ssl->buffers.certificate.buffer, certSz); i += certSz; /* send rest of chain? */ if (ssl->buffers.certChain.buffer) { XMEMCPY(output + i, ssl->buffers.certChain.buffer, ssl->buffers.certChain.length); i += ssl->buffers.certChain.length; } } if (ssl->keys.encryptionOn) { byte* input; int inputSz = i - RECORD_HEADER_SZ; /* build msg adds rec hdr */ input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (input == NULL) return MEMORY_E; XMEMCPY(input, output + RECORD_HEADER_SZ, inputSz); sendSz = BuildMessage(ssl, output, sendSz, input,inputSz,handshake); XFREE(input, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (sendSz < 0) return sendSz; } else { ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Certificate", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("Certificate", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif if (ssl->options.side == WOLFSSL_SERVER_END) ssl->options.serverState = SERVER_CERT_COMPLETE; ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) return 0; else return SendBuffered(ssl); } int SendCertificateRequest(WOLFSSL* ssl) { byte *output; int ret; int sendSz; word32 i = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int typeTotal = 1; /* only 1 for now */ int reqSz = ENUM_LEN + typeTotal + REQ_HEADER_SZ; /* add auth later */ if (IsAtLeastTLSv1_2(ssl)) reqSz += LENGTH_SZ + ssl->suites->hashSigAlgoSz; if (ssl->options.usingPSK_cipher || ssl->options.usingAnon_cipher) return 0; /* not needed */ sendSz = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ + reqSz; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; i += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; } #endif /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, reqSz, certificate_request, ssl); /* write to output */ output[i++] = (byte)typeTotal; /* # of types */ #ifdef HAVE_ECC if (ssl->options.cipherSuite0 == ECC_BYTE && ssl->specs.sig_algo == ecc_dsa_sa_algo) { output[i++] = ecdsa_sign; } else #endif /* HAVE_ECC */ { output[i++] = rsa_sign; } /* supported hash/sig */ if (IsAtLeastTLSv1_2(ssl)) { c16toa(ssl->suites->hashSigAlgoSz, &output[i]); i += LENGTH_SZ; XMEMCPY(&output[i], ssl->suites->hashSigAlgo, ssl->suites->hashSigAlgoSz); i += ssl->suites->hashSigAlgoSz; } c16toa(0, &output[i]); /* auth's */ /* if add more to output, adjust i i += REQ_HEADER_SZ; */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("CertificateRequest", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("CertificateRequest", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) return 0; else return SendBuffered(ssl); } #endif /* !NO_CERTS */ int SendData(WOLFSSL* ssl, const void* data, int sz) { int sent = 0, /* plainText size */ sendSz, ret, dtlsExtra = 0; if (ssl->error == WANT_WRITE) ssl->error = 0; if (ssl->options.handShakeState != HANDSHAKE_DONE) { int err; WOLFSSL_MSG("handshake not complete, trying to finish"); if ( (err = wolfSSL_negotiate(ssl)) != SSL_SUCCESS) return err; } /* last time system socket output buffer was full, try again to send */ if (ssl->buffers.outputBuffer.length > 0) { WOLFSSL_MSG("output buffer was full, trying to send again"); if ( (ssl->error = SendBuffered(ssl)) < 0) { WOLFSSL_ERROR(ssl->error); if (ssl->error == SOCKET_ERROR_E && ssl->options.connReset) return 0; /* peer reset */ return ssl->error; } else { /* advance sent to previous sent + plain size just sent */ sent = ssl->buffers.prevSent + ssl->buffers.plainSz; WOLFSSL_MSG("sent write buffered data"); if (sent > sz) { WOLFSSL_MSG("error: write() after WANT_WRITE with short size"); return ssl->error = BAD_FUNC_ARG; } } } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { dtlsExtra = DTLS_RECORD_EXTRA; } #endif for (;;) { #ifdef HAVE_MAX_FRAGMENT int len = min(sz - sent, min(ssl->max_fragment, OUTPUT_RECORD_SIZE)); #else int len = min(sz - sent, OUTPUT_RECORD_SIZE); #endif byte* out; byte* sendBuffer = (byte*)data + sent; /* may switch on comp */ int buffSz = len; /* may switch on comp */ int outputSz; #ifdef HAVE_LIBZ byte comp[MAX_RECORD_SIZE + MAX_COMP_EXTRA]; #endif if (sent == sz) break; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { len = min(len, MAX_UDP_SIZE); buffSz = len; } #endif /* check for available size */ outputSz = len + COMP_EXTRA + dtlsExtra + MAX_MSG_EXTRA; if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) return ssl->error = ret; /* get ouput buffer */ out = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; #ifdef HAVE_LIBZ if (ssl->options.usingCompression) { buffSz = myCompress(ssl, sendBuffer, buffSz, comp, sizeof(comp)); if (buffSz < 0) { return buffSz; } sendBuffer = comp; } #endif sendSz = BuildMessage(ssl, out, outputSz, sendBuffer, buffSz, application_data); if (sendSz < 0) return BUILD_MSG_ERROR; ssl->buffers.outputBuffer.length += sendSz; if ( (ret = SendBuffered(ssl)) < 0) { WOLFSSL_ERROR(ret); /* store for next call if WANT_WRITE or user embedSend() that doesn't present like WANT_WRITE */ ssl->buffers.plainSz = len; ssl->buffers.prevSent = sent; if (ret == SOCKET_ERROR_E && ssl->options.connReset) return 0; /* peer reset */ return ssl->error = ret; } sent += len; /* only one message per attempt */ if (ssl->options.partialWrite == 1) { WOLFSSL_MSG("Paritial Write on, only sending one record"); break; } } return sent; } /* process input data */ int ReceiveData(WOLFSSL* ssl, byte* output, int sz, int peek) { int size; WOLFSSL_ENTER("ReceiveData()"); if (ssl->error == WANT_READ) ssl->error = 0; if (ssl->error != 0 && ssl->error != WANT_WRITE) { WOLFSSL_MSG("User calling wolfSSL_read in error state, not allowed"); return ssl->error; } if (ssl->options.handShakeState != HANDSHAKE_DONE) { int err; WOLFSSL_MSG("Handshake not complete, trying to finish"); if ( (err = wolfSSL_negotiate(ssl)) != SSL_SUCCESS) return err; } #ifdef HAVE_SECURE_RENEGOTIATION startScr: if (ssl->secure_renegotiation && ssl->secure_renegotiation->startScr) { int err; ssl->secure_renegotiation->startScr = 0; /* only start once */ WOLFSSL_MSG("Need to start scr, server requested"); if ( (err = wolfSSL_Rehandshake(ssl)) != SSL_SUCCESS) return err; } #endif while (ssl->buffers.clearOutputBuffer.length == 0) { if ( (ssl->error = ProcessReply(ssl)) < 0) { WOLFSSL_ERROR(ssl->error); if (ssl->error == ZERO_RETURN) { WOLFSSL_MSG("Zero return, no more data coming"); return 0; /* no more data coming */ } if (ssl->error == SOCKET_ERROR_E) { if (ssl->options.connReset || ssl->options.isClosed) { WOLFSSL_MSG("Peer reset or closed, connection done"); ssl->error = SOCKET_PEER_CLOSED_E; WOLFSSL_ERROR(ssl->error); return 0; /* peer reset or closed */ } } return ssl->error; } #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation && ssl->secure_renegotiation->startScr) { goto startScr; } #endif } if (sz < (int)ssl->buffers.clearOutputBuffer.length) size = sz; else size = ssl->buffers.clearOutputBuffer.length; XMEMCPY(output, ssl->buffers.clearOutputBuffer.buffer, size); if (peek == 0) { ssl->buffers.clearOutputBuffer.length -= size; ssl->buffers.clearOutputBuffer.buffer += size; } if (ssl->buffers.clearOutputBuffer.length == 0 && ssl->buffers.inputBuffer.dynamicFlag) ShrinkInputBuffer(ssl, NO_FORCED_FREE); WOLFSSL_LEAVE("ReceiveData()", size); return size; } /* send alert message */ int SendAlert(WOLFSSL* ssl, int severity, int type) { byte input[ALERT_SIZE]; byte *output; int sendSz; int ret; int outputSz; int dtlsExtra = 0; /* if sendalert is called again for nonbloking */ if (ssl->options.sendAlertState != 0) { ret = SendBuffered(ssl); if (ret == 0) ssl->options.sendAlertState = 0; return ret; } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) dtlsExtra = DTLS_RECORD_EXTRA; #endif /* check for available size */ outputSz = ALERT_SIZE + MAX_MSG_EXTRA + dtlsExtra; if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; input[0] = (byte)severity; input[1] = (byte)type; ssl->alert_history.last_tx.code = type; ssl->alert_history.last_tx.level = severity; if (severity == alert_fatal) { ssl->options.isClosed = 1; /* Don't send close_notify */ } /* only send encrypted alert if handshake actually complete, otherwise other side may not be able to handle it */ if (ssl->keys.encryptionOn && ssl->options.handShakeDone) sendSz = BuildMessage(ssl, output, outputSz, input, ALERT_SIZE, alert); else { AddRecordHeader(output, ALERT_SIZE, alert, ssl); output += RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) output += DTLS_RECORD_EXTRA; #endif XMEMCPY(output, input, ALERT_SIZE); sendSz = RECORD_HEADER_SZ + ALERT_SIZE; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) sendSz += DTLS_RECORD_EXTRA; #endif } if (sendSz < 0) return BUILD_MSG_ERROR; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Alert", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("Alert", &ssl->timeoutInfo, output, sendSz,ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; ssl->options.sendAlertState = 1; return SendBuffered(ssl); } const char* wolfSSL_ERR_reason_error_string(unsigned long e) { #ifdef NO_ERROR_STRINGS (void)e; return "no support for error strings built in"; #else int error = (int)e; /* pass to wolfCrypt */ if (error < MAX_CODE_E && error > MIN_CODE_E) { return wc_GetErrorString(error); } switch (error) { case UNSUPPORTED_SUITE : return "unsupported cipher suite"; case INPUT_CASE_ERROR : return "input state error"; case PREFIX_ERROR : return "bad index to key rounds"; case MEMORY_ERROR : return "out of memory"; case VERIFY_FINISHED_ERROR : return "verify problem on finished"; case VERIFY_MAC_ERROR : return "verify mac problem"; case PARSE_ERROR : return "parse error on header"; case SIDE_ERROR : return "wrong client/server type"; case NO_PEER_CERT : return "peer didn't send cert"; case UNKNOWN_HANDSHAKE_TYPE : return "weird handshake type"; case SOCKET_ERROR_E : return "error state on socket"; case SOCKET_NODATA : return "expected data, not there"; case INCOMPLETE_DATA : return "don't have enough data to complete task"; case UNKNOWN_RECORD_TYPE : return "unknown type in record hdr"; case DECRYPT_ERROR : return "error during decryption"; case FATAL_ERROR : return "revcd alert fatal error"; case ENCRYPT_ERROR : return "error during encryption"; case FREAD_ERROR : return "fread problem"; case NO_PEER_KEY : return "need peer's key"; case NO_PRIVATE_KEY : return "need the private key"; case NO_DH_PARAMS : return "server missing DH params"; case RSA_PRIVATE_ERROR : return "error during rsa priv op"; case MATCH_SUITE_ERROR : return "can't match cipher suite"; case BUILD_MSG_ERROR : return "build message failure"; case BAD_HELLO : return "client hello malformed"; case DOMAIN_NAME_MISMATCH : return "peer subject name mismatch"; case WANT_READ : case SSL_ERROR_WANT_READ : return "non-blocking socket wants data to be read"; case NOT_READY_ERROR : return "handshake layer not ready yet, complete first"; case PMS_VERSION_ERROR : return "premaster secret version mismatch error"; case VERSION_ERROR : return "record layer version error"; case WANT_WRITE : case SSL_ERROR_WANT_WRITE : return "non-blocking socket write buffer full"; case BUFFER_ERROR : return "malformed buffer input error"; case VERIFY_CERT_ERROR : return "verify problem on certificate"; case VERIFY_SIGN_ERROR : return "verify problem based on signature"; case CLIENT_ID_ERROR : return "psk client identity error"; case SERVER_HINT_ERROR: return "psk server hint error"; case PSK_KEY_ERROR: return "psk key callback error"; case NTRU_KEY_ERROR: return "NTRU key error"; case NTRU_DRBG_ERROR: return "NTRU drbg error"; case NTRU_ENCRYPT_ERROR: return "NTRU encrypt error"; case NTRU_DECRYPT_ERROR: return "NTRU decrypt error"; case ZLIB_INIT_ERROR: return "zlib init error"; case ZLIB_COMPRESS_ERROR: return "zlib compress error"; case ZLIB_DECOMPRESS_ERROR: return "zlib decompress error"; case GETTIME_ERROR: return "gettimeofday() error"; case GETITIMER_ERROR: return "getitimer() error"; case SIGACT_ERROR: return "sigaction() error"; case SETITIMER_ERROR: return "setitimer() error"; case LENGTH_ERROR: return "record layer length error"; case PEER_KEY_ERROR: return "cant decode peer key"; case ZERO_RETURN: case SSL_ERROR_ZERO_RETURN: return "peer sent close notify alert"; case ECC_CURVETYPE_ERROR: return "Bad ECC Curve Type or unsupported"; case ECC_CURVE_ERROR: return "Bad ECC Curve or unsupported"; case ECC_PEERKEY_ERROR: return "Bad ECC Peer Key"; case ECC_MAKEKEY_ERROR: return "ECC Make Key failure"; case ECC_EXPORT_ERROR: return "ECC Export Key failure"; case ECC_SHARED_ERROR: return "ECC DHE shared failure"; case NOT_CA_ERROR: return "Not a CA by basic constraint error"; case BAD_PATH_ERROR: return "Bad path for opendir error"; case BAD_CERT_MANAGER_ERROR: return "Bad Cert Manager error"; case OCSP_CERT_REVOKED: return "OCSP Cert revoked"; case CRL_CERT_REVOKED: return "CRL Cert revoked"; case CRL_MISSING: return "CRL missing, not loaded"; case MONITOR_RUNNING_E: return "CRL monitor already running"; case THREAD_CREATE_E: return "Thread creation problem"; case OCSP_NEED_URL: return "OCSP need URL"; case OCSP_CERT_UNKNOWN: return "OCSP Cert unknown"; case OCSP_LOOKUP_FAIL: return "OCSP Responder lookup fail"; case MAX_CHAIN_ERROR: return "Maximum Chain Depth Exceeded"; case COOKIE_ERROR: return "DTLS Cookie Error"; case SEQUENCE_ERROR: return "DTLS Sequence Error"; case SUITES_ERROR: return "Suites Pointer Error"; case SSL_NO_PEM_HEADER: return "No PEM Header Error"; case OUT_OF_ORDER_E: return "Out of order message, fatal"; case BAD_KEA_TYPE_E: return "Bad KEA type found"; case SANITY_CIPHER_E: return "Sanity check on ciphertext failed"; case RECV_OVERFLOW_E: return "Receive callback returned more than requested"; case GEN_COOKIE_E: return "Generate Cookie Error"; case NO_PEER_VERIFY: return "Need peer certificate verify Error"; case FWRITE_ERROR: return "fwrite Error"; case CACHE_MATCH_ERROR: return "Cache restore header match Error"; case UNKNOWN_SNI_HOST_NAME_E: return "Unrecognized host name Error"; case KEYUSE_SIGNATURE_E: return "Key Use digitalSignature not set Error"; case KEYUSE_ENCIPHER_E: return "Key Use keyEncipherment not set Error"; case EXTKEYUSE_AUTH_E: return "Ext Key Use server/client auth not set Error"; case SEND_OOB_READ_E: return "Send Callback Out of Bounds Read Error"; case SECURE_RENEGOTIATION_E: return "Invalid Renegotiation Error"; case SESSION_TICKET_LEN_E: return "Session Ticket Too Long Error"; case SESSION_TICKET_EXPECT_E: return "Session Ticket Error"; case SCR_DIFFERENT_CERT_E: return "Peer sent different cert during SCR"; case SESSION_SECRET_CB_E: return "Session Secret Callback Error"; case NO_CHANGE_CIPHER_E: return "Finished received from peer before Change Cipher Error"; case SANITY_MSG_E: return "Sanity Check on message order Error"; case DUPLICATE_MSG_E: return "Duplicate HandShake message Error"; case SNI_UNSUPPORTED: return "Protocol version does not support SNI Error"; case SOCKET_PEER_CLOSED_E: return "Peer closed underlying transport Error"; case BAD_TICKET_KEY_CB_SZ: return "Bad user session ticket key callback Size Error"; case BAD_TICKET_MSG_SZ: return "Bad session ticket message Size Error"; case BAD_TICKET_ENCRYPT: return "Bad user ticket callback encrypt Error"; case DH_KEY_SIZE_E: return "DH key too small Error"; default : return "unknown error number"; } #endif /* NO_ERROR_STRINGS */ } void SetErrorString(int error, char* str) { XSTRNCPY(str, wolfSSL_ERR_reason_error_string(error), WOLFSSL_MAX_ERROR_SZ); } /* be sure to add to cipher_name_idx too !!!! */ static const char* const cipher_names[] = { #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA "RC4-SHA", #endif #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 "RC4-MD5", #endif #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA "DES-CBC3-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA "AES128-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA "AES256-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_NULL_SHA "NULL-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 "NULL-SHA256", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA "DHE-RSA-AES128-SHA", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA "DHE-RSA-AES256-SHA", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 "DHE-PSK-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 "DHE-PSK-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384 "PSK-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256 "PSK-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 "DHE-PSK-AES256-CBC-SHA384", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 "DHE-PSK-AES128-CBC-SHA256", #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384 "PSK-AES256-CBC-SHA384", #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 "PSK-AES128-CBC-SHA256", #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA "PSK-AES128-CBC-SHA", #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA "PSK-AES256-CBC-SHA", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CCM "DHE-PSK-AES128-CCM", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CCM "DHE-PSK-AES256-CCM", #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM "PSK-AES128-CCM", #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM "PSK-AES256-CCM", #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 "PSK-AES128-CCM-8", #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 "PSK-AES256-CCM-8", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA384 "DHE-PSK-NULL-SHA384", #endif #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA256 "DHE-PSK-NULL-SHA256", #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA384 "PSK-NULL-SHA384", #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 "PSK-NULL-SHA256", #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA "PSK-NULL-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_MD5 "HC128-MD5", #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_SHA "HC128-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_B2B256 "HC128-B2B256", #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 "AES128-B2B256", #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 "AES256-B2B256", #endif #ifdef BUILD_TLS_RSA_WITH_RABBIT_SHA "RABBIT-SHA", #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA "NTRU-RC4-SHA", #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA "NTRU-DES-CBC3-SHA", #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA "NTRU-AES128-SHA", #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA "NTRU-AES256-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 "AES128-CCM-8", #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 "AES256-CCM-8", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 "ECDHE-ECDSA-AES128-CCM-8", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 "ECDHE-ECDSA-AES256-CCM-8", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA "ECDHE-RSA-AES128-SHA", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA "ECDHE-RSA-AES256-SHA", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "ECDHE-ECDSA-AES128-SHA", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "ECDHE-ECDSA-AES256-SHA", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA "ECDHE-RSA-RC4-SHA", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA "ECDHE-RSA-DES-CBC3-SHA", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA "ECDHE-ECDSA-RC4-SHA", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA "ECDHE-ECDSA-DES-CBC3-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 "AES128-SHA256", #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 "AES256-SHA256", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 "DHE-RSA-AES128-SHA256", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 "DHE-RSA-AES256-SHA256", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA "ECDH-RSA-AES128-SHA", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA "ECDH-RSA-AES256-SHA", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA "ECDH-ECDSA-AES128-SHA", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA "ECDH-ECDSA-AES256-SHA", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA "ECDH-RSA-RC4-SHA", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA "ECDH-RSA-DES-CBC3-SHA", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA "ECDH-ECDSA-RC4-SHA", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA "ECDH-ECDSA-DES-CBC3-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 "AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 "AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 "DHE-RSA-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 "DHE-RSA-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 "ECDHE-RSA-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 "ECDHE-RSA-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 "ECDHE-ECDSA-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 "ECDHE-ECDSA-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 "ECDH-RSA-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 "ECDH-RSA-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 "ECDH-ECDSA-AES128-GCM-SHA256", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 "ECDH-ECDSA-AES256-GCM-SHA384", #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA "CAMELLIA128-SHA", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "DHE-RSA-CAMELLIA128-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA "CAMELLIA256-SHA", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "DHE-RSA-CAMELLIA256-SHA", #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 "CAMELLIA128-SHA256", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DHE-RSA-CAMELLIA128-SHA256", #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 "CAMELLIA256-SHA256", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DHE-RSA-CAMELLIA256-SHA256", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 "ECDHE-RSA-AES128-SHA256", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 "ECDHE-ECDSA-AES128-SHA256", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 "ECDH-RSA-AES128-SHA256", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 "ECDH-ECDSA-AES128-SHA256", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 "ECDHE-RSA-AES256-SHA384", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 "ECDHE-ECDSA-AES256-SHA384", #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 "ECDH-RSA-AES256-SHA384", #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 "ECDH-ECDSA-AES256-SHA384", #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 "ECDHE-RSA-CHACHA20-POLY1305", #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 "ECDHE-ECDSA-CHACHA20-POLY1305", #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 "DHE-RSA-CHACHA20-POLY1305", #endif #ifdef BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA "ADH-AES128-SHA", #endif #ifdef HAVE_RENEGOTIATION_INDICATION "RENEGOTIATION-INFO", #endif }; /* cipher suite number that matches above name table */ static int cipher_name_idx[] = { #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA SSL_RSA_WITH_RC4_128_SHA, #endif #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 SSL_RSA_WITH_RC4_128_MD5, #endif #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA SSL_RSA_WITH_3DES_EDE_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA TLS_RSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA TLS_RSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_NULL_SHA TLS_RSA_WITH_NULL_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 TLS_RSA_WITH_NULL_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA TLS_DHE_RSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA TLS_DHE_RSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 TLS_DHE_PSK_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384 TLS_PSK_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256 TLS_PSK_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384 TLS_PSK_WITH_AES_256_CBC_SHA384, #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 TLS_PSK_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA TLS_PSK_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA TLS_PSK_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_128_CCM TLS_DHE_PSK_WITH_AES_128_CCM, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_AES_256_CCM TLS_DHE_PSK_WITH_AES_256_CCM, #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM TLS_PSK_WITH_AES_128_CCM, #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM TLS_PSK_WITH_AES_256_CCM, #endif #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 TLS_PSK_WITH_AES_128_CCM_8, #endif #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 TLS_PSK_WITH_AES_256_CCM_8, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA384 TLS_DHE_PSK_WITH_NULL_SHA384, #endif #ifdef BUILD_TLS_DHE_PSK_WITH_NULL_SHA256 TLS_DHE_PSK_WITH_NULL_SHA256, #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA384 TLS_PSK_WITH_NULL_SHA384, #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 TLS_PSK_WITH_NULL_SHA256, #endif #ifdef BUILD_TLS_PSK_WITH_NULL_SHA TLS_PSK_WITH_NULL_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_MD5 TLS_RSA_WITH_HC_128_MD5, #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_SHA TLS_RSA_WITH_HC_128_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_HC_128_B2B256 TLS_RSA_WITH_HC_128_B2B256, #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 TLS_RSA_WITH_AES_128_CBC_B2B256, #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 TLS_RSA_WITH_AES_256_CBC_B2B256, #endif #ifdef BUILD_TLS_RSA_WITH_RABBIT_SHA TLS_RSA_WITH_RABBIT_SHA, #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA TLS_NTRU_RSA_WITH_RC4_128_SHA, #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA, #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA TLS_NTRU_RSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA TLS_NTRU_RSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 TLS_RSA_WITH_AES_128_CCM_8, #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 TLS_RSA_WITH_AES_256_CCM_8, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA TLS_ECDHE_RSA_WITH_RC4_128_SHA, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 TLS_RSA_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 TLS_RSA_WITH_AES_256_CBC_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA TLS_ECDH_RSA_WITH_RC4_128_SHA, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA TLS_ECDH_ECDSA_WITH_RC4_128_SHA, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 TLS_RSA_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 TLS_RSA_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, #endif #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, #endif #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, #endif #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, #endif #ifdef BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, #endif #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, #endif #ifdef BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256, #endif #ifdef BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA TLS_DH_anon_WITH_AES_128_CBC_SHA, #endif #ifdef HAVE_RENEGOTIATION_INDICATION TLS_EMPTY_RENEGOTIATION_INFO_SCSV, #endif }; /* returns the cipher_names array */ const char* const* GetCipherNames(void) { return cipher_names; } /* returns the size of the cipher_names array */ int GetCipherNamesSize(void) { return (int)(sizeof(cipher_names) / sizeof(char*)); } /** Set the enabled cipher suites. @param [out] suites Suites structure. @param [in] list List of cipher suites, only supports full name from cipher_name[] delimited by ':'. @return true on success, else false. */ int SetCipherList(Suites* suites, const char* list) { int ret = 0; int idx = 0; int haveRSAsig = 0; int haveECDSAsig = 0; int haveAnon = 0; const int suiteSz = GetCipherNamesSize(); char* next = (char*)list; if (suites == NULL || list == NULL) { WOLFSSL_MSG("SetCipherList parameter error"); return 0; } if (next[0] == 0 || XSTRNCMP(next, "ALL", 3) == 0) return 1; /* wolfSSL defualt */ do { char* current = next; char name[MAX_SUITE_NAME + 1]; int i; word32 length; next = XSTRSTR(next, ":"); length = min(sizeof(name), !next ? (word32)XSTRLEN(current) /* last */ : (word32)(next - current)); XSTRNCPY(name, current, length); name[(length == sizeof(name)) ? length - 1 : length] = 0; for (i = 0; i < suiteSz; i++) { if (XSTRNCMP(name, cipher_names[i], sizeof(name)) == 0) { suites->suites[idx++] = (XSTRSTR(name, "CHACHA")) ? CHACHA_BYTE : (XSTRSTR(name, "EC")) ? ECC_BYTE : (XSTRSTR(name, "CCM")) ? ECC_BYTE : 0x00; /* normal */ suites->suites[idx++] = (byte)cipher_name_idx[i]; /* The suites are either ECDSA, RSA, PSK, or Anon. The RSA * suites don't necessarily have RSA in the name. */ if ((haveECDSAsig == 0) && XSTRSTR(name, "ECDSA")) haveECDSAsig = 1; else if (XSTRSTR(name, "ADH")) haveAnon = 1; else if ((haveRSAsig == 0) && (XSTRSTR(name, "PSK") == NULL)) haveRSAsig = 1; ret = 1; /* found at least one */ break; } } } while (next++); /* ++ needed to skip ':' */ if (ret) { suites->setSuites = 1; suites->suiteSz = (word16)idx; InitSuitesHashSigAlgo(suites, haveECDSAsig, haveRSAsig, haveAnon); } return ret; } static void PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz) { word32 i; ssl->suites->sigAlgo = ssl->specs.sig_algo; ssl->suites->hashAlgo = sha_mac; /* i+1 since peek a byte ahead for type */ for (i = 0; (i+1) < hashSigAlgoSz; i += 2) { if (hashSigAlgo[i+1] == ssl->specs.sig_algo) { if (hashSigAlgo[i] == sha_mac) { break; } #ifndef NO_SHA256 else if (hashSigAlgo[i] == sha256_mac) { ssl->suites->hashAlgo = sha256_mac; break; } #endif #ifdef WOLFSSL_SHA384 else if (hashSigAlgo[i] == sha384_mac) { ssl->suites->hashAlgo = sha384_mac; break; } #endif #ifdef WOLFSSL_SHA512 else if (hashSigAlgo[i] == sha512_mac) { ssl->suites->hashAlgo = sha512_mac; break; } #endif } } } #ifdef WOLFSSL_CALLBACKS /* Initialisze HandShakeInfo */ void InitHandShakeInfo(HandShakeInfo* info) { int i; info->cipherName[0] = 0; for (i = 0; i < MAX_PACKETS_HANDSHAKE; i++) info->packetNames[i][0] = 0; info->numberPackets = 0; info->negotiationError = 0; } /* Set Final HandShakeInfo parameters */ void FinishHandShakeInfo(HandShakeInfo* info, const WOLFSSL* ssl) { int i; int sz = sizeof(cipher_name_idx)/sizeof(int); for (i = 0; i < sz; i++) if (ssl->options.cipherSuite == (byte)cipher_name_idx[i]) { if (ssl->options.cipherSuite0 == ECC_BYTE) continue; /* ECC suites at end */ XSTRNCPY(info->cipherName, cipher_names[i], MAX_CIPHERNAME_SZ); break; } /* error max and min are negative numbers */ if (ssl->error <= MIN_PARAM_ERR && ssl->error >= MAX_PARAM_ERR) info->negotiationError = ssl->error; } /* Add name to info packet names, increase packet name count */ void AddPacketName(const char* name, HandShakeInfo* info) { if (info->numberPackets < MAX_PACKETS_HANDSHAKE) { XSTRNCPY(info->packetNames[info->numberPackets++], name, MAX_PACKETNAME_SZ); } } /* Initialisze TimeoutInfo */ void InitTimeoutInfo(TimeoutInfo* info) { int i; info->timeoutName[0] = 0; info->flags = 0; for (i = 0; i < MAX_PACKETS_HANDSHAKE; i++) { info->packets[i].packetName[0] = 0; info->packets[i].timestamp.tv_sec = 0; info->packets[i].timestamp.tv_usec = 0; info->packets[i].bufferValue = 0; info->packets[i].valueSz = 0; } info->numberPackets = 0; info->timeoutValue.tv_sec = 0; info->timeoutValue.tv_usec = 0; } /* Free TimeoutInfo */ void FreeTimeoutInfo(TimeoutInfo* info, void* heap) { int i; (void)heap; for (i = 0; i < MAX_PACKETS_HANDSHAKE; i++) if (info->packets[i].bufferValue) { XFREE(info->packets[i].bufferValue, heap, DYNAMIC_TYPE_INFO); info->packets[i].bufferValue = 0; } } /* Add PacketInfo to TimeoutInfo */ void AddPacketInfo(const char* name, TimeoutInfo* info, const byte* data, int sz, void* heap) { if (info->numberPackets < (MAX_PACKETS_HANDSHAKE - 1)) { Timeval currTime; /* may add name after */ if (name) XSTRNCPY(info->packets[info->numberPackets].packetName, name, MAX_PACKETNAME_SZ); /* add data, put in buffer if bigger than static buffer */ info->packets[info->numberPackets].valueSz = sz; if (sz < MAX_VALUE_SZ) XMEMCPY(info->packets[info->numberPackets].value, data, sz); else { info->packets[info->numberPackets].bufferValue = XMALLOC(sz, heap, DYNAMIC_TYPE_INFO); if (!info->packets[info->numberPackets].bufferValue) /* let next alloc catch, just don't fill, not fatal here */ info->packets[info->numberPackets].valueSz = 0; else XMEMCPY(info->packets[info->numberPackets].bufferValue, data, sz); } gettimeofday(&currTime, 0); info->packets[info->numberPackets].timestamp.tv_sec = currTime.tv_sec; info->packets[info->numberPackets].timestamp.tv_usec = currTime.tv_usec; info->numberPackets++; } } /* Add packet name to previsouly added packet info */ void AddLateName(const char* name, TimeoutInfo* info) { /* make sure we have a valid previous one */ if (info->numberPackets > 0 && info->numberPackets < MAX_PACKETS_HANDSHAKE) { XSTRNCPY(info->packets[info->numberPackets - 1].packetName, name, MAX_PACKETNAME_SZ); } } /* Add record header to previsouly added packet info */ void AddLateRecordHeader(const RecordLayerHeader* rl, TimeoutInfo* info) { /* make sure we have a valid previous one */ if (info->numberPackets > 0 && info->numberPackets < MAX_PACKETS_HANDSHAKE) { if (info->packets[info->numberPackets - 1].bufferValue) XMEMCPY(info->packets[info->numberPackets - 1].bufferValue, rl, RECORD_HEADER_SZ); else XMEMCPY(info->packets[info->numberPackets - 1].value, rl, RECORD_HEADER_SZ); } } #endif /* WOLFSSL_CALLBACKS */ /* client only parts */ #ifndef NO_WOLFSSL_CLIENT int SendClientHello(WOLFSSL* ssl) { byte *output; word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int sendSz; int idSz = ssl->options.resuming ? ssl->session.sessionIDSz : 0; int ret; if (ssl->suites == NULL) { WOLFSSL_MSG("Bad suites pointer in SendClientHello"); return SUITES_ERROR; } #ifdef HAVE_SESSION_TICKET if (ssl->options.resuming && ssl->session.ticketLen > 0) { SessionTicket* ticket; ticket = TLSX_SessionTicket_Create(0, ssl->session.ticket, ssl->session.ticketLen); if (ticket == NULL) return MEMORY_E; ret = TLSX_UseSessionTicket(&ssl->extensions, ticket); if (ret != SSL_SUCCESS) return ret; idSz = 0; } #endif length = VERSION_SZ + RAN_LEN + idSz + ENUM_LEN + ssl->suites->suiteSz + SUITE_LEN + COMP_LEN + ENUM_LEN; #ifdef HAVE_TLS_EXTENSIONS length += TLSX_GetRequestSize(ssl); #else if (IsAtLeastTLSv1_2(ssl) && ssl->suites->hashSigAlgoSz) { length += ssl->suites->hashSigAlgoSz + HELLO_EXT_SZ; } #endif sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { length += ENUM_LEN; /* cookie */ if (ssl->arrays->cookieSz != 0) length += ssl->arrays->cookieSz; sendSz = length + DTLS_HANDSHAKE_HEADER_SZ + DTLS_RECORD_HEADER_SZ; idx += DTLS_HANDSHAKE_EXTRA + DTLS_RECORD_EXTRA; } #endif if (ssl->keys.encryptionOn) sendSz += MAX_MSG_EXTRA; /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, client_hello, ssl); /* client hello, first version */ output[idx++] = ssl->version.major; output[idx++] = ssl->version.minor; ssl->chVersion = ssl->version; /* store in case changed */ /* then random */ if (ssl->options.connectState == CONNECT_BEGIN) { ret = wc_RNG_GenerateBlock(ssl->rng, output + idx, RAN_LEN); if (ret != 0) return ret; /* store random */ XMEMCPY(ssl->arrays->clientRandom, output + idx, RAN_LEN); } else { #ifdef WOLFSSL_DTLS /* send same random on hello again */ XMEMCPY(output + idx, ssl->arrays->clientRandom, RAN_LEN); #endif } idx += RAN_LEN; /* then session id */ output[idx++] = (byte)idSz; if (idSz) { XMEMCPY(output + idx, ssl->session.sessionID, ssl->session.sessionIDSz); idx += ssl->session.sessionIDSz; } /* then DTLS cookie */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { byte cookieSz = ssl->arrays->cookieSz; output[idx++] = cookieSz; if (cookieSz) { XMEMCPY(&output[idx], ssl->arrays->cookie, cookieSz); idx += cookieSz; } } #endif /* then cipher suites */ c16toa(ssl->suites->suiteSz, output + idx); idx += 2; XMEMCPY(output + idx, &ssl->suites->suites, ssl->suites->suiteSz); idx += ssl->suites->suiteSz; /* last, compression */ output[idx++] = COMP_LEN; if (ssl->options.usingCompression) output[idx++] = ZLIB_COMPRESSION; else output[idx++] = NO_COMPRESSION; #ifdef HAVE_TLS_EXTENSIONS idx += TLSX_WriteRequest(ssl, output + idx); (void)idx; /* suppress analyzer warning, keep idx current */ #else if (IsAtLeastTLSv1_2(ssl) && ssl->suites->hashSigAlgoSz) { int i; /* add in the extensions length */ c16toa(HELLO_EXT_LEN + ssl->suites->hashSigAlgoSz, output + idx); idx += 2; c16toa(HELLO_EXT_SIG_ALGO, output + idx); idx += 2; c16toa(HELLO_EXT_SIGALGO_SZ+ssl->suites->hashSigAlgoSz, output+idx); idx += 2; c16toa(ssl->suites->hashSigAlgoSz, output + idx); idx += 2; for (i = 0; i < ssl->suites->hashSigAlgoSz; i++, idx++) { output[idx] = ssl->suites->hashSigAlgo[i]; } } #endif if (ssl->keys.encryptionOn) { byte* input; int inputSz = idx - RECORD_HEADER_SZ; /* build msg adds rec hdr */ input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (input == NULL) return MEMORY_E; XMEMCPY(input, output + RECORD_HEADER_SZ, inputSz); sendSz = BuildMessage(ssl, output, sendSz, input,inputSz,handshake); XFREE(input, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (sendSz < 0) return sendSz; } else { ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif ssl->options.clientState = CLIENT_HELLO_COMPLETE; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ClientHello", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ClientHello", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; return SendBuffered(ssl); } static int DoHelloVerifyRequest(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 size) { ProtocolVersion pv; byte cookieSz; word32 begin = *inOutIdx; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("HelloVerifyRequest", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("HelloVerifyRequest", &ssl->timeoutInfo); #endif #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { DtlsPoolReset(ssl); } #endif if ((*inOutIdx - begin) + OPAQUE16_LEN + OPAQUE8_LEN > size) return BUFFER_ERROR; XMEMCPY(&pv, input + *inOutIdx, OPAQUE16_LEN); *inOutIdx += OPAQUE16_LEN; cookieSz = input[(*inOutIdx)++]; if (cookieSz) { if ((*inOutIdx - begin) + cookieSz > size) return BUFFER_ERROR; #ifdef WOLFSSL_DTLS if (cookieSz <= MAX_COOKIE_LEN) { XMEMCPY(ssl->arrays->cookie, input + *inOutIdx, cookieSz); ssl->arrays->cookieSz = cookieSz; } #endif *inOutIdx += cookieSz; } ssl->options.serverState = SERVER_HELLOVERIFYREQUEST_COMPLETE; return 0; } static INLINE int DSH_CheckSessionId(WOLFSSL* ssl) { int ret = 0; #ifdef HAVE_SECRET_CALLBACK /* If a session secret callback exists, we are using that * key instead of the saved session key. */ ret = ret || (ssl->sessionSecretCb != NULL); #endif #ifdef HAVE_SESSION_TICKET /* server may send blank ticket which may not be expected to indicate * exisiting one ok but will also be sending a new one */ ret = ret || (ssl->session.ticketLen > 0); #endif ret = ret || (ssl->options.haveSessionId && XMEMCMP(ssl->arrays->sessionID, ssl->session.sessionID, ID_LEN) == 0); return ret; } static int DoServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 helloSz) { byte cs0; /* cipher suite bytes 0, 1 */ byte cs1; ProtocolVersion pv; byte compression; word32 i = *inOutIdx; word32 begin = i; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerHello", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("ServerHello", &ssl->timeoutInfo); #endif /* protocol version, random and session id length check */ if (OPAQUE16_LEN + RAN_LEN + OPAQUE8_LEN > helloSz) return BUFFER_ERROR; /* protocol version */ XMEMCPY(&pv, input + i, OPAQUE16_LEN); i += OPAQUE16_LEN; if (pv.minor > ssl->version.minor) { WOLFSSL_MSG("Server using higher version, fatal error"); return VERSION_ERROR; } else if (pv.minor < ssl->version.minor) { WOLFSSL_MSG("server using lower version"); if (!ssl->options.downgrade) { WOLFSSL_MSG(" no downgrade allowed, fatal error"); return VERSION_ERROR; } if (pv.minor < ssl->options.minDowngrade) { WOLFSSL_MSG(" version below minimum allowed, fatal error"); return VERSION_ERROR; } #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation && ssl->secure_renegotiation->enabled && ssl->options.handShakeDone) { WOLFSSL_MSG("Server changed version during scr"); return VERSION_ERROR; } #endif if (pv.minor == SSLv3_MINOR) { /* turn off tls */ WOLFSSL_MSG(" downgrading to SSLv3"); ssl->options.tls = 0; ssl->options.tls1_1 = 0; ssl->version.minor = SSLv3_MINOR; } else if (pv.minor == TLSv1_MINOR) { /* turn off tls 1.1+ */ WOLFSSL_MSG(" downgrading to TLSv1"); ssl->options.tls1_1 = 0; ssl->version.minor = TLSv1_MINOR; } else if (pv.minor == TLSv1_1_MINOR) { WOLFSSL_MSG(" downgrading to TLSv1.1"); ssl->version.minor = TLSv1_1_MINOR; } } /* random */ XMEMCPY(ssl->arrays->serverRandom, input + i, RAN_LEN); i += RAN_LEN; /* session id */ ssl->arrays->sessionIDSz = input[i++]; if (ssl->arrays->sessionIDSz > ID_LEN) { WOLFSSL_MSG("Invalid session ID size"); ssl->arrays->sessionIDSz = 0; return BUFFER_ERROR; } else if (ssl->arrays->sessionIDSz) { if ((i - begin) + ssl->arrays->sessionIDSz > helloSz) return BUFFER_ERROR; XMEMCPY(ssl->arrays->sessionID, input + i, ssl->arrays->sessionIDSz); i += ssl->arrays->sessionIDSz; ssl->options.haveSessionId = 1; } /* suite and compression */ if ((i - begin) + OPAQUE16_LEN + OPAQUE8_LEN > helloSz) return BUFFER_ERROR; cs0 = input[i++]; cs1 = input[i++]; #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation && ssl->secure_renegotiation->enabled && ssl->options.handShakeDone) { if (ssl->options.cipherSuite0 != cs0 || ssl->options.cipherSuite != cs1) { WOLFSSL_MSG("Server changed cipher suite during scr"); return MATCH_SUITE_ERROR; } } #endif ssl->options.cipherSuite0 = cs0; ssl->options.cipherSuite = cs1; compression = input[i++]; if (compression != ZLIB_COMPRESSION && ssl->options.usingCompression) { WOLFSSL_MSG("Server refused compression, turning off"); ssl->options.usingCompression = 0; /* turn off if server refused */ } *inOutIdx = i; /* tls extensions */ if ( (i - begin) < helloSz) { #ifdef HAVE_TLS_EXTENSIONS if (TLSX_SupportExtensions(ssl)) { int ret = 0; word16 totalExtSz; if ((i - begin) + OPAQUE16_LEN > helloSz) return BUFFER_ERROR; ato16(&input[i], &totalExtSz); i += OPAQUE16_LEN; if ((i - begin) + totalExtSz > helloSz) return BUFFER_ERROR; if ((ret = TLSX_Parse(ssl, (byte *) input + i, totalExtSz, 0, NULL))) return ret; i += totalExtSz; *inOutIdx = i; } else #endif *inOutIdx = begin + helloSz; /* skip extensions */ } ssl->options.serverState = SERVER_HELLO_COMPLETE; if (ssl->keys.encryptionOn) { *inOutIdx += ssl->keys.padSz; } #ifdef HAVE_SECRET_CALLBACK if (ssl->sessionSecretCb != NULL) { int secretSz = SECRET_LEN, ret; ret = ssl->sessionSecretCb(ssl, ssl->session.masterSecret, &secretSz, ssl->sessionSecretCtx); if (ret != 0 || secretSz != SECRET_LEN) return SESSION_SECRET_CB_E; } #endif /* HAVE_SECRET_CALLBACK */ if (ssl->options.resuming) { if (DSH_CheckSessionId(ssl)) { if (SetCipherSpecs(ssl) == 0) { int ret = -1; XMEMCPY(ssl->arrays->masterSecret, ssl->session.masterSecret, SECRET_LEN); #ifdef NO_OLD_TLS ret = DeriveTlsKeys(ssl); #else #ifndef NO_TLS if (ssl->options.tls) ret = DeriveTlsKeys(ssl); #endif if (!ssl->options.tls) ret = DeriveKeys(ssl); #endif ssl->options.serverState = SERVER_HELLODONE_COMPLETE; return ret; } else { WOLFSSL_MSG("Unsupported cipher suite, DoServerHello"); return UNSUPPORTED_SUITE; } } else { WOLFSSL_MSG("Server denied resumption attempt"); ssl->options.resuming = 0; /* server denied resumption try */ } } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { DtlsPoolReset(ssl); } #endif return SetCipherSpecs(ssl); } /* Make sure client setup is valid for this suite, true on success */ int VerifyClientSuite(WOLFSSL* ssl) { int havePSK = 0; byte first = ssl->options.cipherSuite0; byte second = ssl->options.cipherSuite; WOLFSSL_ENTER("VerifyClientSuite"); #ifndef NO_PSK havePSK = ssl->options.havePSK; #endif if (CipherRequires(first, second, REQUIRES_PSK)) { WOLFSSL_MSG("Requires PSK"); if (havePSK == 0) { WOLFSSL_MSG("Don't have PSK"); return 0; } } return 1; /* success */ } #ifndef NO_CERTS /* just read in and ignore for now TODO: */ static int DoCertificateRequest(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 size) { word16 len; word32 begin = *inOutIdx; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("CertificateRequest", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("CertificateRequest", &ssl->timeoutInfo); #endif if ((*inOutIdx - begin) + OPAQUE8_LEN > size) return BUFFER_ERROR; len = input[(*inOutIdx)++]; if ((*inOutIdx - begin) + len > size) return BUFFER_ERROR; /* types, read in here */ *inOutIdx += len; /* signature and hash signature algorithm */ if (IsAtLeastTLSv1_2(ssl)) { if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &len); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + len > size) return BUFFER_ERROR; PickHashSigAlgo(ssl, input + *inOutIdx, len); *inOutIdx += len; } /* authorities */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &len); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + len > size) return BUFFER_ERROR; while (len) { word16 dnSz; if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &dnSz); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + dnSz > size) return BUFFER_ERROR; *inOutIdx += dnSz; len -= OPAQUE16_LEN + dnSz; } /* don't send client cert or cert verify if user hasn't provided cert and private key */ if (ssl->buffers.certificate.buffer && ssl->buffers.key.buffer) ssl->options.sendVerify = SEND_CERT; else if (IsTLS(ssl)) ssl->options.sendVerify = SEND_BLANK_CERT; if (ssl->keys.encryptionOn) *inOutIdx += ssl->keys.padSz; return 0; } #endif /* !NO_CERTS */ #ifdef HAVE_ECC static int CheckCurveId(int oid) { int ret = 0; switch (oid) { #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC160) case WOLFSSL_ECC_SECP160R1: #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC192) case WOLFSSL_ECC_SECP192R1: #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC224) case WOLFSSL_ECC_SECP224R1: #endif #if defined(HAVE_ALL_CURVES) || !defined(NO_ECC256) case WOLFSSL_ECC_SECP256R1: #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC384) case WOLFSSL_ECC_SECP384R1: #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC521) case WOLFSSL_ECC_SECP521R1: #endif break; default: ret = -1; } return ret; } #endif /* HAVE_ECC */ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 size) { word16 length = 0; word32 begin = *inOutIdx; int ret = 0; #define ERROR_OUT(err, eLabel) do { ret = err; goto eLabel; } while(0) (void)length; /* shut up compiler warnings */ (void)begin; (void)ssl; (void)input; (void)size; (void)ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("ServerKeyExchange", &ssl->timeoutInfo); #endif #ifndef NO_PSK if (ssl->specs.kea == psk_kea) { if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; XMEMCPY(ssl->arrays->server_hint, input + *inOutIdx, min(length, MAX_PSK_ID_LEN)); ssl->arrays->server_hint[min(length, MAX_PSK_ID_LEN - 1)] = 0; *inOutIdx += length; return 0; } #endif #ifndef NO_DH if (ssl->specs.kea == diffie_hellman_kea) { /* p */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; if (length < ssl->options.minDhKeySz) { WOLFSSL_MSG("Server using a DH key that is too small"); SendAlert(ssl, alert_fatal, handshake_failure); return DH_KEY_SIZE_E; } ssl->buffers.serverDH_P.buffer = (byte*) XMALLOC(length, ssl->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_P.buffer) ssl->buffers.serverDH_P.length = length; else return MEMORY_ERROR; XMEMCPY(ssl->buffers.serverDH_P.buffer, input + *inOutIdx, length); *inOutIdx += length; ssl->options.dhKeySz = length; /* g */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; ssl->buffers.serverDH_G.buffer = (byte*) XMALLOC(length, ssl->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_G.buffer) ssl->buffers.serverDH_G.length = length; else return MEMORY_ERROR; XMEMCPY(ssl->buffers.serverDH_G.buffer, input + *inOutIdx, length); *inOutIdx += length; /* pub */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; ssl->buffers.serverDH_Pub.buffer = (byte*) XMALLOC(length, ssl->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_Pub.buffer) ssl->buffers.serverDH_Pub.length = length; else return MEMORY_ERROR; XMEMCPY(ssl->buffers.serverDH_Pub.buffer, input + *inOutIdx, length); *inOutIdx += length; } /* dh_kea */ #endif /* NO_DH */ #ifdef HAVE_ECC if (ssl->specs.kea == ecc_diffie_hellman_kea) { byte b; if ((*inOutIdx - begin) + ENUM_LEN + OPAQUE16_LEN + OPAQUE8_LEN > size) return BUFFER_ERROR; b = input[(*inOutIdx)++]; if (b != named_curve) return ECC_CURVETYPE_ERROR; *inOutIdx += 1; /* curve type, eat leading 0 */ b = input[(*inOutIdx)++]; if (CheckCurveId(b) != 0) { return ECC_CURVE_ERROR; } length = input[(*inOutIdx)++]; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; if (ssl->peerEccKey == NULL) { /* alloc/init on demand */ ssl->peerEccKey = (ecc_key*)XMALLOC(sizeof(ecc_key), ssl->ctx->heap, DYNAMIC_TYPE_ECC); if (ssl->peerEccKey == NULL) { WOLFSSL_MSG("PeerEccKey Memory error"); return MEMORY_E; } wc_ecc_init(ssl->peerEccKey); } else if (ssl->peerEccKeyPresent) { /* don't leak on reuse */ wc_ecc_free(ssl->peerEccKey); ssl->peerEccKeyPresent = 0; wc_ecc_init(ssl->peerEccKey); } if (wc_ecc_import_x963(input + *inOutIdx, length, ssl->peerEccKey) != 0) return ECC_PEERKEY_ERROR; *inOutIdx += length; ssl->peerEccKeyPresent = 1; } #endif /* HAVE_ECC */ #if !defined(NO_DH) && !defined(NO_PSK) if (ssl->specs.kea == dhe_psk_kea) { if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; XMEMCPY(ssl->arrays->server_hint, input + *inOutIdx, min(length, MAX_PSK_ID_LEN)); ssl->arrays->server_hint[min(length, MAX_PSK_ID_LEN - 1)] = 0; *inOutIdx += length; /* p */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; if (length < ssl->options.minDhKeySz) { WOLFSSL_MSG("Server using a DH key that is too small"); SendAlert(ssl, alert_fatal, handshake_failure); return DH_KEY_SIZE_E; } ssl->buffers.serverDH_P.buffer = (byte*) XMALLOC(length, ssl->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_P.buffer) ssl->buffers.serverDH_P.length = length; else return MEMORY_ERROR; XMEMCPY(ssl->buffers.serverDH_P.buffer, input + *inOutIdx, length); *inOutIdx += length; ssl->options.dhKeySz = length; /* g */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; ssl->buffers.serverDH_G.buffer = (byte*) XMALLOC(length, ssl->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_G.buffer) ssl->buffers.serverDH_G.length = length; else return MEMORY_ERROR; XMEMCPY(ssl->buffers.serverDH_G.buffer, input + *inOutIdx, length); *inOutIdx += length; /* pub */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; ssl->buffers.serverDH_Pub.buffer = (byte*) XMALLOC(length, ssl->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_Pub.buffer) ssl->buffers.serverDH_Pub.length = length; else return MEMORY_ERROR; XMEMCPY(ssl->buffers.serverDH_Pub.buffer, input + *inOutIdx, length); *inOutIdx += length; } #endif /* !NO_DH || !NO_PSK */ #if !defined(NO_DH) || defined(HAVE_ECC) if (!ssl->options.usingAnon_cipher && (ssl->specs.kea == ecc_diffie_hellman_kea || ssl->specs.kea == diffie_hellman_kea)) { #ifndef NO_OLD_TLS #ifdef WOLFSSL_SMALL_STACK Md5* md5 = NULL; Sha* sha = NULL; #else Md5 md5[1]; Sha sha[1]; #endif #endif #ifndef NO_SHA256 #ifdef WOLFSSL_SMALL_STACK Sha256* sha256 = NULL; byte* hash256 = NULL; #else Sha256 sha256[1]; byte hash256[SHA256_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SMALL_STACK Sha384* sha384 = NULL; byte* hash384 = NULL; #else Sha384 sha384[1]; byte hash384[SHA384_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SMALL_STACK Sha512* sha512 = NULL; byte* hash512 = NULL; #else Sha512 sha512[1]; byte hash512[SHA512_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SMALL_STACK byte* hash = NULL; byte* messageVerify = NULL; #else byte hash[FINISHED_SZ]; byte messageVerify[MAX_DH_SZ]; #endif byte hashAlgo = sha_mac; byte sigAlgo = ssl->specs.sig_algo; word16 verifySz = (word16) (*inOutIdx - begin); #ifndef NO_OLD_TLS byte doMd5 = 0; byte doSha = 0; #endif #ifndef NO_SHA256 byte doSha256 = 0; #endif #ifdef WOLFSSL_SHA384 byte doSha384 = 0; #endif #ifdef WOLFSSL_SHA512 byte doSha512 = 0; #endif (void)hash; (void)sigAlgo; (void)hashAlgo; /* save message for hash verify */ if (verifySz > MAX_DH_SZ) ERROR_OUT(BUFFER_ERROR, done); #ifdef WOLFSSL_SMALL_STACK messageVerify = (byte*)XMALLOC(MAX_DH_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (messageVerify == NULL) ERROR_OUT(MEMORY_E, done); #endif XMEMCPY(messageVerify, input + begin, verifySz); if (IsAtLeastTLSv1_2(ssl)) { byte setHash = 0; if ((*inOutIdx - begin) + ENUM_LEN + ENUM_LEN > size) ERROR_OUT(BUFFER_ERROR, done); hashAlgo = input[(*inOutIdx)++]; sigAlgo = input[(*inOutIdx)++]; switch (hashAlgo) { case sha512_mac: #ifdef WOLFSSL_SHA512 doSha512 = 1; setHash = 1; #endif break; case sha384_mac: #ifdef WOLFSSL_SHA384 doSha384 = 1; setHash = 1; #endif break; case sha256_mac: #ifndef NO_SHA256 doSha256 = 1; setHash = 1; #endif break; case sha_mac: #ifndef NO_OLD_TLS doSha = 1; setHash = 1; #endif break; default: ERROR_OUT(ALGO_ID_E, done); } if (setHash == 0) { ERROR_OUT(ALGO_ID_E, done); } } else { /* only using sha and md5 for rsa */ #ifndef NO_OLD_TLS doSha = 1; if (sigAlgo == rsa_sa_algo) { doMd5 = 1; } #else ERROR_OUT(ALGO_ID_E, done); #endif } /* signature */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) ERROR_OUT(BUFFER_ERROR, done); ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + length > size) ERROR_OUT(BUFFER_ERROR, done); /* inOutIdx updated at the end of the function */ /* verify signature */ #ifdef WOLFSSL_SMALL_STACK hash = (byte*)XMALLOC(FINISHED_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash == NULL) ERROR_OUT(MEMORY_E, done); #endif #ifndef NO_OLD_TLS /* md5 */ #ifdef WOLFSSL_SMALL_STACK if (doMd5) { md5 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (md5 == NULL) ERROR_OUT(MEMORY_E, done); } #endif if (doMd5) { wc_InitMd5(md5); wc_Md5Update(md5, ssl->arrays->clientRandom, RAN_LEN); wc_Md5Update(md5, ssl->arrays->serverRandom, RAN_LEN); wc_Md5Update(md5, messageVerify, verifySz); wc_Md5Final(md5, hash); } /* sha */ #ifdef WOLFSSL_SMALL_STACK if (doSha) { sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha == NULL) ERROR_OUT(MEMORY_E, done); } #endif if (doSha) { ret = wc_InitSha(sha); if (ret != 0) goto done; wc_ShaUpdate(sha, ssl->arrays->clientRandom, RAN_LEN); wc_ShaUpdate(sha, ssl->arrays->serverRandom, RAN_LEN); wc_ShaUpdate(sha, messageVerify, verifySz); wc_ShaFinal(sha, hash + MD5_DIGEST_SIZE); } #endif #ifndef NO_SHA256 #ifdef WOLFSSL_SMALL_STACK if (doSha256) { sha256 = (Sha256*)XMALLOC(sizeof(Sha256), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash256 = (byte*)XMALLOC(SHA256_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha256 == NULL || hash256 == NULL) ERROR_OUT(MEMORY_E, done); } #endif if (doSha256) { if (!(ret = wc_InitSha256(sha256)) && !(ret = wc_Sha256Update(sha256, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha256Update(sha256, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha256Update(sha256, messageVerify, verifySz))) ret = wc_Sha256Final(sha256, hash256); if (ret != 0) goto done; } #endif #ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SMALL_STACK if (doSha384) { sha384 = (Sha384*)XMALLOC(sizeof(Sha384), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash384 = (byte*)XMALLOC(SHA384_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha384 == NULL || hash384 == NULL) ERROR_OUT(MEMORY_E, done); } #endif if (doSha384) { if (!(ret = wc_InitSha384(sha384)) && !(ret = wc_Sha384Update(sha384, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha384Update(sha384, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha384Update(sha384, messageVerify, verifySz))) ret = wc_Sha384Final(sha384, hash384); if (ret != 0) goto done; } #endif #ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SMALL_STACK if (doSha512) { sha512 = (Sha512*)XMALLOC(sizeof(Sha512), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash512 = (byte*)XMALLOC(SHA512_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha512 == NULL || hash512 == NULL) ERROR_OUT(MEMORY_E, done); } #endif if (doSha512) { if (!(ret = wc_InitSha512(sha512)) && !(ret = wc_Sha512Update(sha512, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha512Update(sha512, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha512Update(sha512, messageVerify, verifySz))) ret = wc_Sha512Final(sha512, hash512); if (ret != 0) goto done; } #endif #ifndef NO_RSA /* rsa */ if (sigAlgo == rsa_sa_algo) { byte* out = NULL; byte doUserRsa = 0; word32 verifiedSz = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->RsaVerifyCb) doUserRsa = 1; #endif /*HAVE_PK_CALLBACKS */ if (ssl->peerRsaKey == NULL || !ssl->peerRsaKeyPresent) ERROR_OUT(NO_PEER_KEY, done); if (doUserRsa) { #ifdef HAVE_PK_CALLBACKS verifiedSz = ssl->ctx->RsaVerifyCb(ssl, (byte *)input + *inOutIdx, length, &out, ssl->buffers.peerRsaKey.buffer, ssl->buffers.peerRsaKey.length, ssl->RsaVerifyCtx); #endif /*HAVE_PK_CALLBACKS */ } else verifiedSz = wc_RsaSSL_VerifyInline((byte *)input + *inOutIdx, length, &out, ssl->peerRsaKey); if (IsAtLeastTLSv1_2(ssl)) { word32 encSigSz; #ifndef NO_OLD_TLS byte* digest = &hash[MD5_DIGEST_SIZE]; int typeH = SHAh; int digestSz = SHA_DIGEST_SIZE; #else byte* digest = hash256; int typeH = SHA256h; int digestSz = SHA256_DIGEST_SIZE; #endif #ifdef WOLFSSL_SMALL_STACK byte* encodedSig = NULL; #else byte encodedSig[MAX_ENCODED_SIG_SZ]; #endif if (hashAlgo == sha_mac) { #ifndef NO_SHA digest = &hash[MD5_DIGEST_SIZE]; typeH = SHAh; digestSz = SHA_DIGEST_SIZE; #endif } else if (hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = hash256; typeH = SHA256h; digestSz = SHA256_DIGEST_SIZE; #endif } else if (hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = hash384; typeH = SHA384h; digestSz = SHA384_DIGEST_SIZE; #endif } else if (hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = hash512; typeH = SHA512h; digestSz = SHA512_DIGEST_SIZE; #endif } #ifdef WOLFSSL_SMALL_STACK encodedSig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encodedSig == NULL) ERROR_OUT(MEMORY_E, done); #endif if (digest == NULL) ERROR_OUT(ALGO_ID_E, done); encSigSz = wc_EncodeSignature(encodedSig, digest, digestSz, typeH); if (encSigSz != verifiedSz || !out || XMEMCMP(out, encodedSig, min(encSigSz, MAX_ENCODED_SIG_SZ)) != 0) ret = VERIFY_SIGN_ERROR; #ifdef WOLFSSL_SMALL_STACK XFREE(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret != 0) goto done; } else if (verifiedSz != FINISHED_SZ || !out || XMEMCMP(out, hash, FINISHED_SZ) != 0) ERROR_OUT(VERIFY_SIGN_ERROR, done); } else #endif #ifdef HAVE_ECC /* ecdsa */ if (sigAlgo == ecc_dsa_sa_algo) { int verify = 0; #ifndef NO_OLD_TLS byte* digest = &hash[MD5_DIGEST_SIZE]; word32 digestSz = SHA_DIGEST_SIZE; #else byte* digest = hash256; word32 digestSz = SHA256_DIGEST_SIZE; #endif byte doUserEcc = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->EccVerifyCb) doUserEcc = 1; #endif if (!ssl->peerEccDsaKeyPresent) ERROR_OUT(NO_PEER_KEY, done); if (IsAtLeastTLSv1_2(ssl)) { if (hashAlgo == sha_mac) { #ifndef NO_SHA digest = &hash[MD5_DIGEST_SIZE]; digestSz = SHA_DIGEST_SIZE; #endif } else if (hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = hash256; digestSz = SHA256_DIGEST_SIZE; #endif } else if (hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = hash384; digestSz = SHA384_DIGEST_SIZE; #endif } else if (hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = hash512; digestSz = SHA512_DIGEST_SIZE; #endif } } if (doUserEcc) { #ifdef HAVE_PK_CALLBACKS ret = ssl->ctx->EccVerifyCb(ssl, input + *inOutIdx, length, digest, digestSz, ssl->buffers.peerEccDsaKey.buffer, ssl->buffers.peerEccDsaKey.length, &verify, ssl->EccVerifyCtx); #endif } else { ret = wc_ecc_verify_hash(input + *inOutIdx, length, digest, digestSz, &verify, ssl->peerEccDsaKey); } if (ret != 0 || verify == 0) ERROR_OUT(VERIFY_SIGN_ERROR, done); } else #endif /* HAVE_ECC */ ERROR_OUT(ALGO_ID_E, done); /* signature length */ *inOutIdx += length; ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; done: #ifdef WOLFSSL_SMALL_STACK #ifndef NO_OLD_TLS XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifndef NO_SHA256 XFREE(sha256, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash256, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifdef WOLFSSL_SHA384 XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash384, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifdef WOLFSSL_SHA512 XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash512, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif XFREE(hash, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(messageVerify, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret != 0) return ret; } if (ssl->keys.encryptionOn) { *inOutIdx += ssl->keys.padSz; } return 0; #else /* !NO_DH or HAVE_ECC */ return NOT_COMPILED_IN; /* not supported by build */ #endif /* !NO_DH or HAVE_ECC */ #undef ERROR_OUT } int SendClientKeyExchange(WOLFSSL* ssl) { #ifdef WOLFSSL_SMALL_STACK byte* encSecret = NULL; #else byte encSecret[MAX_ENCRYPT_SZ]; #endif word32 encSz = 0; word32 idx = 0; int ret = 0; byte doUserRsa = 0; (void)doUserRsa; #ifdef HAVE_PK_CALLBACKS #ifndef NO_RSA if (ssl->ctx->RsaEncCb) doUserRsa = 1; #endif /* NO_RSA */ #endif /*HAVE_PK_CALLBACKS */ #ifdef WOLFSSL_SMALL_STACK encSecret = (byte*)XMALLOC(MAX_ENCRYPT_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encSecret == NULL) return MEMORY_E; #endif switch (ssl->specs.kea) { #ifndef NO_RSA case rsa_kea: ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, SECRET_LEN); if (ret != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } ssl->arrays->preMasterSecret[0] = ssl->chVersion.major; ssl->arrays->preMasterSecret[1] = ssl->chVersion.minor; ssl->arrays->preMasterSz = SECRET_LEN; if (ssl->peerRsaKey == NULL || ssl->peerRsaKeyPresent == 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } if (doUserRsa) { #ifdef HAVE_PK_CALLBACKS #ifndef NO_RSA encSz = MAX_ENCRYPT_SZ; ret = ssl->ctx->RsaEncCb(ssl, ssl->arrays->preMasterSecret, SECRET_LEN, encSecret, &encSz, ssl->buffers.peerRsaKey.buffer, ssl->buffers.peerRsaKey.length, ssl->RsaEncCtx); #endif /* NO_RSA */ #endif /*HAVE_PK_CALLBACKS */ } else { ret = wc_RsaPublicEncrypt(ssl->arrays->preMasterSecret, SECRET_LEN, encSecret, MAX_ENCRYPT_SZ, ssl->peerRsaKey, ssl->rng); if (ret > 0) { encSz = ret; ret = 0; /* set success to 0 */ } } break; #endif #ifndef NO_DH case diffie_hellman_kea: { buffer serverP = ssl->buffers.serverDH_P; buffer serverG = ssl->buffers.serverDH_G; buffer serverPub = ssl->buffers.serverDH_Pub; #ifdef WOLFSSL_SMALL_STACK byte* priv = NULL; #else byte priv[ENCRYPT_LEN]; #endif word32 privSz = 0; DhKey key; if (serverP.buffer == 0 || serverG.buffer == 0 || serverPub.buffer == 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } #ifdef WOLFSSL_SMALL_STACK priv = (byte*)XMALLOC(ENCRYPT_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (priv == NULL) { XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } #endif wc_InitDhKey(&key); ret = wc_DhSetKey(&key, serverP.buffer, serverP.length, serverG.buffer, serverG.length); if (ret == 0) /* for DH, encSecret is Yc, agree is pre-master */ ret = wc_DhGenerateKeyPair(&key, ssl->rng, priv, &privSz, encSecret, &encSz); if (ret == 0) ret = wc_DhAgree(&key, ssl->arrays->preMasterSecret, &ssl->arrays->preMasterSz, priv, privSz, serverPub.buffer, serverPub.length); #ifdef WOLFSSL_SMALL_STACK XFREE(priv, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif wc_FreeDhKey(&key); } break; #endif /* NO_DH */ #ifndef NO_PSK case psk_kea: { byte* pms = ssl->arrays->preMasterSecret; ssl->arrays->psk_keySz = ssl->options.client_psk_cb(ssl, ssl->arrays->server_hint, ssl->arrays->client_identity, MAX_PSK_ID_LEN, ssl->arrays->psk_key, MAX_PSK_KEY_LEN); if (ssl->arrays->psk_keySz == 0 || ssl->arrays->psk_keySz > MAX_PSK_KEY_LEN) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return PSK_KEY_ERROR; } encSz = (word32)XSTRLEN(ssl->arrays->client_identity); if (encSz > MAX_PSK_ID_LEN) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return CLIENT_ID_ERROR; } XMEMCPY(encSecret, ssl->arrays->client_identity, encSz); /* make psk pre master secret */ /* length of key + length 0s + length of key + key */ c16toa((word16)ssl->arrays->psk_keySz, pms); pms += 2; XMEMSET(pms, 0, ssl->arrays->psk_keySz); pms += ssl->arrays->psk_keySz; c16toa((word16)ssl->arrays->psk_keySz, pms); pms += 2; XMEMCPY(pms, ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->preMasterSz = ssl->arrays->psk_keySz * 2 + 4; ForceZero(ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->psk_keySz = 0; /* No further need */ } break; #endif /* NO_PSK */ #if !defined(NO_DH) && !defined(NO_PSK) case dhe_psk_kea: { byte* pms = ssl->arrays->preMasterSecret; byte* es = encSecret; buffer serverP = ssl->buffers.serverDH_P; buffer serverG = ssl->buffers.serverDH_G; buffer serverPub = ssl->buffers.serverDH_Pub; #ifdef WOLFSSL_SMALL_STACK byte* priv = NULL; #else byte priv[ENCRYPT_LEN]; #endif word32 privSz = 0; word32 pubSz = 0; word32 esSz = 0; DhKey key; if (serverP.buffer == 0 || serverG.buffer == 0 || serverPub.buffer == 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } ssl->arrays->psk_keySz = ssl->options.client_psk_cb(ssl, ssl->arrays->server_hint, ssl->arrays->client_identity, MAX_PSK_ID_LEN, ssl->arrays->psk_key, MAX_PSK_KEY_LEN); if (ssl->arrays->psk_keySz == 0 || ssl->arrays->psk_keySz > MAX_PSK_KEY_LEN) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return PSK_KEY_ERROR; } esSz = (word32)XSTRLEN(ssl->arrays->client_identity); if (esSz > MAX_PSK_ID_LEN) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return CLIENT_ID_ERROR; } #ifdef WOLFSSL_SMALL_STACK priv = (byte*)XMALLOC(ENCRYPT_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (priv == NULL) { XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } #endif c16toa((word16)esSz, es); es += OPAQUE16_LEN; XMEMCPY(es, ssl->arrays->client_identity, esSz); es += esSz; encSz = esSz + OPAQUE16_LEN; wc_InitDhKey(&key); ret = wc_DhSetKey(&key, serverP.buffer, serverP.length, serverG.buffer, serverG.length); if (ret == 0) /* for DH, encSecret is Yc, agree is pre-master */ ret = wc_DhGenerateKeyPair(&key, ssl->rng, priv, &privSz, es + OPAQUE16_LEN, &pubSz); if (ret == 0) ret = wc_DhAgree(&key, pms + OPAQUE16_LEN, &ssl->arrays->preMasterSz, priv, privSz, serverPub.buffer, serverPub.length); wc_FreeDhKey(&key); #ifdef WOLFSSL_SMALL_STACK XFREE(priv, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } c16toa((word16)pubSz, es); encSz += pubSz + OPAQUE16_LEN; c16toa((word16)ssl->arrays->preMasterSz, pms); ssl->arrays->preMasterSz += OPAQUE16_LEN; pms += ssl->arrays->preMasterSz; /* make psk pre master secret */ /* length of key + length 0s + length of key + key */ c16toa((word16)ssl->arrays->psk_keySz, pms); pms += OPAQUE16_LEN; XMEMCPY(pms, ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->preMasterSz += ssl->arrays->psk_keySz + OPAQUE16_LEN; ForceZero(ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->psk_keySz = 0; /* No further need */ } break; #endif /* !NO_DH && !NO_PSK */ #ifdef HAVE_NTRU case ntru_kea: { word32 rc; word16 cipherLen = MAX_ENCRYPT_SZ; DRBG_HANDLE drbg; static uint8_t const wolfsslStr[] = { 'C', 'y', 'a', 'S', 'S', 'L', ' ', 'N', 'T', 'R', 'U' }; ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, SECRET_LEN); if (ret != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } ssl->arrays->preMasterSz = SECRET_LEN; if (ssl->peerNtruKeyPresent == 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } rc = ntru_crypto_drbg_instantiate(MAX_NTRU_BITS, wolfsslStr, sizeof(wolfsslStr), GetEntropy, &drbg); if (rc != DRBG_OK) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NTRU_DRBG_ERROR; } rc = ntru_crypto_ntru_encrypt(drbg, ssl->peerNtruKeyLen, ssl->peerNtruKey, ssl->arrays->preMasterSz, ssl->arrays->preMasterSecret, &cipherLen, encSecret); ntru_crypto_drbg_uninstantiate(drbg); if (rc != NTRU_OK) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NTRU_ENCRYPT_ERROR; } encSz = cipherLen; ret = 0; } break; #endif /* HAVE_NTRU */ #ifdef HAVE_ECC case ecc_diffie_hellman_kea: { ecc_key myKey; ecc_key* peerKey = NULL; word32 size = MAX_ENCRYPT_SZ; if (ssl->specs.static_ecdh) { /* TODO: EccDsa is really fixed Ecc change naming */ if (!ssl->peerEccDsaKey || !ssl->peerEccDsaKeyPresent || !ssl->peerEccDsaKey->dp) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } peerKey = ssl->peerEccDsaKey; } else { if (!ssl->peerEccKey || !ssl->peerEccKeyPresent || !ssl->peerEccKey->dp) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } peerKey = ssl->peerEccKey; } if (peerKey == NULL) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return NO_PEER_KEY; } wc_ecc_init(&myKey); ret = wc_ecc_make_key(ssl->rng, peerKey->dp->size, &myKey); if (ret != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ECC_MAKEKEY_ERROR; } /* precede export with 1 byte length */ ret = wc_ecc_export_x963(&myKey, encSecret + 1, &size); encSecret[0] = (byte)size; encSz = size + 1; if (ret != 0) ret = ECC_EXPORT_ERROR; else { size = sizeof(ssl->arrays->preMasterSecret); ret = wc_ecc_shared_secret(&myKey, peerKey, ssl->arrays->preMasterSecret, &size); if (ret != 0) ret = ECC_SHARED_ERROR; } ssl->arrays->preMasterSz = size; wc_ecc_free(&myKey); } break; #endif /* HAVE_ECC */ default: #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ALGO_ID_E; /* unsupported kea */ } if (ret == 0) { byte *output; int sendSz; word32 tlsSz = 0; if (ssl->options.tls || ssl->specs.kea == diffie_hellman_kea) tlsSz = 2; if (ssl->specs.kea == ecc_diffie_hellman_kea || ssl->specs.kea == dhe_psk_kea) /* always off */ tlsSz = 0; sendSz = encSz + tlsSz + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; idx = HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_HANDSHAKE_EXTRA + DTLS_RECORD_EXTRA; idx += DTLS_HANDSHAKE_EXTRA + DTLS_RECORD_EXTRA; } #endif if (ssl->keys.encryptionOn) sendSz += MAX_MSG_EXTRA; /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, encSz + tlsSz, client_key_exchange, ssl); if (tlsSz) { c16toa((word16)encSz, &output[idx]); idx += 2; } XMEMCPY(output + idx, encSecret, encSz); idx += encSz; if (ssl->keys.encryptionOn) { byte* input; int inputSz = idx-RECORD_HEADER_SZ; /* buildmsg adds rechdr */ input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (input == NULL) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return MEMORY_E; } XMEMCPY(input, output + RECORD_HEADER_SZ, inputSz); sendSz = BuildMessage(ssl, output, sendSz, input, inputSz, handshake); XFREE(input, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (sendSz < 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return sendSz; } } else { ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } } #endif #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ClientKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ClientKeyExchange", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) ret = 0; else ret = SendBuffered(ssl); } #ifdef WOLFSSL_SMALL_STACK XFREE(encSecret, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret == 0 || ret == WANT_WRITE) { int tmpRet = MakeMasterSecret(ssl); if (tmpRet != 0) ret = tmpRet; /* save WANT_WRITE unless more serious */ ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; } /* No further need for PMS */ ForceZero(ssl->arrays->preMasterSecret, ssl->arrays->preMasterSz); ssl->arrays->preMasterSz = 0; return ret; } #ifndef NO_CERTS int SendCertificateVerify(WOLFSSL* ssl) { byte *output; int sendSz = MAX_CERT_VERIFY_SZ, length, ret; word32 idx = 0; word32 sigOutSz = 0; #ifndef NO_RSA RsaKey key; int initRsaKey = 0; #endif int usingEcc = 0; #ifdef HAVE_ECC ecc_key eccKey; #endif (void)idx; if (ssl->options.sendVerify == SEND_BLANK_CERT) return 0; /* sent blank cert, can't verify */ if (ssl->keys.encryptionOn) sendSz += MAX_MSG_EXTRA; /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; ret = BuildCertHashes(ssl, &ssl->hsHashes->certHashes); if (ret != 0) return ret; #ifdef HAVE_ECC wc_ecc_init(&eccKey); #endif #ifndef NO_RSA ret = wc_InitRsaKey(&key, ssl->heap); if (ret == 0) initRsaKey = 1; if (ret == 0) ret = wc_RsaPrivateKeyDecode(ssl->buffers.key.buffer, &idx, &key, ssl->buffers.key.length); if (ret == 0) sigOutSz = wc_RsaEncryptSize(&key); else #endif { #ifdef HAVE_ECC WOLFSSL_MSG("Trying ECC client cert, RSA didn't work"); idx = 0; ret = wc_EccPrivateKeyDecode(ssl->buffers.key.buffer, &idx, &eccKey, ssl->buffers.key.length); if (ret == 0) { WOLFSSL_MSG("Using ECC client cert"); usingEcc = 1; sigOutSz = MAX_ENCODED_SIG_SZ; } else { WOLFSSL_MSG("Bad client cert type"); } #endif } if (ret == 0) { byte* verify = (byte*)&output[RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ]; #ifndef NO_OLD_TLS byte* signBuffer = ssl->hsHashes->certHashes.md5; #else byte* signBuffer = NULL; #endif word32 signSz = FINISHED_SZ; word32 extraSz = 0; /* tls 1.2 hash/sig */ #ifdef WOLFSSL_SMALL_STACK byte* encodedSig = NULL; #else byte encodedSig[MAX_ENCODED_SIG_SZ]; #endif #ifdef WOLFSSL_SMALL_STACK encodedSig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encodedSig == NULL) { #ifndef NO_RSA if (initRsaKey) wc_FreeRsaKey(&key); #endif #ifdef HAVE_ECC wc_ecc_free(&eccKey); #endif return MEMORY_E; } #endif (void)encodedSig; (void)signSz; (void)signBuffer; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) verify += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; #endif length = sigOutSz; if (IsAtLeastTLSv1_2(ssl)) { verify[0] = ssl->suites->hashAlgo; verify[1] = usingEcc ? ecc_dsa_sa_algo : rsa_sa_algo; extraSz = HASH_SIG_SIZE; } if (usingEcc) { #ifdef HAVE_ECC word32 localSz = MAX_ENCODED_SIG_SZ; word32 digestSz; byte* digest; byte doUserEcc = 0; #ifndef NO_OLD_TLS /* old tls default */ digestSz = SHA_DIGEST_SIZE; digest = ssl->hsHashes->certHashes.sha; #else /* new tls default */ digestSz = SHA256_DIGEST_SIZE; digest = ssl->hsHashes->certHashes.sha256; #endif #ifdef HAVE_PK_CALLBACKS #ifdef HAVE_ECC if (ssl->ctx->EccSignCb) doUserEcc = 1; #endif /* HAVE_ECC */ #endif /*HAVE_PK_CALLBACKS */ if (IsAtLeastTLSv1_2(ssl)) { if (ssl->suites->hashAlgo == sha_mac) { #ifndef NO_SHA digest = ssl->hsHashes->certHashes.sha; digestSz = SHA_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = ssl->hsHashes->certHashes.sha256; digestSz = SHA256_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = ssl->hsHashes->certHashes.sha384; digestSz = SHA384_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = ssl->hsHashes->certHashes.sha512; digestSz = SHA512_DIGEST_SIZE; #endif } } if (doUserEcc) { #ifdef HAVE_PK_CALLBACKS #ifdef HAVE_ECC ret = ssl->ctx->EccSignCb(ssl, digest, digestSz, encodedSig, &localSz, ssl->buffers.key.buffer, ssl->buffers.key.length, ssl->EccSignCtx); #endif /* HAVE_ECC */ #endif /*HAVE_PK_CALLBACKS */ } else { ret = wc_ecc_sign_hash(digest, digestSz, encodedSig, &localSz, ssl->rng, &eccKey); } if (ret == 0) { length = localSz; c16toa((word16)length, verify + extraSz); /* prepend hdr */ XMEMCPY(verify + extraSz + VERIFY_HEADER,encodedSig,length); } #endif } #ifndef NO_RSA else { byte doUserRsa = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->RsaSignCb) doUserRsa = 1; #endif /*HAVE_PK_CALLBACKS */ if (IsAtLeastTLSv1_2(ssl)) { /* * MSVC Compiler complains because it can not * guarantee any of the conditionals will succeed in * assigning a value before wc_EncodeSignature executes. */ byte* digest = NULL; int digestSz = 0; int typeH = 0; int didSet = 0; if (ssl->suites->hashAlgo == sha_mac) { #ifndef NO_SHA digest = ssl->hsHashes->certHashes.sha; typeH = SHAh; digestSz = SHA_DIGEST_SIZE; didSet = 1; #endif } else if (ssl->suites->hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = ssl->hsHashes->certHashes.sha256; typeH = SHA256h; digestSz = SHA256_DIGEST_SIZE; didSet = 1; #endif } else if (ssl->suites->hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = ssl->hsHashes->certHashes.sha384; typeH = SHA384h; digestSz = SHA384_DIGEST_SIZE; didSet = 1; #endif } else if (ssl->suites->hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = ssl->hsHashes->certHashes.sha512; typeH = SHA512h; digestSz = SHA512_DIGEST_SIZE; didSet = 1; #endif } if (didSet == 0) { /* defaults */ #ifndef NO_OLD_TLS digest = ssl->hsHashes->certHashes.sha; digestSz = SHA_DIGEST_SIZE; typeH = SHAh; #else digest = ssl->hsHashes->certHashes.sha256; digestSz = SHA256_DIGEST_SIZE; typeH = SHA256h; #endif } signSz = wc_EncodeSignature(encodedSig, digest,digestSz,typeH); signBuffer = encodedSig; } c16toa((word16)length, verify + extraSz); /* prepend hdr */ if (doUserRsa) { #ifdef HAVE_PK_CALLBACKS #ifndef NO_RSA word32 ioLen = ENCRYPT_LEN; ret = ssl->ctx->RsaSignCb(ssl, signBuffer, signSz, verify + extraSz + VERIFY_HEADER, &ioLen, ssl->buffers.key.buffer, ssl->buffers.key.length, ssl->RsaSignCtx); #endif /* NO_RSA */ #endif /*HAVE_PK_CALLBACKS */ } else { ret = wc_RsaSSL_Sign(signBuffer, signSz, verify + extraSz + VERIFY_HEADER, ENCRYPT_LEN, &key, ssl->rng); } if (ret > 0) ret = 0; /* RSA reset */ } #endif #ifdef WOLFSSL_SMALL_STACK XFREE(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret == 0) { AddHeaders(output, length + extraSz + VERIFY_HEADER, certificate_verify, ssl); sendSz = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ + length + extraSz + VERIFY_HEADER; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; } #endif if (ssl->keys.encryptionOn) { byte* input; int inputSz = sendSz - RECORD_HEADER_SZ; /* build msg adds rec hdr */ input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (input == NULL) ret = MEMORY_E; else { XMEMCPY(input, output + RECORD_HEADER_SZ, inputSz); sendSz = BuildMessage(ssl, output, MAX_CERT_VERIFY_SZ +MAX_MSG_EXTRA, input, inputSz, handshake); XFREE(input, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); if (sendSz < 0) ret = sendSz; } } else { ret = HashOutput(ssl, output, sendSz, 0); } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif } } #ifndef NO_RSA if (initRsaKey) wc_FreeRsaKey(&key); #endif #ifdef HAVE_ECC wc_ecc_free(&eccKey); #endif if (ret == 0) { #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("CertificateVerify", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("CertificateVerify", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) return 0; else return SendBuffered(ssl); } else return ret; } #endif /* NO_CERTS */ #ifdef HAVE_SESSION_TICKET int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 size) { word32 begin = *inOutIdx; word32 lifetime; word16 length; if (ssl->expect_session_ticket == 0) { WOLFSSL_MSG("Unexpected session ticket"); return SESSION_TICKET_EXPECT_E; } if ((*inOutIdx - begin) + OPAQUE32_LEN > size) return BUFFER_ERROR; ato32(input + *inOutIdx, &lifetime); *inOutIdx += OPAQUE32_LEN; if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &length); *inOutIdx += OPAQUE16_LEN; if (length > sizeof(ssl->session.ticket)) return SESSION_TICKET_LEN_E; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; /* If the received ticket including its length is greater than * a length value, the save it. Otherwise, don't save it. */ if (length > 0) { XMEMCPY(ssl->session.ticket, input + *inOutIdx, length); *inOutIdx += length; ssl->session.ticketLen = length; ssl->timeout = lifetime; if (ssl->session_ticket_cb != NULL) { ssl->session_ticket_cb(ssl, ssl->session.ticket, ssl->session.ticketLen, ssl->session_ticket_ctx); } /* Create a fake sessionID based on the ticket, this will * supercede the existing session cache info. */ ssl->options.haveSessionId = 1; XMEMCPY(ssl->arrays->sessionID, ssl->session.ticket + length - ID_LEN, ID_LEN); #ifndef NO_SESSION_CACHE AddSession(ssl); #endif } else { ssl->session.ticketLen = 0; } if (ssl->keys.encryptionOn) { *inOutIdx += ssl->keys.padSz; } ssl->expect_session_ticket = 0; return 0; } #endif /* HAVE_SESSION_TICKET */ #endif /* NO_WOLFSSL_CLIENT */ #ifndef NO_WOLFSSL_SERVER int SendServerHello(WOLFSSL* ssl) { byte *output; word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int sendSz; int ret; byte sessIdSz = ID_LEN; length = VERSION_SZ + RAN_LEN + ID_LEN + ENUM_LEN + SUITE_LEN + ENUM_LEN; #ifdef HAVE_TLS_EXTENSIONS length += TLSX_GetResponseSize(ssl); #ifdef HAVE_SESSION_TICKET if (ssl->options.useTicket && ssl->arrays->sessionIDSz == 0) { /* no session id */ length -= ID_LEN; sessIdSz = 0; } #endif /* HAVE_SESSION_TICKET */ #endif /* check for avalaible size */ if ((ret = CheckAvailableSize(ssl, MAX_HELLO_SZ)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; AddHeaders(output, length, server_hello, ssl); #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; } #endif /* now write to output */ /* first version */ output[idx++] = ssl->version.major; output[idx++] = ssl->version.minor; /* then random */ if (!ssl->options.resuming) { ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, RAN_LEN); if (ret != 0) return ret; } XMEMCPY(output + idx, ssl->arrays->serverRandom, RAN_LEN); idx += RAN_LEN; #ifdef SHOW_SECRETS { int j; printf("server random: "); for (j = 0; j < RAN_LEN; j++) printf("%02x", ssl->arrays->serverRandom[j]); printf("\n"); } #endif /* then session id */ output[idx++] = sessIdSz; if (sessIdSz) { if (!ssl->options.resuming) { ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->sessionID, sessIdSz); if (ret != 0) return ret; } XMEMCPY(output + idx, ssl->arrays->sessionID, sessIdSz); idx += sessIdSz; } /* then cipher suite */ output[idx++] = ssl->options.cipherSuite0; output[idx++] = ssl->options.cipherSuite; /* then compression */ if (ssl->options.usingCompression) output[idx++] = ZLIB_COMPRESSION; else output[idx++] = NO_COMPRESSION; /* last, extensions */ #ifdef HAVE_TLS_EXTENSIONS TLSX_WriteResponse(ssl, output + idx); #endif ssl->buffers.outputBuffer.length += sendSz; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; } #endif ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerHello", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ServerHello", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->options.serverState = SERVER_HELLO_COMPLETE; if (ssl->options.groupMessages) return 0; else return SendBuffered(ssl); } #ifdef HAVE_ECC static byte SetCurveId(int size) { switch(size) { #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC160) case 20: return WOLFSSL_ECC_SECP160R1; #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC192) case 24: return WOLFSSL_ECC_SECP192R1; #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC224) case 28: return WOLFSSL_ECC_SECP224R1; #endif #if defined(HAVE_ALL_CURVES) || !defined(NO_ECC256) case 32: return WOLFSSL_ECC_SECP256R1; #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC384) case 48: return WOLFSSL_ECC_SECP384R1; #endif #if defined(HAVE_ALL_CURVES) || defined(HAVE_ECC521) case 66: return WOLFSSL_ECC_SECP521R1; #endif default: return 0; } } #endif /* HAVE_ECC */ int SendServerKeyExchange(WOLFSSL* ssl) { int ret = 0; (void)ssl; #define ERROR_OUT(err, eLabel) do { ret = err; goto eLabel; } while(0) #ifndef NO_PSK if (ssl->specs.kea == psk_kea) { byte *output; word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int sendSz; if (ssl->arrays->server_hint[0] == 0) return 0; /* don't send */ /* include size part */ length = (word32)XSTRLEN(ssl->arrays->server_hint); if (length > MAX_PSK_ID_LEN) return SERVER_HINT_ERROR; length += HINT_LEN_SZ; sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; } #endif /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, server_key_exchange, ssl); /* key data */ c16toa((word16)(length - HINT_LEN_SZ), output + idx); idx += HINT_LEN_SZ; XMEMCPY(output + idx, ssl->arrays->server_hint,length -HINT_LEN_SZ); #ifdef WOLFSSL_DTLS if (ssl->options.dtls) if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; #endif ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) ret = 0; else ret = SendBuffered(ssl); ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; } #endif /*NO_PSK */ #if !defined(NO_DH) && !defined(NO_PSK) if (ssl->specs.kea == dhe_psk_kea) { byte *output; word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; word32 hintLen; int sendSz; DhKey dhKey; if (ssl->buffers.serverDH_P.buffer == NULL || ssl->buffers.serverDH_G.buffer == NULL) return NO_DH_PARAMS; if (ssl->buffers.serverDH_Pub.buffer == NULL) { ssl->buffers.serverDH_Pub.buffer = (byte*)XMALLOC( ssl->buffers.serverDH_P.length + 2, ssl->ctx->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_Pub.buffer == NULL) return MEMORY_E; } if (ssl->buffers.serverDH_Priv.buffer == NULL) { ssl->buffers.serverDH_Priv.buffer = (byte*)XMALLOC( ssl->buffers.serverDH_P.length + 2, ssl->ctx->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_Priv.buffer == NULL) return MEMORY_E; } wc_InitDhKey(&dhKey); ret = wc_DhSetKey(&dhKey, ssl->buffers.serverDH_P.buffer, ssl->buffers.serverDH_P.length, ssl->buffers.serverDH_G.buffer, ssl->buffers.serverDH_G.length); if (ret == 0) ret = wc_DhGenerateKeyPair(&dhKey, ssl->rng, ssl->buffers.serverDH_Priv.buffer, &ssl->buffers.serverDH_Priv.length, ssl->buffers.serverDH_Pub.buffer, &ssl->buffers.serverDH_Pub.length); wc_FreeDhKey(&dhKey); if (ret != 0) return ret; length = LENGTH_SZ * 3 + /* p, g, pub */ ssl->buffers.serverDH_P.length + ssl->buffers.serverDH_G.length + ssl->buffers.serverDH_Pub.length; /* include size part */ hintLen = (word32)XSTRLEN(ssl->arrays->server_hint); if (hintLen > MAX_PSK_ID_LEN) return SERVER_HINT_ERROR; length += hintLen + HINT_LEN_SZ; sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; } #endif /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, server_key_exchange, ssl); /* key data */ c16toa((word16)hintLen, output + idx); idx += HINT_LEN_SZ; XMEMCPY(output + idx, ssl->arrays->server_hint, hintLen); idx += hintLen; /* add p, g, pub */ c16toa((word16)ssl->buffers.serverDH_P.length, output + idx); idx += LENGTH_SZ; XMEMCPY(output + idx, ssl->buffers.serverDH_P.buffer, ssl->buffers.serverDH_P.length); idx += ssl->buffers.serverDH_P.length; /* g */ c16toa((word16)ssl->buffers.serverDH_G.length, output + idx); idx += LENGTH_SZ; XMEMCPY(output + idx, ssl->buffers.serverDH_G.buffer, ssl->buffers.serverDH_G.length); idx += ssl->buffers.serverDH_G.length; /* pub */ c16toa((word16)ssl->buffers.serverDH_Pub.length, output + idx); idx += LENGTH_SZ; XMEMCPY(output + idx, ssl->buffers.serverDH_Pub.buffer, ssl->buffers.serverDH_Pub.length); idx += ssl->buffers.serverDH_Pub.length; (void)idx; /* suppress analyzer warning, and keep idx current */ #ifdef WOLFSSL_DTLS if (ssl->options.dtls) if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; #endif ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) ret = 0; else ret = SendBuffered(ssl); ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; } #endif /* !NO_DH && !NO_PSK */ #ifdef HAVE_ECC if (ssl->specs.kea == ecc_diffie_hellman_kea) { byte *output; word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int sendSz; word32 sigSz; word32 preSigSz, preSigIdx; #ifndef NO_RSA RsaKey rsaKey; #endif ecc_key dsaKey; #ifdef WOLFSSL_SMALL_STACK byte* exportBuf = NULL; #else byte exportBuf[MAX_EXPORT_ECC_SZ]; #endif word32 expSz = MAX_EXPORT_ECC_SZ; #ifndef NO_OLD_TLS byte doMd5 = 0; byte doSha = 0; #endif #ifndef NO_SHA256 byte doSha256 = 0; #endif #ifdef WOLFSSL_SHA384 byte doSha384 = 0; #endif #ifdef WOLFSSL_SHA512 byte doSha512 = 0; #endif if (ssl->specs.static_ecdh) { WOLFSSL_MSG("Using Static ECDH, not sending ServerKeyExchagne"); return 0; } /* curve type, named curve, length(1) */ length = ENUM_LEN + CURVE_LEN + ENUM_LEN; /* pub key size */ WOLFSSL_MSG("Using ephemeral ECDH"); /* need ephemeral key now, create it if missing */ if (ssl->eccTempKey == NULL) { /* alloc/init on demand */ ssl->eccTempKey = (ecc_key*)XMALLOC(sizeof(ecc_key), ssl->ctx->heap, DYNAMIC_TYPE_ECC); if (ssl->eccTempKey == NULL) { WOLFSSL_MSG("EccTempKey Memory error"); return MEMORY_E; } wc_ecc_init(ssl->eccTempKey); } if (ssl->eccTempKeyPresent == 0) { if (wc_ecc_make_key(ssl->rng, ssl->eccTempKeySz, ssl->eccTempKey) != 0) { return ECC_MAKEKEY_ERROR; } ssl->eccTempKeyPresent = 1; } #ifdef WOLFSSL_SMALL_STACK exportBuf = (byte*)XMALLOC(MAX_EXPORT_ECC_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (exportBuf == NULL) return MEMORY_E; #endif if (wc_ecc_export_x963(ssl->eccTempKey, exportBuf, &expSz) != 0) ERROR_OUT(ECC_EXPORT_ERROR, done_a); length += expSz; preSigSz = length; preSigIdx = idx; #ifndef NO_RSA ret = wc_InitRsaKey(&rsaKey, ssl->heap); if (ret != 0) goto done_a; #endif wc_ecc_init(&dsaKey); /* sig length */ length += LENGTH_SZ; if (!ssl->buffers.key.buffer) { #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); ERROR_OUT(NO_PRIVATE_KEY, done_a); } #ifndef NO_RSA if (ssl->specs.sig_algo == rsa_sa_algo) { /* rsa sig size */ word32 i = 0; ret = wc_RsaPrivateKeyDecode(ssl->buffers.key.buffer, &i, &rsaKey, ssl->buffers.key.length); if (ret != 0) goto done_a; sigSz = wc_RsaEncryptSize(&rsaKey); } else #endif if (ssl->specs.sig_algo == ecc_dsa_sa_algo) { /* ecdsa sig size */ word32 i = 0; ret = wc_EccPrivateKeyDecode(ssl->buffers.key.buffer, &i, &dsaKey, ssl->buffers.key.length); if (ret != 0) goto done_a; sigSz = wc_ecc_sig_size(&dsaKey); /* worst case estimate */ } else { #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); ERROR_OUT(ALGO_ID_E, done_a); /* unsupported type */ } length += sigSz; if (IsAtLeastTLSv1_2(ssl)) length += HASH_SIG_SIZE; sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; preSigIdx = idx; } #endif /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) { #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); goto done_a; } /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; /* record and message headers will be added below, when we're sure of the sig length */ /* key exchange data */ output[idx++] = named_curve; output[idx++] = 0x00; /* leading zero */ output[idx++] = SetCurveId(wc_ecc_size(ssl->eccTempKey)); output[idx++] = (byte)expSz; XMEMCPY(output + idx, exportBuf, expSz); idx += expSz; if (IsAtLeastTLSv1_2(ssl)) { byte setHash = 0; output[idx++] = ssl->suites->hashAlgo; output[idx++] = ssl->suites->sigAlgo; switch (ssl->suites->hashAlgo) { case sha512_mac: #ifdef WOLFSSL_SHA512 doSha512 = 1; setHash = 1; #endif break; case sha384_mac: #ifdef WOLFSSL_SHA384 doSha384 = 1; setHash = 1; #endif break; case sha256_mac: #ifndef NO_SHA256 doSha256 = 1; setHash = 1; #endif break; case sha_mac: #ifndef NO_OLD_TLS doSha = 1; setHash = 1; #endif break; default: WOLFSSL_MSG("Bad hash sig algo"); break; } if (setHash == 0) { #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); ERROR_OUT(ALGO_ID_E, done_a); } } else { /* only using sha and md5 for rsa */ #ifndef NO_OLD_TLS doSha = 1; if (ssl->suites->sigAlgo == rsa_sa_algo) { doMd5 = 1; } #else #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); ERROR_OUT(ALGO_ID_E, done_a); #endif } /* Signtaure length will be written later, when we're sure what it is */ #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, output + preSigIdx, preSigSz, FUZZ_SIGNATURE, ssl->fuzzerCtx); #endif /* do signature */ { #ifndef NO_OLD_TLS #ifdef WOLFSSL_SMALL_STACK Md5* md5 = NULL; Sha* sha = NULL; #else Md5 md5[1]; Sha sha[1]; #endif #endif #ifdef WOLFSSL_SMALL_STACK byte* hash = NULL; #else byte hash[FINISHED_SZ]; #endif #ifndef NO_SHA256 #ifdef WOLFSSL_SMALL_STACK Sha256* sha256 = NULL; byte* hash256 = NULL; #else Sha256 sha256[1]; byte hash256[SHA256_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SMALL_STACK Sha384* sha384 = NULL; byte* hash384 = NULL; #else Sha384 sha384[1]; byte hash384[SHA384_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SMALL_STACK Sha512* sha512 = NULL; byte* hash512 = NULL; #else Sha512 sha512[1]; byte hash512[SHA512_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SMALL_STACK hash = (byte*)XMALLOC(FINISHED_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash == NULL) ERROR_OUT(MEMORY_E, done_a); #endif #ifndef NO_OLD_TLS /* md5 */ #ifdef WOLFSSL_SMALL_STACK if (doMd5) { md5 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (md5 == NULL) ERROR_OUT(MEMORY_E, done_a2); } #endif if (doMd5) { wc_InitMd5(md5); wc_Md5Update(md5, ssl->arrays->clientRandom, RAN_LEN); wc_Md5Update(md5, ssl->arrays->serverRandom, RAN_LEN); wc_Md5Update(md5, output + preSigIdx, preSigSz); wc_Md5Final(md5, hash); } /* sha */ #ifdef WOLFSSL_SMALL_STACK if (doSha) { sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha == NULL) ERROR_OUT(MEMORY_E, done_a2); } #endif if (doSha) { ret = wc_InitSha(sha); if (ret != 0) goto done_a2; wc_ShaUpdate(sha, ssl->arrays->clientRandom, RAN_LEN); wc_ShaUpdate(sha, ssl->arrays->serverRandom, RAN_LEN); wc_ShaUpdate(sha, output + preSigIdx, preSigSz); wc_ShaFinal(sha, &hash[MD5_DIGEST_SIZE]); } #endif #ifndef NO_SHA256 #ifdef WOLFSSL_SMALL_STACK if (doSha256) { sha256 = (Sha256*)XMALLOC(sizeof(Sha256), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash256 = (byte*)XMALLOC(SHA256_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha256 == NULL || hash256 == NULL) ERROR_OUT(MEMORY_E, done_a2); } #endif if (doSha256) { if (!(ret = wc_InitSha256(sha256)) && !(ret = wc_Sha256Update(sha256, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha256Update(sha256, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha256Update(sha256, output + preSigIdx, preSigSz))) ret = wc_Sha256Final(sha256, hash256); if (ret != 0) goto done_a2; } #endif #ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SMALL_STACK if (doSha384) { sha384 = (Sha384*)XMALLOC(sizeof(Sha384), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash384 = (byte*)XMALLOC(SHA384_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha384 == NULL || hash384 == NULL) ERROR_OUT(MEMORY_E, done_a2); } #endif if (doSha384) { if (!(ret = wc_InitSha384(sha384)) && !(ret = wc_Sha384Update(sha384, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha384Update(sha384, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha384Update(sha384, output + preSigIdx, preSigSz))) ret = wc_Sha384Final(sha384, hash384); if (ret != 0) goto done_a2; } #endif #ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SMALL_STACK if (doSha512) { sha512 = (Sha512*)XMALLOC(sizeof(Sha512), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash512 = (byte*)XMALLOC(SHA512_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha512 == NULL || hash512 == NULL) ERROR_OUT(MEMORY_E, done_a2); } #endif if (doSha512) { if (!(ret = wc_InitSha512(sha512)) && !(ret = wc_Sha512Update(sha512, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha512Update(sha512, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha512Update(sha512, output + preSigIdx, preSigSz))) ret = wc_Sha512Final(sha512, hash512); if (ret != 0) goto done_a2; } #endif #ifndef NO_RSA if (ssl->suites->sigAlgo == rsa_sa_algo) { byte* signBuffer = hash; word32 signSz = FINISHED_SZ; byte doUserRsa = 0; #ifdef WOLFSSL_SMALL_STACK byte* encodedSig = NULL; #else byte encodedSig[MAX_ENCODED_SIG_SZ]; #endif #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->RsaSignCb) doUserRsa = 1; #endif #ifdef WOLFSSL_SMALL_STACK encodedSig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encodedSig == NULL) ERROR_OUT(MEMORY_E, done_a2); #endif if (IsAtLeastTLSv1_2(ssl)) { byte* digest = &hash[MD5_DIGEST_SIZE]; int typeH = SHAh; int digestSz = SHA_DIGEST_SIZE; if (ssl->suites->hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = hash256; typeH = SHA256h; digestSz = SHA256_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = hash384; typeH = SHA384h; digestSz = SHA384_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = hash512; typeH = SHA512h; digestSz = SHA512_DIGEST_SIZE; #endif } if (digest == NULL) { #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); ERROR_OUT(ALGO_ID_E, done_a2); } signSz = wc_EncodeSignature(encodedSig, digest, digestSz, typeH); signBuffer = encodedSig; } /* write sig size here */ c16toa((word16)sigSz, output + idx); idx += LENGTH_SZ; if (doUserRsa) { #ifdef HAVE_PK_CALLBACKS word32 ioLen = sigSz; ret = ssl->ctx->RsaSignCb(ssl, signBuffer, signSz, output + idx, &ioLen, ssl->buffers.key.buffer, ssl->buffers.key.length, ssl->RsaSignCtx); #endif /*HAVE_PK_CALLBACKS */ } else ret = wc_RsaSSL_Sign(signBuffer, signSz, output + idx, sigSz, &rsaKey, ssl->rng); wc_FreeRsaKey(&rsaKey); wc_ecc_free(&dsaKey); #ifdef WOLFSSL_SMALL_STACK XFREE(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret < 0) goto done_a2; } else #endif if (ssl->suites->sigAlgo == ecc_dsa_sa_algo) { #ifndef NO_OLD_TLS byte* digest = &hash[MD5_DIGEST_SIZE]; word32 digestSz = SHA_DIGEST_SIZE; #else byte* digest = hash256; word32 digestSz = SHA256_DIGEST_SIZE; #endif word32 sz = sigSz; byte doUserEcc = 0; #if defined(HAVE_PK_CALLBACKS) && defined(HAVE_ECC) if (ssl->ctx->EccSignCb) doUserEcc = 1; #endif if (IsAtLeastTLSv1_2(ssl)) { if (ssl->suites->hashAlgo == sha_mac) { #ifndef NO_SHA digest = &hash[MD5_DIGEST_SIZE]; digestSz = SHA_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = hash256; digestSz = SHA256_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = hash384; digestSz = SHA384_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = hash512; digestSz = SHA512_DIGEST_SIZE; #endif } } if (doUserEcc) { #if defined(HAVE_PK_CALLBACKS) && defined(HAVE_ECC) ret = ssl->ctx->EccSignCb(ssl, digest, digestSz, output + LENGTH_SZ + idx, &sz, ssl->buffers.key.buffer, ssl->buffers.key.length, ssl->EccSignCtx); #endif } else { ret = wc_ecc_sign_hash(digest, digestSz, output + LENGTH_SZ + idx, &sz, ssl->rng, &dsaKey); } #ifndef NO_RSA wc_FreeRsaKey(&rsaKey); #endif wc_ecc_free(&dsaKey); if (ret < 0) goto done_a2; /* Now that we know the real sig size, write it. */ c16toa((word16)sz, output + idx); /* And adjust length and sendSz from estimates */ length += sz - sigSz; sendSz += sz - sigSz; } done_a2: #ifdef WOLFSSL_SMALL_STACK #ifndef NO_OLD_TLS XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif XFREE(hash, NULL, DYNAMIC_TYPE_TMP_BUFFER); #ifndef NO_SHA256 XFREE(sha256, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash256, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifdef WOLFSSL_SHA384 XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash384, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifdef WOLFSSL_SHA512 XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash512, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #endif if (ret < 0) goto done_a; } AddHeaders(output, length, server_key_exchange, ssl); #ifdef WOLFSSL_DTLS if (ssl->options.dtls) if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) goto done_a; #endif if ((ret = HashOutput(ssl, output, sendSz, 0)) != 0) goto done_a; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) ret = 0; else ret = SendBuffered(ssl); ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; done_a: #ifdef WOLFSSL_SMALL_STACK XFREE(exportBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } #endif /* HAVE_ECC */ #if !defined(NO_DH) && !defined(NO_RSA) if (ssl->specs.kea == diffie_hellman_kea) { byte *output; word32 length = 0, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int sendSz; word32 sigSz = 0, i = 0; word32 preSigSz = 0, preSigIdx = 0; RsaKey rsaKey; DhKey dhKey; if (ssl->buffers.serverDH_P.buffer == NULL || ssl->buffers.serverDH_G.buffer == NULL) return NO_DH_PARAMS; if (ssl->buffers.serverDH_Pub.buffer == NULL) { ssl->buffers.serverDH_Pub.buffer = (byte*)XMALLOC( ssl->buffers.serverDH_P.length + 2, ssl->ctx->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_Pub.buffer == NULL) return MEMORY_E; } if (ssl->buffers.serverDH_Priv.buffer == NULL) { ssl->buffers.serverDH_Priv.buffer = (byte*)XMALLOC( ssl->buffers.serverDH_P.length + 2, ssl->ctx->heap, DYNAMIC_TYPE_DH); if (ssl->buffers.serverDH_Priv.buffer == NULL) return MEMORY_E; } wc_InitDhKey(&dhKey); ret = wc_DhSetKey(&dhKey, ssl->buffers.serverDH_P.buffer, ssl->buffers.serverDH_P.length, ssl->buffers.serverDH_G.buffer, ssl->buffers.serverDH_G.length); if (ret == 0) ret = wc_DhGenerateKeyPair(&dhKey, ssl->rng, ssl->buffers.serverDH_Priv.buffer, &ssl->buffers.serverDH_Priv.length, ssl->buffers.serverDH_Pub.buffer, &ssl->buffers.serverDH_Pub.length); wc_FreeDhKey(&dhKey); if (ret != 0) return ret; length = LENGTH_SZ * 3; /* p, g, pub */ length += ssl->buffers.serverDH_P.length + ssl->buffers.serverDH_G.length + ssl->buffers.serverDH_Pub.length; preSigIdx = idx; preSigSz = length; if (!ssl->options.usingAnon_cipher) { ret = wc_InitRsaKey(&rsaKey, ssl->heap); if (ret != 0) return ret; /* sig length */ length += LENGTH_SZ; if (!ssl->buffers.key.buffer) return NO_PRIVATE_KEY; ret = wc_RsaPrivateKeyDecode(ssl->buffers.key.buffer, &i, &rsaKey, ssl->buffers.key.length); if (ret == 0) { sigSz = wc_RsaEncryptSize(&rsaKey); length += sigSz; } else { wc_FreeRsaKey(&rsaKey); return ret; } if (IsAtLeastTLSv1_2(ssl)) length += HASH_SIG_SIZE; } sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; preSigIdx = idx; } #endif /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) { if (!ssl->options.usingAnon_cipher) wc_FreeRsaKey(&rsaKey); return ret; } /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, server_key_exchange, ssl); /* add p, g, pub */ c16toa((word16)ssl->buffers.serverDH_P.length, output + idx); idx += LENGTH_SZ; XMEMCPY(output + idx, ssl->buffers.serverDH_P.buffer, ssl->buffers.serverDH_P.length); idx += ssl->buffers.serverDH_P.length; /* g */ c16toa((word16)ssl->buffers.serverDH_G.length, output + idx); idx += LENGTH_SZ; XMEMCPY(output + idx, ssl->buffers.serverDH_G.buffer, ssl->buffers.serverDH_G.length); idx += ssl->buffers.serverDH_G.length; /* pub */ c16toa((word16)ssl->buffers.serverDH_Pub.length, output + idx); idx += LENGTH_SZ; XMEMCPY(output + idx, ssl->buffers.serverDH_Pub.buffer, ssl->buffers.serverDH_Pub.length); idx += ssl->buffers.serverDH_Pub.length; #ifdef HAVE_FUZZER if (ssl->fuzzerCb) ssl->fuzzerCb(ssl, output + preSigIdx, preSigSz, FUZZ_SIGNATURE, ssl->fuzzerCtx); #endif /* Add signature */ if (!ssl->options.usingAnon_cipher) { #ifndef NO_OLD_TLS #ifdef WOLFSSL_SMALL_STACK Md5* md5 = NULL; Sha* sha = NULL; #else Md5 md5[1]; Sha sha[1]; #endif #endif #ifdef WOLFSSL_SMALL_STACK byte* hash = NULL; #else byte hash[FINISHED_SZ]; #endif #ifndef NO_SHA256 #ifdef WOLFSSL_SMALL_STACK Sha256* sha256 = NULL; byte* hash256 = NULL; #else Sha256 sha256[1]; byte hash256[SHA256_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SMALL_STACK Sha384* sha384 = NULL; byte* hash384 = NULL; #else Sha384 sha384[1]; byte hash384[SHA384_DIGEST_SIZE]; #endif #endif #ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SMALL_STACK Sha512* sha512 = NULL; byte* hash512 = NULL; #else Sha512 sha512[1]; byte hash512[SHA512_DIGEST_SIZE]; #endif #endif #ifndef NO_OLD_TLS byte doMd5 = 0; byte doSha = 0; #endif #ifndef NO_SHA256 byte doSha256 = 0; #endif #ifdef WOLFSSL_SHA384 byte doSha384 = 0; #endif #ifdef WOLFSSL_SHA512 byte doSha512 = 0; #endif /* Add hash/signature algo ID */ if (IsAtLeastTLSv1_2(ssl)) { byte setHash = 0; output[idx++] = ssl->suites->hashAlgo; output[idx++] = ssl->suites->sigAlgo; switch (ssl->suites->hashAlgo) { case sha512_mac: #ifdef WOLFSSL_SHA512 doSha512 = 1; setHash = 1; #endif break; case sha384_mac: #ifdef WOLFSSL_SHA384 doSha384 = 1; setHash = 1; #endif break; case sha256_mac: #ifndef NO_SHA256 doSha256 = 1; setHash = 1; #endif break; case sha_mac: #ifndef NO_OLD_TLS doSha = 1; setHash = 1; #endif break; default: WOLFSSL_MSG("Bad hash sig algo"); break; } if (setHash == 0) { wc_FreeRsaKey(&rsaKey); return ALGO_ID_E; } } else { /* only using sha and md5 for rsa */ #ifndef NO_OLD_TLS doSha = 1; if (ssl->suites->sigAlgo == rsa_sa_algo) { doMd5 = 1; } #else wc_FreeRsaKey(&rsaKey); return ALGO_ID_E; #endif } /* signature size */ c16toa((word16)sigSz, output + idx); idx += LENGTH_SZ; /* do signature */ #ifdef WOLFSSL_SMALL_STACK hash = (byte*)XMALLOC(FINISHED_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash == NULL) return MEMORY_E; /* No heap commitment before this point, from now on, the resources are freed at done_b. */ #endif #ifndef NO_OLD_TLS /* md5 */ #ifdef WOLFSSL_SMALL_STACK if (doMd5) { md5 = (Md5*)XMALLOC(sizeof(Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (md5 == NULL) ERROR_OUT(MEMORY_E, done_b); } #endif if (doMd5) { wc_InitMd5(md5); wc_Md5Update(md5, ssl->arrays->clientRandom, RAN_LEN); wc_Md5Update(md5, ssl->arrays->serverRandom, RAN_LEN); wc_Md5Update(md5, output + preSigIdx, preSigSz); wc_Md5Final(md5, hash); } /* sha */ #ifdef WOLFSSL_SMALL_STACK if (doSha) { sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha == NULL) ERROR_OUT(MEMORY_E, done_b); } #endif if (doSha) { if ((ret = wc_InitSha(sha)) != 0) goto done_b; wc_ShaUpdate(sha, ssl->arrays->clientRandom, RAN_LEN); wc_ShaUpdate(sha, ssl->arrays->serverRandom, RAN_LEN); wc_ShaUpdate(sha, output + preSigIdx, preSigSz); wc_ShaFinal(sha, &hash[MD5_DIGEST_SIZE]); } #endif #ifndef NO_SHA256 #ifdef WOLFSSL_SMALL_STACK if (doSha256) { sha256 = (Sha256*)XMALLOC(sizeof(Sha256), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash256 = (byte*)XMALLOC(SHA256_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha256 == NULL || hash256 == NULL) ERROR_OUT(MEMORY_E, done_b); } #endif if (doSha256) { if (!(ret = wc_InitSha256(sha256)) && !(ret = wc_Sha256Update(sha256, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha256Update(sha256, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha256Update(sha256, output + preSigIdx, preSigSz))) ret = wc_Sha256Final(sha256, hash256); if (ret != 0) goto done_b; } #endif #ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SMALL_STACK if (doSha384) { sha384 = (Sha384*)XMALLOC(sizeof(Sha384), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash384 = (byte*)XMALLOC(SHA384_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha384 == NULL || hash384 == NULL) ERROR_OUT(MEMORY_E, done_b); } #endif if (doSha384) { if (!(ret = wc_InitSha384(sha384)) && !(ret = wc_Sha384Update(sha384, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha384Update(sha384, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha384Update(sha384, output + preSigIdx, preSigSz))) ret = wc_Sha384Final(sha384, hash384); if (ret != 0) goto done_b; } #endif #ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SMALL_STACK if (doSha512) { sha512 = (Sha512*)XMALLOC(sizeof(Sha512), NULL, DYNAMIC_TYPE_TMP_BUFFER); hash512 = (byte*)XMALLOC(SHA512_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha512 == NULL || hash512 == NULL) ERROR_OUT(MEMORY_E, done_b); } #endif if (doSha512) { if (!(ret = wc_InitSha512(sha512)) && !(ret = wc_Sha512Update(sha512, ssl->arrays->clientRandom, RAN_LEN)) && !(ret = wc_Sha512Update(sha512, ssl->arrays->serverRandom, RAN_LEN)) && !(ret = wc_Sha512Update(sha512, output + preSigIdx, preSigSz))) ret = wc_Sha512Final(sha512, hash512); if (ret != 0) goto done_b; } #endif #ifndef NO_RSA if (ssl->suites->sigAlgo == rsa_sa_algo) { byte* signBuffer = hash; word32 signSz = FINISHED_SZ; #ifdef WOLFSSL_SMALL_STACK byte* encodedSig = NULL; #else byte encodedSig[MAX_ENCODED_SIG_SZ]; #endif byte doUserRsa = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->RsaSignCb) doUserRsa = 1; #endif #ifdef WOLFSSL_SMALL_STACK encodedSig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encodedSig == NULL) ERROR_OUT(MEMORY_E, done_b); #endif if (IsAtLeastTLSv1_2(ssl)) { byte* digest = &hash[MD5_DIGEST_SIZE]; int typeH = SHAh; int digestSz = SHA_DIGEST_SIZE; if (ssl->suites->hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = hash256; typeH = SHA256h; digestSz = SHA256_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = hash384; typeH = SHA384h; digestSz = SHA384_DIGEST_SIZE; #endif } else if (ssl->suites->hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = hash512; typeH = SHA512h; digestSz = SHA512_DIGEST_SIZE; #endif } if (digest == NULL) { ret = ALGO_ID_E; } else { signSz = wc_EncodeSignature(encodedSig, digest, digestSz, typeH); signBuffer = encodedSig; } } if (doUserRsa && ret == 0) { #ifdef HAVE_PK_CALLBACKS word32 ioLen = sigSz; ret = ssl->ctx->RsaSignCb(ssl, signBuffer, signSz, output + idx, &ioLen, ssl->buffers.key.buffer, ssl->buffers.key.length, ssl->RsaSignCtx); #endif } else if (ret == 0) { ret = wc_RsaSSL_Sign(signBuffer, signSz, output + idx, sigSz, &rsaKey, ssl->rng); } wc_FreeRsaKey(&rsaKey); #ifdef WOLFSSL_SMALL_STACK XFREE(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } #endif done_b: #ifdef WOLFSSL_SMALL_STACK #ifndef NO_OLD_TLS XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif XFREE(hash, NULL, DYNAMIC_TYPE_TMP_BUFFER); #ifndef NO_SHA256 XFREE(sha256, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash256, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifdef WOLFSSL_SHA384 XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash384, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #ifdef WOLFSSL_SHA512 XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(hash512, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif #endif if (ret < 0) return ret; } #ifdef WOLFSSL_DTLS if (ssl->options.dtls) if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return ret; #endif if ((ret = HashOutput(ssl, output, sendSz, 0)) != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->buffers.outputBuffer.length += sendSz; if (ssl->options.groupMessages) ret = 0; else ret = SendBuffered(ssl); ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; } #endif /* NO_DH */ return ret; #undef ERROR_OUT } /* Make sure server cert/key are valid for this suite, true on success */ static int VerifyServerSuite(WOLFSSL* ssl, word16 idx) { int haveRSA = !ssl->options.haveStaticECC; int havePSK = 0; byte first; byte second; WOLFSSL_ENTER("VerifyServerSuite"); if (ssl->suites == NULL) { WOLFSSL_MSG("Suites pointer error"); return 0; } first = ssl->suites->suites[idx]; second = ssl->suites->suites[idx+1]; #ifndef NO_PSK havePSK = ssl->options.havePSK; #endif if (ssl->options.haveNTRU) haveRSA = 0; if (CipherRequires(first, second, REQUIRES_RSA)) { WOLFSSL_MSG("Requires RSA"); if (haveRSA == 0) { WOLFSSL_MSG("Don't have RSA"); return 0; } } if (CipherRequires(first, second, REQUIRES_DHE)) { WOLFSSL_MSG("Requires DHE"); if (ssl->options.haveDH == 0) { WOLFSSL_MSG("Don't have DHE"); return 0; } } if (CipherRequires(first, second, REQUIRES_ECC_DSA)) { WOLFSSL_MSG("Requires ECCDSA"); if (ssl->options.haveECDSAsig == 0) { WOLFSSL_MSG("Don't have ECCDSA"); return 0; } } if (CipherRequires(first, second, REQUIRES_ECC_STATIC)) { WOLFSSL_MSG("Requires static ECC"); if (ssl->options.haveStaticECC == 0) { WOLFSSL_MSG("Don't have static ECC"); return 0; } } if (CipherRequires(first, second, REQUIRES_PSK)) { WOLFSSL_MSG("Requires PSK"); if (havePSK == 0) { WOLFSSL_MSG("Don't have PSK"); return 0; } } if (CipherRequires(first, second, REQUIRES_NTRU)) { WOLFSSL_MSG("Requires NTRU"); if (ssl->options.haveNTRU == 0) { WOLFSSL_MSG("Don't have NTRU"); return 0; } } if (CipherRequires(first, second, REQUIRES_RSA_SIG)) { WOLFSSL_MSG("Requires RSA Signature"); if (ssl->options.side == WOLFSSL_SERVER_END && ssl->options.haveECDSAsig == 1) { WOLFSSL_MSG("Don't have RSA Signature"); return 0; } } #ifdef HAVE_SUPPORTED_CURVES if (!TLSX_ValidateEllipticCurves(ssl, first, second)) { WOLFSSL_MSG("Don't have matching curves"); return 0; } #endif /* ECCDHE is always supported if ECC on */ return 1; } static int MatchSuite(WOLFSSL* ssl, Suites* peerSuites) { word16 i, j; WOLFSSL_ENTER("MatchSuite"); /* & 0x1 equivalent % 2 */ if (peerSuites->suiteSz == 0 || peerSuites->suiteSz & 0x1) return MATCH_SUITE_ERROR; if (ssl->suites == NULL) return SUITES_ERROR; /* start with best, if a match we are good */ for (i = 0; i < ssl->suites->suiteSz; i += 2) for (j = 0; j < peerSuites->suiteSz; j += 2) if (ssl->suites->suites[i] == peerSuites->suites[j] && ssl->suites->suites[i+1] == peerSuites->suites[j+1] ) { if (VerifyServerSuite(ssl, i)) { int result; WOLFSSL_MSG("Verified suite validity"); ssl->options.cipherSuite0 = ssl->suites->suites[i]; ssl->options.cipherSuite = ssl->suites->suites[i+1]; result = SetCipherSpecs(ssl); if (result == 0) PickHashSigAlgo(ssl, peerSuites->hashSigAlgo, peerSuites->hashSigAlgoSz); return result; } else { WOLFSSL_MSG("Could not verify suite validity, continue"); } } return MATCH_SUITE_ERROR; } #ifdef OLD_HELLO_ALLOWED /* process old style client hello, deprecate? */ int ProcessOldClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 inSz, word16 sz) { word32 idx = *inOutIdx; word16 sessionSz; word16 randomSz; word16 i, j; ProtocolVersion pv; Suites clSuites; (void)inSz; WOLFSSL_MSG("Got old format client hello"); #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ClientHello", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("ClientHello", &ssl->timeoutInfo); #endif /* manually hash input since different format */ #ifndef NO_OLD_TLS #ifndef NO_MD5 wc_Md5Update(&ssl->hsHashes->hashMd5, input + idx, sz); #endif #ifndef NO_SHA wc_ShaUpdate(&ssl->hsHashes->hashSha, input + idx, sz); #endif #endif #ifndef NO_SHA256 if (IsAtLeastTLSv1_2(ssl)) { int shaRet = wc_Sha256Update(&ssl->hsHashes->hashSha256, input + idx, sz); if (shaRet != 0) return shaRet; } #endif /* does this value mean client_hello? */ idx++; /* version */ pv.major = input[idx++]; pv.minor = input[idx++]; ssl->chVersion = pv; /* store */ if (ssl->version.minor > pv.minor) { byte haveRSA = 0; byte havePSK = 0; if (!ssl->options.downgrade) { WOLFSSL_MSG("Client trying to connect with lesser version"); return VERSION_ERROR; } if (pv.minor < ssl->options.minDowngrade) { WOLFSSL_MSG(" version below minimum allowed, fatal error"); return VERSION_ERROR; } if (pv.minor == SSLv3_MINOR) { /* turn off tls */ WOLFSSL_MSG(" downgrading to SSLv3"); ssl->options.tls = 0; ssl->options.tls1_1 = 0; ssl->version.minor = SSLv3_MINOR; } else if (pv.minor == TLSv1_MINOR) { WOLFSSL_MSG(" downgrading to TLSv1"); /* turn off tls 1.1+ */ ssl->options.tls1_1 = 0; ssl->version.minor = TLSv1_MINOR; } else if (pv.minor == TLSv1_1_MINOR) { WOLFSSL_MSG(" downgrading to TLSv1.1"); ssl->version.minor = TLSv1_1_MINOR; } #ifndef NO_RSA haveRSA = 1; #endif #ifndef NO_PSK havePSK = ssl->options.havePSK; #endif InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, ssl->options.haveDH, ssl->options.haveNTRU, ssl->options.haveECDSAsig, ssl->options.haveStaticECC, ssl->options.side); } /* suite size */ ato16(&input[idx], &clSuites.suiteSz); idx += 2; if (clSuites.suiteSz > MAX_SUITE_SZ) return BUFFER_ERROR; clSuites.hashSigAlgoSz = 0; /* session size */ ato16(&input[idx], &sessionSz); idx += 2; if (sessionSz > ID_LEN) return BUFFER_ERROR; /* random size */ ato16(&input[idx], &randomSz); idx += 2; if (randomSz > RAN_LEN) return BUFFER_ERROR; /* suites */ for (i = 0, j = 0; i < clSuites.suiteSz; i += 3) { byte first = input[idx++]; if (!first) { /* implicit: skip sslv2 type */ XMEMCPY(&clSuites.suites[j], &input[idx], 2); j += 2; } idx += 2; } clSuites.suiteSz = j; /* session id */ if (sessionSz) { XMEMCPY(ssl->arrays->sessionID, input + idx, sessionSz); ssl->arrays->sessionIDSz = (byte)sessionSz; idx += sessionSz; ssl->options.resuming = 1; } /* random */ if (randomSz < RAN_LEN) XMEMSET(ssl->arrays->clientRandom, 0, RAN_LEN - randomSz); XMEMCPY(&ssl->arrays->clientRandom[RAN_LEN - randomSz], input + idx, randomSz); idx += randomSz; if (ssl->options.usingCompression) ssl->options.usingCompression = 0; /* turn off */ ssl->options.clientState = CLIENT_HELLO_COMPLETE; *inOutIdx = idx; ssl->options.haveSessionId = 1; /* DoClientHello uses same resume code */ if (ssl->options.resuming) { /* let's try */ int ret = -1; WOLFSSL_SESSION* session = GetSession(ssl, ssl->arrays->masterSecret); #ifdef HAVE_SESSION_TICKET if (ssl->options.useTicket == 1) { session = &ssl->session; } #endif if (!session) { WOLFSSL_MSG("Session lookup for resume failed"); ssl->options.resuming = 0; } else { if (MatchSuite(ssl, &clSuites) < 0) { WOLFSSL_MSG("Unsupported cipher suite, OldClientHello"); return UNSUPPORTED_SUITE; } #ifdef SESSION_CERTS ssl->session = *session; /* restore session certs. */ #endif ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, RAN_LEN); if (ret != 0) return ret; #ifdef NO_OLD_TLS ret = DeriveTlsKeys(ssl); #else #ifndef NO_TLS if (ssl->options.tls) ret = DeriveTlsKeys(ssl); #endif if (!ssl->options.tls) ret = DeriveKeys(ssl); #endif ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; return ret; } } return MatchSuite(ssl, &clSuites); } #endif /* OLD_HELLO_ALLOWED */ static int DoClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, word32 helloSz) { byte b; ProtocolVersion pv; Suites clSuites; word32 i = *inOutIdx; word32 begin = i; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ClientHello", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("ClientHello", &ssl->timeoutInfo); #endif /* protocol version, random and session id length check */ if ((i - begin) + OPAQUE16_LEN + RAN_LEN + OPAQUE8_LEN > helloSz) return BUFFER_ERROR; /* protocol version */ XMEMCPY(&pv, input + i, OPAQUE16_LEN); ssl->chVersion = pv; /* store */ i += OPAQUE16_LEN; if (ssl->version.minor > pv.minor) { byte haveRSA = 0; byte havePSK = 0; if (!ssl->options.downgrade) { WOLFSSL_MSG("Client trying to connect with lesser version"); return VERSION_ERROR; } if (pv.minor < ssl->options.minDowngrade) { WOLFSSL_MSG(" version below minimum allowed, fatal error"); return VERSION_ERROR; } if (pv.minor == SSLv3_MINOR) { /* turn off tls */ WOLFSSL_MSG(" downgrading to SSLv3"); ssl->options.tls = 0; ssl->options.tls1_1 = 0; ssl->version.minor = SSLv3_MINOR; } else if (pv.minor == TLSv1_MINOR) { /* turn off tls 1.1+ */ WOLFSSL_MSG(" downgrading to TLSv1"); ssl->options.tls1_1 = 0; ssl->version.minor = TLSv1_MINOR; } else if (pv.minor == TLSv1_1_MINOR) { WOLFSSL_MSG(" downgrading to TLSv1.1"); ssl->version.minor = TLSv1_1_MINOR; } #ifndef NO_RSA haveRSA = 1; #endif #ifndef NO_PSK havePSK = ssl->options.havePSK; #endif InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, ssl->options.haveDH, ssl->options.haveNTRU, ssl->options.haveECDSAsig, ssl->options.haveStaticECC, ssl->options.side); } /* random */ XMEMCPY(ssl->arrays->clientRandom, input + i, RAN_LEN); i += RAN_LEN; #ifdef SHOW_SECRETS { int j; printf("client random: "); for (j = 0; j < RAN_LEN; j++) printf("%02x", ssl->arrays->clientRandom[j]); printf("\n"); } #endif /* session id */ b = input[i++]; if (b == ID_LEN) { if ((i - begin) + ID_LEN > helloSz) return BUFFER_ERROR; XMEMCPY(ssl->arrays->sessionID, input + i, ID_LEN); ssl->arrays->sessionIDSz = ID_LEN; i += ID_LEN; ssl->options.resuming = 1; /* client wants to resume */ WOLFSSL_MSG("Client wants to resume session"); } else if (b) { WOLFSSL_MSG("Invalid session ID size"); return BUFFER_ERROR; /* session ID nor 0 neither 32 bytes long */ } #ifdef WOLFSSL_DTLS /* cookie */ if (ssl->options.dtls) { if ((i - begin) + OPAQUE8_LEN > helloSz) return BUFFER_ERROR; b = input[i++]; if (b) { byte cookie[MAX_COOKIE_LEN]; if (b > MAX_COOKIE_LEN) return BUFFER_ERROR; if ((i - begin) + b > helloSz) return BUFFER_ERROR; if (ssl->ctx->CBIOCookie == NULL) { WOLFSSL_MSG("Your Cookie callback is null, please set"); return COOKIE_ERROR; } if ((ssl->ctx->CBIOCookie(ssl, cookie, COOKIE_SZ, ssl->IOCB_CookieCtx) != COOKIE_SZ) || (b != COOKIE_SZ) || (XMEMCMP(cookie, input + i, b) != 0)) { return COOKIE_ERROR; } i += b; } } #endif /* suites */ if ((i - begin) + OPAQUE16_LEN > helloSz) return BUFFER_ERROR; ato16(&input[i], &clSuites.suiteSz); i += OPAQUE16_LEN; /* suites and compression length check */ if ((i - begin) + clSuites.suiteSz + OPAQUE8_LEN > helloSz) return BUFFER_ERROR; if (clSuites.suiteSz > MAX_SUITE_SZ) return BUFFER_ERROR; XMEMCPY(clSuites.suites, input + i, clSuites.suiteSz); i += clSuites.suiteSz; clSuites.hashSigAlgoSz = 0; /* compression length */ b = input[i++]; if ((i - begin) + b > helloSz) return BUFFER_ERROR; if (ssl->options.usingCompression) { int match = 0; while (b--) { byte comp = input[i++]; if (comp == ZLIB_COMPRESSION) match = 1; } if (!match) { WOLFSSL_MSG("Not matching compression, turning off"); ssl->options.usingCompression = 0; /* turn off */ } } else i += b; /* ignore, since we're not on */ *inOutIdx = i; /* tls extensions */ if ((i - begin) < helloSz) { #ifdef HAVE_TLS_EXTENSIONS if (TLSX_SupportExtensions(ssl)) { int ret = 0; #else if (IsAtLeastTLSv1_2(ssl)) { #endif /* Process the hello extension. Skip unsupported. */ word16 totalExtSz; if ((i - begin) + OPAQUE16_LEN > helloSz) return BUFFER_ERROR; ato16(&input[i], &totalExtSz); i += OPAQUE16_LEN; if ((i - begin) + totalExtSz > helloSz) return BUFFER_ERROR; #ifdef HAVE_TLS_EXTENSIONS if ((ret = TLSX_Parse(ssl, (byte *) input + i, totalExtSz, 1, &clSuites))) return ret; i += totalExtSz; #else while (totalExtSz) { word16 extId, extSz; if (OPAQUE16_LEN + OPAQUE16_LEN > totalExtSz) return BUFFER_ERROR; ato16(&input[i], &extId); i += OPAQUE16_LEN; ato16(&input[i], &extSz); i += OPAQUE16_LEN; if (OPAQUE16_LEN + OPAQUE16_LEN + extSz > totalExtSz) return BUFFER_ERROR; if (extId == HELLO_EXT_SIG_ALGO) { ato16(&input[i], &clSuites.hashSigAlgoSz); i += OPAQUE16_LEN; if (OPAQUE16_LEN + clSuites.hashSigAlgoSz > extSz) return BUFFER_ERROR; XMEMCPY(clSuites.hashSigAlgo, &input[i], min(clSuites.hashSigAlgoSz, HELLO_EXT_SIGALGO_MAX)); i += clSuites.hashSigAlgoSz; if (clSuites.hashSigAlgoSz > HELLO_EXT_SIGALGO_MAX) clSuites.hashSigAlgoSz = HELLO_EXT_SIGALGO_MAX; } else i += extSz; totalExtSz -= OPAQUE16_LEN + OPAQUE16_LEN + extSz; } #endif *inOutIdx = i; } else *inOutIdx = begin + helloSz; /* skip extensions */ } ssl->options.clientState = CLIENT_HELLO_COMPLETE; ssl->options.haveSessionId = 1; /* ProcessOld uses same resume code */ if (ssl->options.resuming && (!ssl->options.dtls || ssl->options.acceptState == HELLO_VERIFY_SENT)) { /* let's try */ int ret = -1; WOLFSSL_SESSION* session = GetSession(ssl, ssl->arrays->masterSecret); #ifdef HAVE_SESSION_TICKET if (ssl->options.useTicket == 1) { session = &ssl->session; } #endif if (!session) { WOLFSSL_MSG("Session lookup for resume failed"); ssl->options.resuming = 0; } else { if (MatchSuite(ssl, &clSuites) < 0) { WOLFSSL_MSG("Unsupported cipher suite, ClientHello"); return UNSUPPORTED_SUITE; } #ifdef SESSION_CERTS ssl->session = *session; /* restore session certs. */ #endif ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, RAN_LEN); if (ret != 0) return ret; #ifdef NO_OLD_TLS ret = DeriveTlsKeys(ssl); #else #ifndef NO_TLS if (ssl->options.tls) ret = DeriveTlsKeys(ssl); #endif if (!ssl->options.tls) ret = DeriveKeys(ssl); #endif ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; return ret; } } return MatchSuite(ssl, &clSuites); } #if !defined(NO_RSA) || defined(HAVE_ECC) static int DoCertificateVerify(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size) { word16 sz = 0; int ret = VERIFY_CERT_ERROR; /* start in error state */ byte hashAlgo = sha_mac; byte sigAlgo = anonymous_sa_algo; word32 begin = *inOutIdx; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("CertificateVerify", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("CertificateVerify", &ssl->timeoutInfo); #endif if (IsAtLeastTLSv1_2(ssl)) { if ((*inOutIdx - begin) + ENUM_LEN + ENUM_LEN > size) return BUFFER_ERROR; hashAlgo = input[(*inOutIdx)++]; sigAlgo = input[(*inOutIdx)++]; } if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &sz); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + sz > size || sz > ENCRYPT_LEN) return BUFFER_ERROR; /* RSA */ #ifndef NO_RSA if (ssl->peerRsaKey != NULL && ssl->peerRsaKeyPresent != 0) { byte* out = NULL; int outLen = 0; byte doUserRsa = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->RsaVerifyCb) doUserRsa = 1; #endif /*HAVE_PK_CALLBACKS */ WOLFSSL_MSG("Doing RSA peer cert verify"); if (doUserRsa) { #ifdef HAVE_PK_CALLBACKS outLen = ssl->ctx->RsaVerifyCb(ssl, input + *inOutIdx, sz, &out, ssl->buffers.peerRsaKey.buffer, ssl->buffers.peerRsaKey.length, ssl->RsaVerifyCtx); #endif /*HAVE_PK_CALLBACKS */ } else { outLen = wc_RsaSSL_VerifyInline(input + *inOutIdx, sz, &out, ssl->peerRsaKey); } if (IsAtLeastTLSv1_2(ssl)) { #ifdef WOLFSSL_SMALL_STACK byte* encodedSig = NULL; #else byte encodedSig[MAX_ENCODED_SIG_SZ]; #endif word32 sigSz; byte* digest = ssl->hsHashes->certHashes.sha; int typeH = SHAh; int digestSz = SHA_DIGEST_SIZE; #ifdef WOLFSSL_SMALL_STACK encodedSig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encodedSig == NULL) return MEMORY_E; #endif if (sigAlgo != rsa_sa_algo) { WOLFSSL_MSG("Oops, peer sent RSA key but not in verify"); } if (hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = ssl->hsHashes->certHashes.sha256; typeH = SHA256h; digestSz = SHA256_DIGEST_SIZE; #endif } else if (hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = ssl->hsHashes->certHashes.sha384; typeH = SHA384h; digestSz = SHA384_DIGEST_SIZE; #endif } else if (hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = ssl->hsHashes->certHashes.sha512; typeH = SHA512h; digestSz = SHA512_DIGEST_SIZE; #endif } sigSz = wc_EncodeSignature(encodedSig, digest, digestSz, typeH); if (outLen == (int)sigSz && out && XMEMCMP(out, encodedSig, min(sigSz, MAX_ENCODED_SIG_SZ)) == 0) ret = 0; /* verified */ #ifdef WOLFSSL_SMALL_STACK XFREE(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif } else { if (outLen == FINISHED_SZ && out && XMEMCMP(out, &ssl->hsHashes->certHashes, FINISHED_SZ) == 0) { ret = 0; /* verified */ } } } #endif #ifdef HAVE_ECC if (ssl->peerEccDsaKeyPresent) { int verify = 0; int err = -1; byte* digest = ssl->hsHashes->certHashes.sha; word32 digestSz = SHA_DIGEST_SIZE; byte doUserEcc = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->EccVerifyCb) doUserEcc = 1; #endif WOLFSSL_MSG("Doing ECC peer cert verify"); if (IsAtLeastTLSv1_2(ssl)) { if (sigAlgo != ecc_dsa_sa_algo) { WOLFSSL_MSG("Oops, peer sent ECC key but not in verify"); } if (hashAlgo == sha256_mac) { #ifndef NO_SHA256 digest = ssl->hsHashes->certHashes.sha256; digestSz = SHA256_DIGEST_SIZE; #endif } else if (hashAlgo == sha384_mac) { #ifdef WOLFSSL_SHA384 digest = ssl->hsHashes->certHashes.sha384; digestSz = SHA384_DIGEST_SIZE; #endif } else if (hashAlgo == sha512_mac) { #ifdef WOLFSSL_SHA512 digest = ssl->hsHashes->certHashes.sha512; digestSz = SHA512_DIGEST_SIZE; #endif } } if (doUserEcc) { #ifdef HAVE_PK_CALLBACKS ret = ssl->ctx->EccVerifyCb(ssl, input + *inOutIdx, sz, digest, digestSz, ssl->buffers.peerEccDsaKey.buffer, ssl->buffers.peerEccDsaKey.length, &verify, ssl->EccVerifyCtx); #endif } else { err = wc_ecc_verify_hash(input + *inOutIdx, sz, digest, digestSz, &verify, ssl->peerEccDsaKey); } if (err == 0 && verify == 1) ret = 0; /* verified */ } #endif *inOutIdx += sz; if (ret == 0) ssl->options.havePeerVerify = 1; return ret; } #endif /* !NO_RSA || HAVE_ECC */ int SendServerHelloDone(WOLFSSL* ssl) { byte *output; int sendSz = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; int ret; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; #endif /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, 0, server_hello_done, ssl); #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) return 0; } #endif ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ServerHelloDone", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("ServerHelloDone", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->options.serverState = SERVER_HELLODONE_COMPLETE; ssl->buffers.outputBuffer.length += sendSz; return SendBuffered(ssl); } #ifdef HAVE_SESSION_TICKET #define WOLFSSL_TICKET_FIXED_SZ (WOLFSSL_TICKET_NAME_SZ + \ WOLFSSL_TICKET_IV_SZ + WOLFSSL_TICKET_MAC_SZ + LENGTH_SZ) #define WOLFSSL_TICKET_ENC_SZ (SESSION_TICKET_LEN - WOLFSSL_TICKET_FIXED_SZ) /* our ticket format */ typedef struct InternalTicket { ProtocolVersion pv; /* version when ticket created */ byte suite[SUITE_LEN]; /* cipher suite when created */ byte msecret[SECRET_LEN]; /* master secret */ word32 timestamp; /* born on */ } InternalTicket; /* fit within SESSION_TICKET_LEN */ typedef struct ExternalTicket { byte key_name[WOLFSSL_TICKET_NAME_SZ]; /* key context name */ byte iv[WOLFSSL_TICKET_IV_SZ]; /* this ticket's iv */ byte enc_len[LENGTH_SZ]; /* encrypted length */ byte enc_ticket[WOLFSSL_TICKET_ENC_SZ]; /* encrypted internal ticket */ byte mac[WOLFSSL_TICKET_MAC_SZ]; /* total mac */ /* !! if add to structure, add to TICKET_FIXED_SZ !! */ } ExternalTicket; /* create a new session ticket, 0 on success */ static int CreateTicket(WOLFSSL* ssl) { InternalTicket it; ExternalTicket* et = (ExternalTicket*)ssl->session.ticket; int encLen; int ret; byte zeros[WOLFSSL_TICKET_MAC_SZ]; /* biggest cmp size */ /* build internal */ it.pv.major = ssl->version.major; it.pv.minor = ssl->version.minor; it.suite[0] = ssl->options.cipherSuite0; it.suite[1] = ssl->options.cipherSuite; XMEMCPY(it.msecret, ssl->arrays->masterSecret, SECRET_LEN); c32toa(LowResTimer(), (byte*)&it.timestamp); /* build external */ XMEMCPY(et->enc_ticket, &it, sizeof(InternalTicket)); /* encrypt */ encLen = WOLFSSL_TICKET_ENC_SZ; /* max size user can use */ ret = ssl->ctx->ticketEncCb(ssl, et->key_name, et->iv, et->mac, 1, et->enc_ticket, sizeof(InternalTicket), &encLen, ssl->ctx->ticketEncCtx); if (ret == WOLFSSL_TICKET_RET_OK) { if (encLen < (int)sizeof(InternalTicket) || encLen > WOLFSSL_TICKET_ENC_SZ) { WOLFSSL_MSG("Bad user ticket encrypt size"); return BAD_TICKET_KEY_CB_SZ; } /* sanity checks on encrypt callback */ /* internal ticket can't be the same if encrypted */ if (XMEMCMP(et->enc_ticket, &it, sizeof(InternalTicket)) == 0) { WOLFSSL_MSG("User ticket encrypt didn't encrypt"); return BAD_TICKET_ENCRYPT; } XMEMSET(zeros, 0, sizeof(zeros)); /* name */ if (XMEMCMP(et->key_name, zeros, WOLFSSL_TICKET_NAME_SZ) == 0) { WOLFSSL_MSG("User ticket encrypt didn't set name"); return BAD_TICKET_ENCRYPT; } /* iv */ if (XMEMCMP(et->iv, zeros, WOLFSSL_TICKET_IV_SZ) == 0) { WOLFSSL_MSG("User ticket encrypt didn't set iv"); return BAD_TICKET_ENCRYPT; } /* mac */ if (XMEMCMP(et->mac, zeros, WOLFSSL_TICKET_MAC_SZ) == 0) { WOLFSSL_MSG("User ticket encrypt didn't set mac"); return BAD_TICKET_ENCRYPT; } /* set size */ c16toa((word16)encLen, et->enc_len); ssl->session.ticketLen = (word16)(encLen + WOLFSSL_TICKET_FIXED_SZ); if (encLen < WOLFSSL_TICKET_ENC_SZ) { /* move mac up since whole enc buffer not used */ XMEMMOVE(et->enc_ticket +encLen, et->mac,WOLFSSL_TICKET_MAC_SZ); } } return ret; } /* Parse ticket sent by client, returns callback return value */ int DoClientTicket(WOLFSSL* ssl, const byte* input, word32 len) { ExternalTicket* et; InternalTicket* it; int ret; int outLen; word16 inLen; if (len > SESSION_TICKET_LEN || len < (word32)(sizeof(InternalTicket) + WOLFSSL_TICKET_FIXED_SZ)) { return BAD_TICKET_MSG_SZ; } et = (ExternalTicket*)input; it = (InternalTicket*)et->enc_ticket; /* decrypt */ ato16(et->enc_len, &inLen); if (inLen > (word16)(len - WOLFSSL_TICKET_FIXED_SZ)) { return BAD_TICKET_MSG_SZ; } outLen = inLen; /* may be reduced by user padding */ ret = ssl->ctx->ticketEncCb(ssl, et->key_name, et->iv, et->enc_ticket + inLen, 0, et->enc_ticket, inLen, &outLen, ssl->ctx->ticketEncCtx); if (ret == WOLFSSL_TICKET_RET_FATAL || ret < 0) return ret; if (outLen > inLen || outLen < (int)sizeof(InternalTicket)) { WOLFSSL_MSG("Bad user ticket decrypt len"); return BAD_TICKET_KEY_CB_SZ; } /* get master secret */ if (ret == WOLFSSL_TICKET_RET_OK || ret == WOLFSSL_TICKET_RET_CREATE) XMEMCPY(ssl->arrays->masterSecret, it->msecret, SECRET_LEN); return ret; } /* send Session Ticket */ int SendTicket(WOLFSSL* ssl) { byte* output; int ret; int sendSz; word32 length = SESSION_HINT_SZ + LENGTH_SZ; word32 idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { length += DTLS_RECORD_EXTRA; idx += DTLS_RECORD_EXTRA; } #endif if (ssl->options.createTicket) { ret = CreateTicket(ssl); if (ret != 0) return ret; } length += ssl->session.ticketLen; sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, session_ticket, ssl); /* hint */ c32toa(ssl->ctx->ticketHint, output + idx); idx += SESSION_HINT_SZ; /* length */ c16toa(ssl->session.ticketLen, output + idx); idx += LENGTH_SZ; /* ticket */ XMEMCPY(output + idx, ssl->session.ticket, ssl->session.ticketLen); /* idx += ssl->session.ticketLen; */ ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; ssl->buffers.outputBuffer.length += sendSz; return SendBuffered(ssl); } #endif /* HAVE_SESSION_TICKET */ #ifdef WOLFSSL_DTLS int SendHelloVerifyRequest(WOLFSSL* ssl) { byte* output; byte cookieSz = COOKIE_SZ; int length = VERSION_SZ + ENUM_LEN + cookieSz; int idx = DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ; int sendSz = length + idx; int ret; /* check for available size */ if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) return ret; /* get ouput buffer */ output = ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.length; AddHeaders(output, length, hello_verify_request, ssl); output[idx++] = ssl->chVersion.major; output[idx++] = ssl->chVersion.minor; output[idx++] = cookieSz; if (ssl->ctx->CBIOCookie == NULL) { WOLFSSL_MSG("Your Cookie callback is null, please set"); return COOKIE_ERROR; } if ((ret = ssl->ctx->CBIOCookie(ssl, output + idx, cookieSz, ssl->IOCB_CookieCtx)) < 0) return ret; ret = HashOutput(ssl, output, sendSz, 0); if (ret != 0) return ret; #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("HelloVerifyRequest", &ssl->handShakeInfo); if (ssl->toInfoOn) AddPacketInfo("HelloVerifyRequest", &ssl->timeoutInfo, output, sendSz, ssl->heap); #endif ssl->options.serverState = SERVER_HELLOVERIFYREQUEST_COMPLETE; ssl->buffers.outputBuffer.length += sendSz; return SendBuffered(ssl); } #endif static int DoClientKeyExchange(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size) { int ret = 0; word32 length = 0; byte* out = NULL; word32 begin = *inOutIdx; (void)length; /* shut up compiler warnings */ (void)out; (void)input; (void)size; (void)begin; if (ssl->options.side != WOLFSSL_SERVER_END) { WOLFSSL_MSG("Client received client keyexchange, attack?"); WOLFSSL_ERROR(ssl->error = SIDE_ERROR); return SSL_FATAL_ERROR; } if (ssl->options.clientState < CLIENT_HELLO_COMPLETE) { WOLFSSL_MSG("Client sending keyexchange at wrong time"); SendAlert(ssl, alert_fatal, unexpected_message); return OUT_OF_ORDER_E; } #ifndef NO_CERTS if (ssl->options.verifyPeer && ssl->options.failNoCert) if (!ssl->options.havePeerCert) { WOLFSSL_MSG("client didn't present peer cert"); return NO_PEER_CERT; } #endif #ifdef WOLFSSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("ClientKeyExchange", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("ClientKeyExchange", &ssl->timeoutInfo); #endif switch (ssl->specs.kea) { #ifndef NO_RSA case rsa_kea: { word32 idx = 0; RsaKey key; byte doUserRsa = 0; #ifdef HAVE_PK_CALLBACKS if (ssl->ctx->RsaDecCb) doUserRsa = 1; #endif ret = wc_InitRsaKey(&key, ssl->heap); if (ret != 0) return ret; if (ssl->buffers.key.buffer) ret = wc_RsaPrivateKeyDecode(ssl->buffers.key.buffer, &idx, &key, ssl->buffers.key.length); else return NO_PRIVATE_KEY; if (ret == 0) { length = wc_RsaEncryptSize(&key); ssl->arrays->preMasterSz = SECRET_LEN; if (ssl->options.tls) { word16 check; if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &check); *inOutIdx += OPAQUE16_LEN; if ((word32) check != length) { WOLFSSL_MSG("RSA explicit size doesn't match"); wc_FreeRsaKey(&key); return RSA_PRIVATE_ERROR; } } if ((*inOutIdx - begin) + length > size) { WOLFSSL_MSG("RSA message too big"); wc_FreeRsaKey(&key); return BUFFER_ERROR; } if (doUserRsa) { #ifdef HAVE_PK_CALLBACKS ret = ssl->ctx->RsaDecCb(ssl, input + *inOutIdx, length, &out, ssl->buffers.key.buffer, ssl->buffers.key.length, ssl->RsaDecCtx); #endif } else { ret = wc_RsaPrivateDecryptInline(input + *inOutIdx, length, &out, &key); } *inOutIdx += length; if (ret == SECRET_LEN) { XMEMCPY(ssl->arrays->preMasterSecret, out, SECRET_LEN); if (ssl->arrays->preMasterSecret[0] != ssl->chVersion.major || ssl->arrays->preMasterSecret[1] != ssl->chVersion.minor) ret = PMS_VERSION_ERROR; else ret = MakeMasterSecret(ssl); } else { ret = RSA_PRIVATE_ERROR; } } wc_FreeRsaKey(&key); } break; #endif #ifndef NO_PSK case psk_kea: { byte* pms = ssl->arrays->preMasterSecret; word16 ci_sz; if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &ci_sz); *inOutIdx += OPAQUE16_LEN; if (ci_sz > MAX_PSK_ID_LEN) return CLIENT_ID_ERROR; if ((*inOutIdx - begin) + ci_sz > size) return BUFFER_ERROR; XMEMCPY(ssl->arrays->client_identity, input + *inOutIdx, ci_sz); *inOutIdx += ci_sz; ssl->arrays->client_identity[min(ci_sz, MAX_PSK_ID_LEN-1)] = 0; ssl->arrays->psk_keySz = ssl->options.server_psk_cb(ssl, ssl->arrays->client_identity, ssl->arrays->psk_key, MAX_PSK_KEY_LEN); if (ssl->arrays->psk_keySz == 0 || ssl->arrays->psk_keySz > MAX_PSK_KEY_LEN) return PSK_KEY_ERROR; /* make psk pre master secret */ /* length of key + length 0s + length of key + key */ c16toa((word16) ssl->arrays->psk_keySz, pms); pms += OPAQUE16_LEN; XMEMSET(pms, 0, ssl->arrays->psk_keySz); pms += ssl->arrays->psk_keySz; c16toa((word16) ssl->arrays->psk_keySz, pms); pms += OPAQUE16_LEN; XMEMCPY(pms, ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->preMasterSz = ssl->arrays->psk_keySz * 2 + 4; ret = MakeMasterSecret(ssl); /* No further need for PSK */ ForceZero(ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->psk_keySz = 0; } break; #endif /* NO_PSK */ #ifdef HAVE_NTRU case ntru_kea: { word16 cipherLen; word16 plainLen = sizeof(ssl->arrays->preMasterSecret); if (!ssl->buffers.key.buffer) return NO_PRIVATE_KEY; if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &cipherLen); *inOutIdx += OPAQUE16_LEN; if (cipherLen > MAX_NTRU_ENCRYPT_SZ) return NTRU_KEY_ERROR; if ((*inOutIdx - begin) + cipherLen > size) return BUFFER_ERROR; if (NTRU_OK != ntru_crypto_ntru_decrypt( (word16) ssl->buffers.key.length, ssl->buffers.key.buffer, cipherLen, input + *inOutIdx, &plainLen, ssl->arrays->preMasterSecret)) return NTRU_DECRYPT_ERROR; if (plainLen != SECRET_LEN) return NTRU_DECRYPT_ERROR; *inOutIdx += cipherLen; ssl->arrays->preMasterSz = plainLen; ret = MakeMasterSecret(ssl); } break; #endif /* HAVE_NTRU */ #ifdef HAVE_ECC case ecc_diffie_hellman_kea: { if ((*inOutIdx - begin) + OPAQUE8_LEN > size) return BUFFER_ERROR; length = input[(*inOutIdx)++]; if ((*inOutIdx - begin) + length > size) return BUFFER_ERROR; if (ssl->peerEccKey == NULL) { /* alloc/init on demand */ ssl->peerEccKey = (ecc_key*)XMALLOC(sizeof(ecc_key), ssl->ctx->heap, DYNAMIC_TYPE_ECC); if (ssl->peerEccKey == NULL) { WOLFSSL_MSG("PeerEccKey Memory error"); return MEMORY_E; } wc_ecc_init(ssl->peerEccKey); } else if (ssl->peerEccKeyPresent) { /* don't leak on reuse */ wc_ecc_free(ssl->peerEccKey); ssl->peerEccKeyPresent = 0; wc_ecc_init(ssl->peerEccKey); } if (wc_ecc_import_x963(input + *inOutIdx, length, ssl->peerEccKey)) return ECC_PEERKEY_ERROR; *inOutIdx += length; ssl->peerEccKeyPresent = 1; length = sizeof(ssl->arrays->preMasterSecret); if (ssl->specs.static_ecdh) { ecc_key staticKey; word32 i = 0; wc_ecc_init(&staticKey); ret = wc_EccPrivateKeyDecode(ssl->buffers.key.buffer, &i, &staticKey, ssl->buffers.key.length); if (ret == 0) ret = wc_ecc_shared_secret(&staticKey, ssl->peerEccKey, ssl->arrays->preMasterSecret, &length); wc_ecc_free(&staticKey); } else { if (ssl->eccTempKeyPresent == 0) { WOLFSSL_MSG("Ecc ephemeral key not made correctly"); ret = ECC_MAKEKEY_ERROR; } else { ret = wc_ecc_shared_secret(ssl->eccTempKey,ssl->peerEccKey, ssl->arrays->preMasterSecret, &length); } } if (ret != 0) return ECC_SHARED_ERROR; ssl->arrays->preMasterSz = length; ret = MakeMasterSecret(ssl); } break; #endif /* HAVE_ECC */ #ifndef NO_DH case diffie_hellman_kea: { word16 clientPubSz; DhKey dhKey; if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &clientPubSz); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + clientPubSz > size) return BUFFER_ERROR; wc_InitDhKey(&dhKey); ret = wc_DhSetKey(&dhKey, ssl->buffers.serverDH_P.buffer, ssl->buffers.serverDH_P.length, ssl->buffers.serverDH_G.buffer, ssl->buffers.serverDH_G.length); if (ret == 0) ret = wc_DhAgree(&dhKey, ssl->arrays->preMasterSecret, &ssl->arrays->preMasterSz, ssl->buffers.serverDH_Priv.buffer, ssl->buffers.serverDH_Priv.length, input + *inOutIdx, clientPubSz); wc_FreeDhKey(&dhKey); *inOutIdx += clientPubSz; if (ret == 0) ret = MakeMasterSecret(ssl); } break; #endif /* NO_DH */ #if !defined(NO_DH) && !defined(NO_PSK) case dhe_psk_kea: { byte* pms = ssl->arrays->preMasterSecret; word16 clientSz; DhKey dhKey; /* Read in the PSK hint */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &clientSz); *inOutIdx += OPAQUE16_LEN; if (clientSz > MAX_PSK_ID_LEN) return CLIENT_ID_ERROR; if ((*inOutIdx - begin) + clientSz > size) return BUFFER_ERROR; XMEMCPY(ssl->arrays->client_identity, input + *inOutIdx, clientSz); *inOutIdx += clientSz; ssl->arrays->client_identity[min(clientSz, MAX_PSK_ID_LEN-1)] = 0; /* Read in the DHE business */ if ((*inOutIdx - begin) + OPAQUE16_LEN > size) return BUFFER_ERROR; ato16(input + *inOutIdx, &clientSz); *inOutIdx += OPAQUE16_LEN; if ((*inOutIdx - begin) + clientSz > size) return BUFFER_ERROR; wc_InitDhKey(&dhKey); ret = wc_DhSetKey(&dhKey, ssl->buffers.serverDH_P.buffer, ssl->buffers.serverDH_P.length, ssl->buffers.serverDH_G.buffer, ssl->buffers.serverDH_G.length); if (ret == 0) ret = wc_DhAgree(&dhKey, pms + OPAQUE16_LEN, &ssl->arrays->preMasterSz, ssl->buffers.serverDH_Priv.buffer, ssl->buffers.serverDH_Priv.length, input + *inOutIdx, clientSz); wc_FreeDhKey(&dhKey); *inOutIdx += clientSz; c16toa((word16)ssl->arrays->preMasterSz, pms); ssl->arrays->preMasterSz += OPAQUE16_LEN; pms += ssl->arrays->preMasterSz; /* Use the PSK hint to look up the PSK and add it to the * preMasterSecret here. */ ssl->arrays->psk_keySz = ssl->options.server_psk_cb(ssl, ssl->arrays->client_identity, ssl->arrays->psk_key, MAX_PSK_KEY_LEN); if (ssl->arrays->psk_keySz == 0 || ssl->arrays->psk_keySz > MAX_PSK_KEY_LEN) return PSK_KEY_ERROR; c16toa((word16) ssl->arrays->psk_keySz, pms); pms += OPAQUE16_LEN; XMEMCPY(pms, ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->preMasterSz += ssl->arrays->psk_keySz + OPAQUE16_LEN; if (ret == 0) ret = MakeMasterSecret(ssl); /* No further need for PSK */ ForceZero(ssl->arrays->psk_key, ssl->arrays->psk_keySz); ssl->arrays->psk_keySz = 0; } break; #endif /* !NO_DH && !NO_PSK */ default: { WOLFSSL_MSG("Bad kea type"); ret = BAD_KEA_TYPE_E; } break; } /* No further need for PMS */ ForceZero(ssl->arrays->preMasterSecret, ssl->arrays->preMasterSz); ssl->arrays->preMasterSz = 0; if (ret == 0) { ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; #ifndef NO_CERTS if (ssl->options.verifyPeer) ret = BuildCertHashes(ssl, &ssl->hsHashes->certHashes); #endif } return ret; } #endif /* NO_WOLFSSL_SERVER */
31.700354
160
0.530754
83599fc77274abb0d6077fca0b7e77ae3eb59f92
2,217
h
C
ibulb/AFHttp.h
coderzzz/v
0bdd5267e1981e04028251c26637c854b586558a
[ "MIT" ]
null
null
null
ibulb/AFHttp.h
coderzzz/v
0bdd5267e1981e04028251c26637c854b586558a
[ "MIT" ]
null
null
null
ibulb/AFHttp.h
coderzzz/v
0bdd5267e1981e04028251c26637c854b586558a
[ "MIT" ]
null
null
null
// // AFHttp.h // HWSDK // // Created by Carl on 13-11-28. // Copyright (c) 2013年 helloworld. All rights reserved. // #import <Foundation/Foundation.h> #import "AFNetworking.h" #import "GCDAsyncSocket.h" @interface AFHttp : NSObject<GCDAsyncSocketDelegate> @property (nonatomic,readonly) AFHTTPRequestOperationManager * manager; @property (nonatomic, strong) GCDAsyncSocket *socket; + (AFHttp *)shareInstanced; - (void)connectToHost; - (void)get:(NSString *)url parameters:(NSDictionary *)parameters completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)post:(NSString *)url withParams:(NSDictionary *)params completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)reNameWithIP:(NSString *)ip name:(NSString *)name completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)reStroeWithIP:(NSString *)ip completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)joinGroupWithIP:(NSString *)ip completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)exitGroupWithIP:(NSString *)ip completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)joinToMasterWithIP:(NSString *)ip masterSSID:(NSString *)ssid channel:(NSString *)ch auth:(NSString *)auth encry:(NSString *)encry pwd:(NSString *)pwd completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)updateStartCheckWithIP:(NSString *)ip completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)updateStartWithIP:(NSString *)ip completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; - (void)updateStatusWithIP:(NSString *)ip completionBlock:(void (^)(id obj))success failureBlock:(void (^)(NSError * error,NSString * responseString))failure; @end
55.425
275
0.745602
26243c559ee41267465d9b435430c63a28655711
522
c
C
c&c++programs/pointer5.c
manishaverma1012/programs
dd77546219eab2f2ee81dd0d599b78ebd8f95957
[ "MIT" ]
null
null
null
c&c++programs/pointer5.c
manishaverma1012/programs
dd77546219eab2f2ee81dd0d599b78ebd8f95957
[ "MIT" ]
null
null
null
c&c++programs/pointer5.c
manishaverma1012/programs
dd77546219eab2f2ee81dd0d599b78ebd8f95957
[ "MIT" ]
null
null
null
#include<stdio.h> #include<math.h> void fun( int *, int *, int *, int *,int *); int main() { int a,b,c,d,e; printf(" Enter the value of numbers\n"); scanf("%d%d%d%d%d",&a, &b, &c, &d ,&e ); fun( &a,&b,&c,&d,&e); return 0; } void fun( int *x, int *y, int *z, int *w,int *p) { float sum , av ,std , q; sum = *x+*y+*z+*w+*p; av = sum / 5.0; q = (( av - *x)*( av - *x)+ ( av - *y)*( av - *y)+(av - *z)* ( av - *z)+ ( av - *w)*( av - *w)+ ( av - *p)*( av - *p)); std = sqrt( q); printf(" %f %f %f\n",sum , av, std); }
24.857143
120
0.448276
d3c4a206665caec28f49f3363b1e072de3b620af
4,140
c
C
hal/Startrampe/tmc/ADCs.c
trinamic/TMC-EvalSystem
b14433199055be35906533ec362d06124068a4b3
[ "MIT" ]
42
2019-01-25T13:30:34.000Z
2022-03-31T03:21:41.000Z
hal/Startrampe/tmc/ADCs.c
trinamic/TMC-EvalSystem
b14433199055be35906533ec362d06124068a4b3
[ "MIT" ]
26
2019-01-25T13:36:51.000Z
2022-03-29T03:46:46.000Z
hal/Startrampe/tmc/ADCs.c
trinamic/TMC-EvalSystem
b14433199055be35906533ec362d06124068a4b3
[ "MIT" ]
22
2019-06-04T13:15:11.000Z
2022-03-10T00:12:49.000Z
#include <math.h> #include "hal/HAL.h" #include "hal/ADCs.h" #define ADC1_DR_ADDRESS ((uint32_t)0x4001204C) static void init(void); static void deInit(void); ADCTypeDef ADCs = { .AIN0 = &ADCValue[0], .AIN1 = &ADCValue[1], .AIN2 = &ADCValue[2], .DIO4 = &ADCValue[3], .DIO5 = &ADCValue[4], .VM = &ADCValue[5], .init = init, .deInit = deInit }; void init(void) { ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; ADC_DeInit(); /* Enable peripheral clocks *************************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); HAL.IOs->config->reset(&HAL.IOs->pins->AIN0); HAL.IOs->config->reset(&HAL.IOs->pins->AIN1); HAL.IOs->config->reset(&HAL.IOs->pins->AIN2); HAL.IOs->config->reset(&HAL.IOs->pins->VM_MEAS); /* DMA2_Stream0 channel0 configuration **************************************/ DMA_DeInit(DMA2_Stream0); DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = N_O_ADC_CHANNELS; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); /* DMA2_Stream0 enable */ DMA_Cmd(DMA2_Stream0, ENABLE); /* ADC Common Init **********************************************************/ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC1 Init ****************************************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = N_O_ADC_CHANNELS; ADC_Init(ADC1, &ADC_InitStructure); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* ADC1 regular channel configuration ******************************/ ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 2, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 3, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 6, ADC_SampleTime_15Cycles); /* Enable DMA request after last transfer (Single-ADC mode) */ ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); /* Enable ADC1 **************************************************************/ ADC_Cmd(ADC1, ENABLE); ADC_SoftwareStartConv(ADC1); } static void deInit(void) { ADC_DeInit(); }
40.194175
80
0.692271
268ded3742cb3e3289b04929ab3d5309cc9e3c49
2,394
h
C
Cpp/SDK/BP_Shockwave_classes.h
MrManiak/Squad-SDK
742feb5991ae43d6f0cedd2d6b32b949923ca4f9
[ "Apache-2.0" ]
1
2020-08-15T08:31:55.000Z
2020-08-15T08:31:55.000Z
Cpp/SDK/BP_Shockwave_classes.h
MrManiak/Squad-SDK
742feb5991ae43d6f0cedd2d6b32b949923ca4f9
[ "Apache-2.0" ]
2
2020-08-15T08:43:56.000Z
2021-01-15T05:04:48.000Z
Cpp/SDK/BP_Shockwave_classes.h
MrManiak/Squad-SDK
742feb5991ae43d6f0cedd2d6b32b949923ca4f9
[ "Apache-2.0" ]
2
2020-08-10T12:05:42.000Z
2021-02-12T19:56:10.000Z
#pragma once // Name: S, Version: b #ifdef _MSC_VER #pragma pack(push, 0x01) #endif /*!!HELPER_DEF!!*/ /*!!DEFINE!!*/ namespace UFT { //--------------------------------------------------------------------------- // Classes //--------------------------------------------------------------------------- // BlueprintGeneratedClass BP_Shockwave.BP_Shockwave_C // 0x0028 (FullSize[0x0270] - InheritedSize[0x0248]) class ABP_Shockwave_C : public AActor { public: struct FPointerToUberGraphFrame UberGraphFrame; // 0x0248(0x0008) (ZeroConstructor, Transient, DuplicateTransient) class USceneComponent* ShockwaveRoot; // 0x0250(0x0008) (BlueprintVisible, ZeroConstructor, InstancedReference, IsPlainOldData, NonTransactional, NoDestructor, HasGetValueTypeHash) class UParticleSystem* Emitter_Being_Played; // 0x0258(0x0008) (Edit, BlueprintVisible, ZeroConstructor, IsPlainOldData, NoDestructor, ExposeOnSpawn, HasGetValueTypeHash) int VerticalSteps; // 0x0260(0x0004) (Edit, BlueprintVisible, ZeroConstructor, Config, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash) int HorizontalSteps; // 0x0264(0x0004) (Edit, BlueprintVisible, ZeroConstructor, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash) class UClass* EffectsClass; // 0x0268(0x0008) (Edit, BlueprintVisible, BlueprintReadOnly, ZeroConstructor, IsPlainOldData, NoDestructor, HasGetValueTypeHash) static UClass* StaticClass() { static auto ptr = UObject::FindClass("BlueprintGeneratedClass BP_Shockwave.BP_Shockwave_C"); return ptr; } void SpawnEmitterAtTraceIntersect(const struct FVector& StartTrace, const struct FVector& EndTrace, class AActor* Instigator); void ConvertStepsToLoops(int Steps, int* PositiveInt, int* NegativeInt); void Explode(class AActor* Instigator); void ReceiveBeginPlay(); void ExecuteUbergraph_BP_Shockwave(int EntryPoint); }; } #ifdef _MSC_VER #pragma pack(pop) #endif
45.169811
253
0.593567
8c1448273176222b3fb7a106a32b5fa9a5465f2f
18,353
c
C
animations/music-bars.c
marekpiechut/qmk-animations
857a769d639654dcc383229ffb7470a61d831f53
[ "MIT" ]
4
2021-07-10T09:24:03.000Z
2022-03-21T15:51:36.000Z
animations/music-bars.c
marekpiechut/qmk-animations
857a769d639654dcc383229ffb7470a61d831f53
[ "MIT" ]
null
null
null
animations/music-bars.c
marekpiechut/qmk-animations
857a769d639654dcc383229ffb7470a61d831f53
[ "MIT" ]
null
null
null
/** * Music bar animation with fast/slow typing mode * * ROTATION: * OLED_ROTATION_180 * * Copyright (c) Marek Piechut * MIT License */ #pragma once //-------- CONFIGURATION START -------- #ifndef FAST_TYPE_WPM #define FAST_TYPE_WPM 45 //Switch to fast animation when over words per minute #endif //-------- CONFIGURATION END-------- #define ANIM_SIZE 512 #define ANIM_FRAME 300 static void oled_render_anim(void) { // 'high2', 128x32px static const char ANIM_FRAME1 [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00 }; // 'high1', 128x32px static const char ANIM_FRAME2 [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00 }; // 'low3', 128x32px static const char ANIM_FRAME3 [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00 }; // 'low2', 128x32px static const char ANIM_FRAME4 [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00 }; // 'low', 128x32px static const char ANIM_FRAME5 [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00 }; static const char* FAST_TYPE_FRAMES [] = {ANIM_FRAME1, ANIM_FRAME2, ANIM_FRAME5}; static const char* SLOW_TYPE_FRAMES [] = {ANIM_FRAME5, ANIM_FRAME4, ANIM_FRAME3}; static char wpm_str[4]; void oled_render_speed(void) { sprintf(wpm_str, "%03d", get_current_wpm()); oled_set_cursor(0, 1); oled_write_P(PSTR("WPM"), false); oled_set_cursor(0, 2); oled_write(wpm_str, false); } static uint32_t anim_timer = 0; static uint8_t current_frame = 0; const uint8_t speed = get_current_wpm(); if (timer_elapsed32(anim_timer) > ANIM_FRAME) { anim_timer = timer_read32(); const char* frame = speed > FAST_TYPE_WPM ? FAST_TYPE_FRAMES[current_frame] : SLOW_TYPE_FRAMES[current_frame]; oled_write_raw_P(frame, ANIM_SIZE); current_frame = (current_frame + 1) % 3; oled_render_speed(); } }
79.795652
118
0.618536
145d2c3eed1dab4de37c06ea073e8b799185e8b4
254
h
C
protcomm/include/protcomm_export.h
funnyleecat/protocom
1165bc6c7b03c08324119e0712efb25b9c7208b0
[ "Apache-2.0" ]
null
null
null
protcomm/include/protcomm_export.h
funnyleecat/protocom
1165bc6c7b03c08324119e0712efb25b9c7208b0
[ "Apache-2.0" ]
null
null
null
protcomm/include/protcomm_export.h
funnyleecat/protocom
1165bc6c7b03c08324119e0712efb25b9c7208b0
[ "Apache-2.0" ]
null
null
null
#pragma once #ifdef WIN32 # ifdef PROTCOMM_EXPORTS # define PROTCOMM_API __declspec(dllexport) # else # define PROTCOMM_API __declspec(dllimport) # endif //PROTCOMM_EXPORTS #else # define PROTCOMM_API #endif //WIN32
19.538462
50
0.677165
88cee4b599a07abf33fef84d56f8434470e82218
3,198
h
C
include/cetty/channel/AdaptiveReceiveBufferSizePredictorFactory.h
frankee/Cetty
4ec5be459e42f3ef76617a5a9c8d70cee277d131
[ "BSL-1.0", "Apache-2.0", "BSD-3-Clause" ]
11
2015-01-22T11:23:23.000Z
2021-04-18T13:06:04.000Z
include/cetty/channel/AdaptiveReceiveBufferSizePredictorFactory.h
frankee/Cetty
4ec5be459e42f3ef76617a5a9c8d70cee277d131
[ "BSL-1.0", "Apache-2.0", "BSD-3-Clause" ]
null
null
null
include/cetty/channel/AdaptiveReceiveBufferSizePredictorFactory.h
frankee/Cetty
4ec5be459e42f3ef76617a5a9c8d70cee277d131
[ "BSL-1.0", "Apache-2.0", "BSD-3-Clause" ]
7
2015-04-17T08:13:04.000Z
2020-11-28T04:12:29.000Z
#if !defined(CETTY_CHANNEL_ADAPTIVERECEIVEBUFFERSIZEPREDICTORFACTORY_H) #define CETTY_CHANNEL_ADAPTIVERECEIVEBUFFERSIZEPREDICTORFACTORY_H /* * Copyright 2009 Red Hat, Inc. * * Red Hat licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ /* * Copyright (c) 2010-2011 frankee zhou (frankee.zhou at gmail dot com) * Distributed under under the Apache License, version 2.0 (the "License"). */ #include "cetty/channel/ReceiveBufferSizePredictorFactory.h" #include "cetty/channel/AdaptiveReceiveBufferSizePredictor.h" #include "cetty/util/Exception.h" namespace cetty { namespace channel { using namespace cetty::util; /** * The {@link ReceiveBufferSizePredictorFactory} that creates a new * {@link AdaptiveReceiveBufferSizePredictor}. * * * @author <a href="http://gleamynode.net/">Trustin Lee</a> * @author <a href="mailto:frankee.zhou@gmail.com">Frankee Zhou</a> */ class AdaptiveReceiveBufferSizePredictorFactory : public ReceiveBufferSizePredictorFactory { public: /** * Creates a new factory with the default parameters. With the default * parameters, the expected buffer size starts from <tt>1024</tt>, does not * go down below <tt>64</tt>, and does not go up above <tt>65536</tt>. */ AdaptiveReceiveBufferSizePredictorFactory() : minimum(AdaptiveReceiveBufferSizePredictor::DEFAULT_MINIMUM), initial(AdaptiveReceiveBufferSizePredictor::DEFAULT_INITIAL), maximum(AdaptiveReceiveBufferSizePredictor::DEFAULT_MAXIMUM) { } /** * Creates a new factory with the specified parameters. * * @param minimum the inclusive lower bound of the expected buffer size * @param initial the initial buffer size when no feed back was received * @param maximum the inclusive upper bound of the expected buffer size */ AdaptiveReceiveBufferSizePredictorFactory(int minimum, int initial, int maximum) : minimum(minimum), initial(initial), maximum(maximum) { if (minimum <= 0) { throw InvalidArgumentException("minimum is less than zero."); } if (initial < minimum) { throw InvalidArgumentException("initial is less than zero."); } if (maximum < initial) { throw InvalidArgumentException("maximum is less than zero."); } } virtual ~AdaptiveReceiveBufferSizePredictorFactory() {} virtual ReceiveBufferSizePredictor* getPredictor() { return new AdaptiveReceiveBufferSizePredictor(minimum, initial, maximum); } private: int minimum; int initial; int maximum; }; }} #endif //#if !defined(CETTY_CHANNEL_ADAPTIVERECEIVEBUFFERSIZEPREDICTORFACTORY_H)
36.340909
92
0.720138
bb5102109fb09dff06af7c4ccbcc19135834985c
2,645
h
C
network-manager-applet/shared/nm-default.h
apiraino/sway-ubuntu-build
bb774627867b2b72d5e149f870330933b10bba30
[ "MIT" ]
null
null
null
network-manager-applet/shared/nm-default.h
apiraino/sway-ubuntu-build
bb774627867b2b72d5e149f870330933b10bba30
[ "MIT" ]
null
null
null
network-manager-applet/shared/nm-default.h
apiraino/sway-ubuntu-build
bb774627867b2b72d5e149f870330933b10bba30
[ "MIT" ]
null
null
null
/* NetworkManager -- Network link manager * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * * (C) Copyright 2015 Red Hat, Inc. */ #ifndef __NM_DEFAULT_H__ #define __NM_DEFAULT_H__ /* makefiles define NETWORKMANAGER_COMPILATION for compiling NetworkManager. * Depending on which parts are compiled, different values are set. */ #define NM_NETWORKMANAGER_COMPILATION_DEFAULT 0x0001 #define NM_NETWORKMANAGER_COMPILATION_LIB 0x0002 #define NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY 0x0004 #ifndef NETWORKMANAGER_COMPILATION /* For convenience, we don't require our Makefile.am to define * -DNETWORKMANAGER_COMPILATION. As we now include this internal header, * we know we do a NETWORKMANAGER_COMPILATION. */ #define NETWORKMANAGER_COMPILATION NM_NETWORKMANAGER_COMPILATION_DEFAULT #endif /*****************************************************************************/ /* always include these headers for our internal source files. */ #ifndef ___CONFIG_H__ #define ___CONFIG_H__ #include <config.h> #endif #include <stdlib.h> #include <glib.h> #include "nm-utils/nm-macros-internal.h" #include <nm-version.h> #include <gtk/gtk.h> /*****************************************************************************/ #if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) #define LIBNM_BUILD 1 #else #define LIBNM_BUILD 0 #endif #if ((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_LIB) || ((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) #include <glib/gi18n-lib.h> #else #include <glib/gi18n.h> #endif #if ((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) #include <nm-connection.h> #else #include <NetworkManager.h> #endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ #include "nm-libnm-compat.h" /*****************************************************************************/ #endif /* __NM_DEFAULT_H__ */
32.256098
147
0.702457
9bb5a0f3b831284de16e757a82d608ba999f0121
2,858
h
C
zircon/tools/fidl/include/fidl/type_shape.h
OpenTrustGroup/fuchsia
647e593ea661b8bf98dcad2096e20e8950b24a97
[ "BSD-3-Clause" ]
1
2019-04-21T18:02:26.000Z
2019-04-21T18:02:26.000Z
zircon/tools/fidl/include/fidl/type_shape.h
OpenTrustGroup/fuchsia
647e593ea661b8bf98dcad2096e20e8950b24a97
[ "BSD-3-Clause" ]
16
2020-09-04T19:01:11.000Z
2021-05-28T03:23:09.000Z
zircon/tools/fidl/include/fidl/type_shape.h
OpenTrustGroup/fuchsia
647e593ea661b8bf98dcad2096e20e8950b24a97
[ "BSD-3-Clause" ]
null
null
null
// Copyright 2018 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef ZIRCON_TOOLS_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_ #define ZIRCON_TOOLS_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_ #include <cstdint> class TypeShape { public: constexpr TypeShape(uint32_t size, uint32_t alignment, uint32_t depth = 0u, uint32_t max_handles = 0u, uint32_t max_out_of_line = 0u, bool has_padding = false) : size_(size), alignment_(alignment), depth_(depth), max_handles_(max_handles), max_out_of_line_(max_out_of_line), has_padding_(has_padding) {} constexpr TypeShape() : TypeShape(0u, 0u, 0u, 0u, 0u, false) {} TypeShape(const TypeShape&) = default; TypeShape& operator=(const TypeShape&) = default; uint32_t Size() const { return size_; } uint32_t Alignment() const { return alignment_; } uint32_t Depth() const { return depth_; } // These properties are accounted for recursively. uint32_t MaxHandles() const { return max_handles_; } uint32_t MaxOutOfLine() const { return max_out_of_line_; } bool HasPadding() const { return has_padding_; } private: uint32_t size_; uint32_t alignment_; uint32_t depth_; uint32_t max_handles_; uint32_t max_out_of_line_; bool has_padding_; }; // |FieldShape| describes a |TypeShape| that is embedded in a struct or (x)union as a member field. // It contains additional offset and padding information. class FieldShape { public: // Constructs a |FieldShape| with zero offset and padding. // The offset and padding can be updated via |SetOffset| and |SetPadding| respectively. explicit FieldShape(TypeShape typeshape) : typeshape_(typeshape), offset_(0), padding_(0) {} FieldShape() : FieldShape(TypeShape()) {} TypeShape& Typeshape() { return typeshape_; } const TypeShape& Typeshape() const { return typeshape_; } uint32_t Size() const { return typeshape_.Size(); } uint32_t Alignment() const { return typeshape_.Alignment(); } uint32_t Depth() const { return typeshape_.Depth(); } uint32_t Offset() const { return offset_; } // Padding after this field until the next field or the end of the container. // See // https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/languages/fidl/reference/wire-format/README.md#size-and-alignment uint32_t Padding() const { return padding_; } uint32_t MaxHandles() const { return typeshape_.MaxHandles(); } uint32_t MaxOutOfLine() const { return typeshape_.MaxOutOfLine(); } void SetOffset(uint32_t offset) { offset_ = offset; } void SetPadding(uint32_t padding) { padding_ = padding; } private: TypeShape typeshape_; uint32_t offset_; uint32_t padding_; }; #endif // ZIRCON_TOOLS_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_
35.725
137
0.726032
af87c57315ae26dcfa500f6a7b0921881fe05161
35,588
c
C
Reloaded/trunk/src/mame/video/jaguar.c
lofunz/mieme
4226c2960b46121ec44fa8eab9717d2d644bff04
[ "Unlicense" ]
51
2015-11-22T14:53:28.000Z
2021-12-14T07:17:42.000Z
Reloaded/trunk/src/mame/video/jaguar.c
lofunz/mieme
4226c2960b46121ec44fa8eab9717d2d644bff04
[ "Unlicense" ]
8
2018-01-14T07:19:06.000Z
2021-08-22T15:29:59.000Z
Reloaded/trunk/src/mame/video/jaguar.c
lofunz/mieme
4226c2960b46121ec44fa8eab9717d2d644bff04
[ "Unlicense" ]
35
2017-02-15T09:39:00.000Z
2021-12-14T07:17:43.000Z
/*************************************************************************** Atari Jaguar hardware **************************************************************************** ------------------------------------------------------------ TOM REGISTERS ------------------------------------------------------------ F00000-F0FFFF R/W xxxxxxxx xxxxxxxx Internal Registers F00000 R/W -x-xx--- xxxxxxxx MEMCON1 - memory config reg 1 -x------ -------- (CPU32 - is the CPU 32bits?) ---xx--- -------- (IOSPEED - external I/O clock cycles) -------- x------- (FASTROM - reduces ROM clock cycles) -------- -xx----- (DRAMSPEED - sets RAM clock cycles) -------- ---xx--- (ROMSPEED - sets ROM clock cycles) -------- -----xx- (ROMWIDTH - sets width of ROM: 8,16,32,64 bits) -------- -------x (ROMHI - controls ROM mapping) F00002 R/W --xxxxxx xxxxxxxx MEMCON2 - memory config reg 2 --x----- -------- (HILO - image display bit order) ---x---- -------- (BIGEND - big endian addressing?) ----xxxx -------- (REFRATE - DRAM refresh rate) -------- xx------ (DWIDTH1 - DRAM1 width: 8,16,32,64 bits) -------- --xx---- (COLS1 - DRAM1 columns: 256,512,1024,2048) -------- ----xx-- (DWIDTH0 - DRAM0 width: 8,16,32,64 bits) -------- ------xx (COLS0 - DRAM0 columns: 256,512,1024,2048) F00004 R/W -----xxx xxxxxxxx HC - horizontal count -----x-- -------- (which half of the display) ------xx xxxxxxxx (10-bit counter) F00006 R/W ----xxxx xxxxxxxx VC - vertical count ----x--- -------- (which field is being generated) -----xxx xxxxxxxx (11-bit counter) F00008 R -----xxx xxxxxxxx LPH - light pen horizontal position F0000A R -----xxx xxxxxxxx LPV - light pen vertical position F00010-F00017 R xxxxxxxx xxxxxxxx OB - current object code from the graphics processor F00020-F00023 W xxxxxxxx xxxxxxxx OLP - start of the object list F00026 W -------- -------x OBF - object processor flag F00028 W ----xxxx xxxxxxxx VMODE - video mode W ----xxx- -------- (PWIDTH1-8 - width of pixel in video clock cycles) W -------x -------- (VARMOD - enable variable color resolution) W -------- x------- (BGEN - clear line buffere to BG color) W -------- -x------ (CSYNC - enable composite sync on VSYNC) W -------- --x----- (BINC - local border color if INCEN) W -------- ---x---- (INCEN - encrustation enable) W -------- ----x--- (GENLOCK - enable genlock) W -------- -----xx- (MODE - CRY16,RGB24,DIRECT16,RGB16) W -------- -------x (VIDEN - enables video) F0002A W xxxxxxxx xxxxxxxx BORD1 - border color (red/green) F0002C W -------- xxxxxxxx BORD2 - border color (blue) F0002E W ------xx xxxxxxxx HP - horizontal period F00030 W -----xxx xxxxxxxx HBB - horizontal blanking begin F00032 W -----xxx xxxxxxxx HBE - horizontal blanking end F00034 W -----xxx xxxxxxxx HSYNC - horizontal sync F00036 W ------xx xxxxxxxx HVS - horizontal vertical sync F00038 W -----xxx xxxxxxxx HDB1 - horizontal display begin 1 F0003A W -----xxx xxxxxxxx HDB2 - horizontal display begin 2 F0003C W -----xxx xxxxxxxx HDE - horizontal display end F0003E W -----xxx xxxxxxxx VP - vertical period F00040 W -----xxx xxxxxxxx VBB - vertical blanking begin F00042 W -----xxx xxxxxxxx VBE - vertical blanking end F00044 W -----xxx xxxxxxxx VS - vertical sync F00046 W -----xxx xxxxxxxx VDB - vertical display begin F00048 W -----xxx xxxxxxxx VDE - vertical display end F0004A W -----xxx xxxxxxxx VEB - vertical equalization begin F0004C W -----xxx xxxxxxxx VEE - vertical equalization end F0004E W -----xxx xxxxxxxx VI - vertical interrupt F00050 W xxxxxxxx xxxxxxxx PIT0 - programmable interrupt timer 0 F00052 W xxxxxxxx xxxxxxxx PIT1 - programmable interrupt timer 1 F00054 W ------xx xxxxxxxx HEQ - horizontal equalization end F00058 W xxxxxxxx xxxxxxxx BG - background color F000E0 R/W ---xxxxx ---xxxxx INT1 - CPU interrupt control register ---x---- -------- (C_JERCLR - clear pending Jerry ints) ----x--- -------- (C_PITCLR - clear pending PIT ints) -----x-- -------- (C_OPCLR - clear pending object processor ints) ------x- -------- (C_GPUCLR - clear pending graphics processor ints) -------x -------- (C_VIDCLR - clear pending video timebase ints) -------- ---x---- (C_JERENA - enable Jerry ints) -------- ----x--- (C_PITENA - enable PIT ints) -------- -----x-- (C_OPENA - enable object processor ints) -------- ------x- (C_GPUENA - enable graphics processor ints) -------- -------x (C_VIDENA - enable video timebase ints) F000E2 W -------- -------- INT2 - CPU interrupt resume register F00400-F005FF R/W xxxxxxxx xxxxxxxx CLUT - color lookup table A F00600-F007FF R/W xxxxxxxx xxxxxxxx CLUT - color lookup table B F00800-F00D9F R/W xxxxxxxx xxxxxxxx LBUF - line buffer A F01000-F0159F R/W xxxxxxxx xxxxxxxx LBUF - line buffer B F01800-F01D9F R/W xxxxxxxx xxxxxxxx LBUF - line buffer currently selected ------------------------------------------------------------ F02000-F021FF R/W xxxxxxxx xxxxxxxx GPU control registers F02100 R/W xxxxxxxx xxxxxxxx G_FLAGS - GPU flags register R/W x------- -------- (DMAEN - DMA enable) R/W -x------ -------- (REGPAGE - register page) W --x----- -------- (G_BLITCLR - clear blitter interrupt) W ---x---- -------- (G_OPCLR - clear object processor int) W ----x--- -------- (G_PITCLR - clear PIT interrupt) W -----x-- -------- (G_JERCLR - clear Jerry interrupt) W ------x- -------- (G_CPUCLR - clear CPU interrupt) R/W -------x -------- (G_BLITENA - enable blitter interrupt) R/W -------- x------- (G_OPENA - enable object processor int) R/W -------- -x------ (G_PITENA - enable PIT interrupt) R/W -------- --x----- (G_JERENA - enable Jerry interrupt) R/W -------- ---x---- (G_CPUENA - enable CPU interrupt) R/W -------- ----x--- (IMASK - interrupt mask) R/W -------- -----x-- (NEGA_FLAG - ALU negative) R/W -------- ------x- (CARRY_FLAG - ALU carry) R/W -------- -------x (ZERO_FLAG - ALU zero) F02104 W -------- ----xxxx G_MTXC - matrix control register W -------- ----x--- (MATCOL - column/row major) W -------- -----xxx (MATRIX3-15 - matrix width) F02108 W ----xxxx xxxxxx-- G_MTXA - matrix address register F0210C W -------- -----xxx G_END - data organization register W -------- -----x-- (BIG_INST - big endian instruction fetch) W -------- ------x- (BIG_PIX - big endian pixels) W -------- -------x (BIG_IO - big endian I/O) F02110 R/W xxxxxxxx xxxxxxxx G_PC - GPU program counter F02114 R/W xxxxxxxx xx-xxxxx G_CTRL - GPU control/status register R xxxx---- -------- (VERSION - GPU version code) R/W ----x--- -------- (BUS_HOG - hog the bus!) R/W -----x-- -------- (G_BLITLAT - blitter interrupt latch) R/W ------x- -------- (G_OPLAT - object processor int latch) R/W -------x -------- (G_PITLAT - PIT interrupt latch) R/W -------- x------- (G_JERLAT - Jerry interrupt latch) R/W -------- -x------ (G_CPULAT - CPU interrupt latch) R/W -------- ---x---- (SINGLE_GO - single step one instruction) R/W -------- ----x--- (SINGLE_STEP - single step mode) R/W -------- -----x-- (FORCEINT0 - cause interrupt 0 on GPU) R/W -------- ------x- (CPUINT - send GPU interrupt to CPU) R/W -------- -------x (GPUGO - enable GPU execution) F02118-F0211B R/W xxxxxxxx xxxxxxxx G_HIDATA - high data register F0211C-F0211F R xxxxxxxx xxxxxxxx G_REMAIN - divide unit remainder F0211C W -------- -------x G_DIVCTRL - divide unit control W -------- -------x (DIV_OFFSET - 1=16.16 divide, 0=32-bit divide) ------------------------------------------------------------ ****************************************************************************/ #include "emu.h" #include "memconv.h" #include "profiler.h" #include "machine/atarigen.h" #include "cpu/mips/r3000.h" #include "cpu/m68000/m68000.h" #include "includes/jaguar.h" #include "jagblit.h" #define ENABLE_BORDERS 0 #define LOG_BLITS 0 #define LOG_BAD_BLITS 0 #define LOG_BLITTER_STATS 0 #define LOG_BLITTER_WRITE 0 #define LOG_UNHANDLED_BLITS 0 // interrupts to main CPU: // 0 = video (on the VI scanline) // 1 = GPU (write from GPU coprocessor) // 2 = object (stop object interrupt in display list) // 3 = timer (from the PIT) // 4 = jerry /* GPU registers */ enum { MEMCON1, MEMCON2, HC, VC, LPH, LPV, GPU0, GPU1, OB_HH, OB_HL, OB_LH, OB_LL, GPU2, GPU3, GPU4, GPU5, OLP_L, OLP_H, GPU6, OBF, VMODE, BORD1, BORD2, HP, HBB, HBE, HSYNC, HVS, HDB1, HDB2, HDE, VP, VBB, VBE, VS, VDB, VDE, VEB, VEE, VI, PIT0, PIT1, HEQ, GPU7, BG, INT1 = 0xe0/2, INT2, GPU_REGS }; /************************************* * * Local variables * *************************************/ /* blitter variables */ static UINT32 blitter_regs[BLITTER_REGS]; static UINT16 gpu_regs[GPU_REGS]; static emu_timer *object_timer; static UINT8 cpu_irq_state; static bitmap_t *screen_bitmap; static pen_t *pen_table; UINT8 blitter_status; /************************************* * * Prototypes * *************************************/ /* from jagobj.c */ static void jagobj_init(running_machine *machine); static void process_object_list(running_machine *machine, int vc, UINT16 *_scanline); /* from jagblit.c */ static void generic_blitter(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_09800001_010020_010020(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_09800009_000020_000020(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_01800009_000028_000028(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_01800001_000018_000018(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_01c00001_000018_000018(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); #ifdef MESS static void blitter_00010000_xxxxxx_xxxxxx(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_01800001_xxxxxx_xxxxxx(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); static void blitter_x1800x01_xxxxxx_xxxxxx(running_machine *machine, UINT32 command, UINT32 a1flags, UINT32 a2flags); #endif /************************************* * * Compute X/Y coordinates * *************************************/ INLINE void get_crosshair_xy(running_machine *machine, int player, int *x, int *y) { const rectangle &visarea = machine->primary_screen->visible_area(); int width = visarea.max_x + 1 - visarea.min_x; int height = visarea.max_y + 1 - visarea.min_y; /* only 2 lightguns are connected */ *x = visarea.min_x + (((input_port_read(machine, player ? "FAKE2_X" : "FAKE1_X") & 0xff) * width) >> 8); *y = visarea.min_y + (((input_port_read(machine, player ? "FAKE2_Y" : "FAKE1_Y") & 0xff) * height) >> 8); } /************************************* * * Horizontal display values * *************************************/ INLINE int effective_hvalue(int value) { if (!(value & 0x400)) return value & 0x3ff; else return (value & 0x3ff) + (gpu_regs[HP] & 0x3ff) + 1; } /************************************* * * Object processor timer * *************************************/ INLINE int adjust_object_timer(running_machine *machine, int vc) { int hdbpix[2]; int hdb = 0; /* extract the display begin registers */ hdbpix[0] = (gpu_regs[HDB1] & 0x7ff) / 2; hdbpix[1] = (gpu_regs[HDB2] & 0x7ff) / 2; /* sort */ if (hdbpix[0] > hdbpix[1]) { int temp = hdbpix[0]; hdbpix[0] = hdbpix[1]; hdbpix[1] = temp; } /* select the target one */ hdb = hdbpix[vc % 2]; /* if setting the second one in a line, make sure we will ever actually hit it */ if (vc % 2 == 1 && (hdbpix[1] == hdbpix[0] || hdbpix[1] >= machine->primary_screen->width())) return FALSE; /* adjust the timer */ timer_adjust_oneshot(object_timer, machine->primary_screen->time_until_pos(vc / 2, hdb), vc | (hdb << 16)); return TRUE; } /************************************* * * GPU optimization control * *************************************/ void jaguar_gpu_suspend(running_machine *machine) { machine->device<cpu_device>("gpu")->suspend(SUSPEND_REASON_SPIN, 1); } void jaguar_gpu_resume(running_machine *machine) { machine->device<cpu_device>("gpu")->resume(SUSPEND_REASON_SPIN); } /************************************* * * Main CPU interrupts * *************************************/ static void update_cpu_irq(running_machine *machine) { if (cpu_irq_state & gpu_regs[INT1] & 0x1f) cputag_set_input_line(machine, "maincpu", cojag_is_r3000 ? R3000_IRQ4 : M68K_IRQ_6, ASSERT_LINE); else cputag_set_input_line(machine, "maincpu", cojag_is_r3000 ? R3000_IRQ4 : M68K_IRQ_6, CLEAR_LINE); } void jaguar_gpu_cpu_int(running_device *device) { cpu_irq_state |= 2; update_cpu_irq(device->machine); } void jaguar_dsp_cpu_int(running_device *device) { cpu_irq_state |= 16; update_cpu_irq(device->machine); } /************************************* * * Palette init * *************************************/ static void jaguar_set_palette(UINT16 vmode) { static const UINT8 red_lookup[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 19, 0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 64, 43, 21, 0, 102,102,102,102,102,102,102,102,102,102,102, 95, 71, 47, 23, 0, 135,135,135,135,135,135,135,135,135,135,130,104, 78, 52, 26, 0, 169,169,169,169,169,169,169,169,169,170,141,113, 85, 56, 28, 0, 203,203,203,203,203,203,203,203,203,183,153,122, 91, 61, 30, 0, 237,237,237,237,237,237,237,237,230,197,164,131, 98, 65, 32, 0, 255,255,255,255,255,255,255,255,247,214,181,148,115, 82, 49, 17, 255,255,255,255,255,255,255,255,255,235,204,173,143,112, 81, 51, 255,255,255,255,255,255,255,255,255,255,227,198,170,141,113, 85, 255,255,255,255,255,255,255,255,255,255,249,223,197,171,145,119, 255,255,255,255,255,255,255,255,255,255,255,248,224,200,177,153, 255,255,255,255,255,255,255,255,255,255,255,255,252,230,208,187, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,240,221, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 }; static const UINT8 grn_lookup[256] = { 0, 17, 34, 51, 68, 85,102,119,136,153,170,187,204,221,238,255, 0, 19, 38, 57, 77, 96,115,134,154,173,182,211,231,250,255,255, 0, 21, 43, 64, 86,107,129,150,172,193,215,236,255,255,255,255, 0, 23, 47, 71, 96,119,142,166,190,214,238,255,255,255,255,255, 0, 26, 52, 78,104,130,156,182,208,234,255,255,255,255,255,255, 0, 28, 56, 85,113,141,170,198,226,255,255,255,255,255,255,255, 0, 30, 61, 91,122,153,183,214,244,255,255,255,255,255,255,255, 0, 32, 65, 98,131,164,197,230,255,255,255,255,255,255,255,255, 0, 32, 65, 98,131,164,197,230,255,255,255,255,255,255,255,255, 0, 30, 61, 91,122,153,183,214,244,255,255,255,255,255,255,255, 0, 28, 56, 85,113,141,170,198,226,255,255,255,255,255,255,255, 0, 26, 52, 78,104,130,156,182,208,234,255,255,255,255,255,255, 0, 23, 47, 71, 96,119,142,166,190,214,238,255,255,255,255,255, 0, 21, 43, 64, 86,107,129,150,172,193,215,236,255,255,255,255, 0, 19, 38, 57, 77, 96,115,134,154,173,182,211,231,250,255,255, 0, 17, 34, 51, 68, 85,102,119,136,153,170,187,204,221,238,255 }; static const UINT8 blu_lookup[256] = { 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,240,221, 255,255,255,255,255,255,255,255,255,255,255,255,252,230,208,187, 255,255,255,255,255,255,255,255,255,255,255,248,224,200,177,153, 255,255,255,255,255,255,255,255,255,255,249,223,197,171,145,119, 255,255,255,255,255,255,255,255,255,255,227,198,170,141,113, 85, 255,255,255,255,255,255,255,255,255,235,204,173,143,112, 81, 51, 255,255,255,255,255,255,255,255,247,214,181,148,115, 82, 49, 17, 237,237,237,237,237,237,237,237,230,197,164,131, 98, 65, 32, 0, 203,203,203,203,203,203,203,203,203,183,153,122, 91, 61, 30, 0, 169,169,169,169,169,169,169,169,169,170,141,113, 85, 56, 28, 0, 135,135,135,135,135,135,135,135,135,135,130,104, 78, 52, 26, 0, 102,102,102,102,102,102,102,102,102,102,102, 95, 71, 47, 23, 0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 64, 43, 21, 0, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int i; /* switch off the mode */ switch (vmode & 0x106) { /* YCC full */ case 0x000: /* RGB24 */ case 0x002: for (i = 0; i < 65536; i++) { UINT8 r = (red_lookup[i >> 8] * (i & 0xff)) >> 8; UINT8 g = (grn_lookup[i >> 8] * (i & 0xff)) >> 8; UINT8 b = (blu_lookup[i >> 8] * (i & 0xff)) >> 8; pen_table[i] = MAKE_RGB(r, g, b); } break; /* YCC VARMOD */ case 0x100: for (i = 0; i < 65536; i++) { UINT8 r = (red_lookup[i >> 8] * (i & 0xff)) >> 8; UINT8 g = (grn_lookup[i >> 8] * (i & 0xff)) >> 8; UINT8 b = (blu_lookup[i >> 8] * (i & 0xff)) >> 8; /* if the low bit is set, treat it as 5-5-5 RGB instead */ if (i & 1) { r = (i >> 11) & 31; g = (i >> 1) & 31; b = (i >> 6) & 31; r = (r << 3) | (r >> 2); g = (g << 3) | (g >> 2); b = (b << 3) | (b >> 2); } pen_table[i] = MAKE_RGB(r, g, b); } break; /* RGB VARMOD */ case 0x106: for (i = 0; i < 65536; i++) { if (i & 1) // FIXME: controls RGB 5-5-5 / 5-6-5 format or it's just ignored? Used by UBI Soft logo in Rayman pen_table[i] = MAKE_RGB(pal5bit(i >> 11), pal5bit(i >> 1), pal5bit(i >> 6)); else pen_table[i] = MAKE_RGB(pal5bit(i >> 11), pal6bit(i >> 0), pal5bit(i >> 6)); } break; /* RGB full */ case 0x006: for (i = 0; i < 65536; i++) pen_table[i] = MAKE_RGB(pal5bit(i >> 11), pal6bit(i >> 0), pal5bit(i >> 6)); break; /* others */ default: logerror("Can't handle mode %X\n", vmode); fprintf(stderr, "Can't handle mode %X\n", vmode); break; } } /************************************* * * Fast memory accessors * *************************************/ static UINT8 *get_jaguar_memory(running_machine *machine, UINT32 offset) { const address_space *space = cputag_get_address_space(machine, "gpu", ADDRESS_SPACE_PROGRAM); return (UINT8 *)memory_get_read_ptr(space, offset); } /************************************* * * 32-bit access to the blitter * *************************************/ static void blitter_run(running_machine *machine) { UINT32 command = blitter_regs[B_CMD] & STATIC_COMMAND_MASK; UINT32 a1flags = blitter_regs[A1_FLAGS] & STATIC_FLAGS_MASK; UINT32 a2flags = blitter_regs[A2_FLAGS] & STATIC_FLAGS_MASK; profiler_mark_start(PROFILER_USER1); if (a1flags == a2flags) { if (command == 0x09800001 && a1flags == 0x010020) { blitter_09800001_010020_010020(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } if (command == 0x09800009 && a1flags == 0x000020) { blitter_09800009_000020_000020(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } if (command == 0x01800009 && a1flags == 0x000028) { blitter_01800009_000028_000028(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } if (command == 0x01800001 && a1flags == 0x000018) { blitter_01800001_000018_000018(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } if (command == 0x01c00001 && a1flags == 0x000018) { blitter_01c00001_000018_000018(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } } #ifdef MESS if (command == 0x00010000) { blitter_00010000_xxxxxx_xxxxxx(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } if (command == 0x01800001) { blitter_01800001_xxxxxx_xxxxxx(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } if ((command & 0x0ffff0ff) == 0x01800001) { blitter_x1800x01_xxxxxx_xxxxxx(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); return; } #endif if (LOG_BLITTER_STATS) { static UINT32 blitter_stats[1000][4]; static UINT64 blitter_pixels[1000]; static int blitter_count = 0; static int reps = 0; int i; for (i = 0; i < blitter_count; i++) if (blitter_stats[i][0] == (blitter_regs[B_CMD] & STATIC_COMMAND_MASK) && blitter_stats[i][1] == (blitter_regs[A1_FLAGS] & STATIC_FLAGS_MASK) && blitter_stats[i][2] == (blitter_regs[A2_FLAGS] & STATIC_FLAGS_MASK)) break; if (i == blitter_count) { blitter_stats[i][0] = blitter_regs[B_CMD] & STATIC_COMMAND_MASK; blitter_stats[i][1] = blitter_regs[A1_FLAGS] & STATIC_FLAGS_MASK; blitter_stats[i][2] = blitter_regs[A2_FLAGS] & STATIC_FLAGS_MASK; blitter_stats[i][3] = 0; blitter_pixels[i] = 0; blitter_count++; } blitter_stats[i][3]++; blitter_pixels[i] += (blitter_regs[B_COUNT] & 0xffff) * (blitter_regs[B_COUNT] >> 16); if (++reps % 100 == 99) { mame_printf_debug("---\nBlitter stats:\n"); for (i = 0; i < blitter_count; i++) mame_printf_debug(" CMD=%08X A1=%08X A2=%08X %6d times, %08X%08X pixels\n", blitter_stats[i][0], blitter_stats[i][1], blitter_stats[i][2], blitter_stats[i][3], (UINT32)(blitter_pixels[i] >> 32), (UINT32)(blitter_pixels[i])); mame_printf_debug("---\n"); } } generic_blitter(machine, blitter_regs[B_CMD], blitter_regs[A1_FLAGS], blitter_regs[A2_FLAGS]); profiler_mark_end(); } static TIMER_CALLBACK( blitter_done ) { blitter_status = 1; } READ32_HANDLER( jaguar_blitter_r ) { switch (offset) { case B_CMD: /* B_CMD */ return blitter_status & 3; default: logerror("%08X:Blitter read register @ F022%02X\n", cpu_get_previouspc(space->cpu), offset * 4); return 0; } } WRITE32_HANDLER( jaguar_blitter_w ) { COMBINE_DATA(&blitter_regs[offset]); if (offset == B_CMD) { blitter_status = 0; timer_set(space->machine, ATTOTIME_IN_USEC(100), NULL, 0, blitter_done); blitter_run(space->machine); } if (LOG_BLITTER_WRITE) logerror("%08X:Blitter write register @ F022%02X = %08X\n", cpu_get_previouspc(space->cpu), offset * 4, data); } /************************************* * * 16-bit TOM register access * *************************************/ READ16_HANDLER( jaguar_tom_regs_r ) { if (offset != INT1 && offset != INT2 && offset != HC && offset != VC) logerror("%08X:TOM read register @ F00%03X\n", cpu_get_previouspc(space->cpu), offset * 2); switch (offset) { case INT1: return cpu_irq_state; case HC: return space->machine->primary_screen->hpos() % (space->machine->primary_screen->width() / 2); case VC: { UINT8 half_line; if(space->machine->primary_screen->hpos() >= (space->machine->primary_screen->width() / 2)) half_line = 1; else half_line = 0; return space->machine->primary_screen->vpos() * 2 + half_line; } } return gpu_regs[offset]; } #if 0 static TIMER_CALLBACK( jaguar_pit ) { attotime sample_period; cpu_irq_state |= 4; update_cpu_irq(machine); if (gpu_regs[PIT0]) { sample_period = ATTOTIME_IN_NSEC(machine->device("gpu")->unscaled_clock() / (1+gpu_regs[PIT0]) / (1+gpu_regs[PIT1])); // timer_set(machine, sample_period, NULL, 0, jaguar_pit); } } #endif WRITE16_HANDLER( jaguar_tom_regs_w ) { UINT32 reg_store = gpu_regs[offset]; // attotime sample_period; if (offset < GPU_REGS) { COMBINE_DATA(&gpu_regs[offset]); switch (offset) { case MEMCON1: if((gpu_regs[offset] & 1) == 0) printf("Warning: ROMHI = 0!\n"); break; case PIT0: case PIT1: if(gpu_regs[PIT0] && reg_store != gpu_regs[offset]) printf("Warning: PIT irq used\n"); break; #if 0 case PIT1: if (gpu_regs[PIT0]) { sample_period = ATTOTIME_IN_NSEC(space->machine->device("gpu")->unscaled_clock() / (1+gpu_regs[PIT0]) / (1+gpu_regs[PIT1])); timer_set(space->machine, sample_period, NULL, 0, jaguar_pit); } break; #endif case INT1: cpu_irq_state &= ~(gpu_regs[INT1] >> 8); update_cpu_irq(space->machine); break; case VMODE: if (reg_store != gpu_regs[offset]) jaguar_set_palette(gpu_regs[VMODE]); break; case OBF: /* clear GPU interrupt */ cpu_irq_state &= 0xfd; update_cpu_irq(space->machine); break; case HP: case HBB: case HBE: case HDB1: case HDB2: case HDE: case VP: case VBB: case VBE: case VDB: case VDE: { if (reg_store != gpu_regs[offset]) { int hperiod = 2 * ((gpu_regs[HP] & 0x3ff) + 1); int hbend = effective_hvalue(ENABLE_BORDERS ? gpu_regs[HBE] : MIN(gpu_regs[HDB1], gpu_regs[HDB2])); int hbstart = effective_hvalue(gpu_regs[ENABLE_BORDERS ? HBB : HDE]); int vperiod = (gpu_regs[VP] & 0x7ff) + 1; int vbend = MAX(gpu_regs[VBE],gpu_regs[VDB]) & 0x7ff; int vbstart = gpu_regs[VBB] & 0x7ff; /* adjust for the half-lines */ if (hperiod != 0 && vperiod != 0 && hbend < hbstart && vbend < vbstart && hbstart < hperiod) { rectangle visarea; visarea.min_x = hbend / 2; visarea.max_x = hbstart / 2 - 1; visarea.min_y = vbend / 2; visarea.max_y = vbstart / 2 - 1; space->machine->primary_screen->configure(hperiod / 2, vperiod / 2, visarea, HZ_TO_ATTOSECONDS((double)COJAG_PIXEL_CLOCK * 2 / hperiod / vperiod)); } } break; } } } if (offset != INT2 && offset != VI && offset != INT1) logerror("%08X:TOM write register @ F00%03X = %04X\n", cpu_get_previouspc(space->cpu), offset * 2, data); } /************************************* * * 32-bit TOM register access * *************************************/ READ32_HANDLER( jaguar_tom_regs32_r ) { return read32be_with_16be_handler(jaguar_tom_regs_r, space, offset, mem_mask); } WRITE32_HANDLER( jaguar_tom_regs32_w ) { write32be_with_16be_handler(jaguar_tom_regs_w, space, offset, data, mem_mask); } /************************************* * * Gun input * *************************************/ READ32_HANDLER( cojag_gun_input_r ) { int beamx, beamy; switch (offset) { case 0: get_crosshair_xy(space->machine, 1, &beamx, &beamy); return (beamy << 16) | (beamx ^ 0x1ff); case 1: get_crosshair_xy(space->machine, 0, &beamx, &beamy); return (beamy << 16) | (beamx ^ 0x1ff); case 2: return input_port_read(space->machine, "IN3"); } return 0; } /************************************* * * Video system start * *************************************/ static TIMER_CALLBACK( cojag_scanline_update ) { int vc = param & 0xffff; int hdb = param >> 16; const rectangle &visarea = machine->primary_screen->visible_area(); /* only run if video is enabled and we are past the "display begin" */ if ((gpu_regs[VMODE] & 1) && vc >= (gpu_regs[VDB] & 0x7ff)) { UINT32 *dest = BITMAP_ADDR32(screen_bitmap, vc >> 1, 0); int maxx = visarea.max_x; int hde = effective_hvalue(gpu_regs[HDE]) >> 1; UINT16 x,scanline[760]; UINT8 y,pixel_width = ((gpu_regs[VMODE]>>10)&3)+1; /* if we are first on this scanline, clear to the border color */ if (ENABLE_BORDERS && vc % 2 == 0) { rgb_t border = MAKE_RGB(gpu_regs[BORD1] & 0xff, gpu_regs[BORD1] >> 8, gpu_regs[BORD2] & 0xff); for (x = visarea.min_x; x <= visarea.max_x; x++) dest[x] = border; } /* process the object list for this counter value */ process_object_list(machine, vc, scanline); /* copy the data to the target, clipping */ if ((gpu_regs[VMODE] & 0x106) == 0x002) /* RGB24 */ { for (x = 0; x < 760 && hdb <= maxx && hdb < hde; x+=2) for (y = 0; y < pixel_width; y++) { UINT8 r = pen_table[(scanline[x]&0xff)|256]; UINT8 g = pen_table[(scanline[x]>>8)|512]; UINT8 b = pen_table[scanline[x+1]&0xff]; dest[hdb++] = MAKE_RGB(r, g, b); } } else { for (x = 0; x < 760 && hdb <= maxx && hdb < hde; x++) for (y = 0; y < pixel_width; y++) dest[hdb++] = pen_table[scanline[x]]; } } /* adjust the timer in a loop, to handle missed cases */ do { /* handle vertical interrupts */ if (vc == gpu_regs[VI]) { cpu_irq_state |= 1; update_cpu_irq(machine); } /* point to the next counter value */ if (++vc / 2 >= machine->primary_screen->height()) vc = 0; } while (!adjust_object_timer(machine, vc)); } static STATE_POSTLOAD( cojag_postload ) { update_cpu_irq(machine); } VIDEO_START( cojag ) { memset(&blitter_regs, 0, sizeof(blitter_regs)); memset(&gpu_regs, 0, sizeof(gpu_regs)); cpu_irq_state = 0; object_timer = timer_alloc(machine, cojag_scanline_update, NULL); adjust_object_timer(machine, 0); screen_bitmap = auto_bitmap_alloc(machine, 760, 512, BITMAP_FORMAT_RGB32); jagobj_init(machine); pen_table = auto_alloc_array(machine, pen_t, 65536); state_save_register_global_pointer(machine, pen_table, 65536); state_save_register_global_array(machine, blitter_regs); state_save_register_global_array(machine, gpu_regs); state_save_register_global(machine, cpu_irq_state); state_save_register_postload(machine, cojag_postload, NULL); } /************************************* * * Main refresh * *************************************/ VIDEO_UPDATE( cojag ) { /* if not enabled, just blank */ if (!(gpu_regs[VMODE] & 1)) { bitmap_fill(bitmap, cliprect, 0); return 0; } /* render the object list */ copybitmap(bitmap, screen_bitmap, 0, 0, 0, 0, cliprect); return 0; } /************************************* * * Object processor * *************************************/ #define INCLUDE_OBJECT_PROCESSOR #include "jagobj.c" /************************************* * * Blitter macros * *************************************/ /* generic blitters */ #define FUNCNAME generic_blitter #define COMMAND command #define A1FIXED a1flags #define A2FIXED a2flags #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME /* optimized common blitters */ #define FUNCNAME blitter_09800001_010020_010020 #define COMMAND 0x09800001 #define A1FIXED 0x010020 #define A2FIXED 0x010020 #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #define FUNCNAME blitter_09800009_000020_000020 #define COMMAND 0x09800009 #define A1FIXED 0x000020 #define A2FIXED 0x000020 #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #define FUNCNAME blitter_01800009_000028_000028 #define COMMAND 0x01800009 #define A1FIXED 0x000028 #define A2FIXED 0x000028 #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #define FUNCNAME blitter_01800001_000018_000018 #define COMMAND 0x01800001 #define A1FIXED 0x000018 #define A2FIXED 0x000018 #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #define FUNCNAME blitter_01c00001_000018_000018 #define COMMAND 0x01c00001 #define A1FIXED 0x000018 #define A2FIXED 0x000018 #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #ifdef MESS #define FUNCNAME blitter_00010000_xxxxxx_xxxxxx #define COMMAND 0x00010000 #define A1FIXED a1flags #define A2FIXED a2flags #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #define FUNCNAME blitter_01800001_xxxxxx_xxxxxx #define COMMAND 0x01800001 #define A1FIXED a1flags #define A2FIXED a2flags #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #define FUNCNAME blitter_x1800x01_xxxxxx_xxxxxx #define COMMAND ((command & 0xf0000f00) | 0x01800001) #define A1FIXED a1flags #define A2FIXED a2flags #include "jagblit.c" #undef A2FIXED #undef A1FIXED #undef COMMAND #undef FUNCNAME #endif /* MESS */
33.668874
154
0.553248
3b07a19081ed133f22eab1006b0cd7ca98b99431
31,248
c
C
mi8/drivers/staging/qca-wifi-host-cmn/umac/scan/dispatcher/src/wlan_scan_utils_api.c
wqk317/mi8_kernel_source
e3482d1a7ea6021de2fc8f3178496b4b043bb727
[ "MIT" ]
null
null
null
mi8/drivers/staging/qca-wifi-host-cmn/umac/scan/dispatcher/src/wlan_scan_utils_api.c
wqk317/mi8_kernel_source
e3482d1a7ea6021de2fc8f3178496b4b043bb727
[ "MIT" ]
null
null
null
mi8/drivers/staging/qca-wifi-host-cmn/umac/scan/dispatcher/src/wlan_scan_utils_api.c
wqk317/mi8_kernel_source
e3482d1a7ea6021de2fc8f3178496b4b043bb727
[ "MIT" ]
null
null
null
/* * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. * * 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. */ /* * DOC: Defines scan utility functions */ #include <wlan_cmn.h> #include <wlan_scan_ucfg_api.h> #include <wlan_scan_utils_api.h> #include <../../core/src/wlan_scan_cache_db.h> #include <../../core/src/wlan_scan_main.h> #include <wlan_reg_services_api.h> const char* util_scan_get_ev_type_name(enum scan_event_type type) { static const char * const event_name[] = { [SCAN_EVENT_TYPE_STARTED] = "STARTED", [SCAN_EVENT_TYPE_COMPLETED] = "COMPLETED", [SCAN_EVENT_TYPE_BSS_CHANNEL] = "HOME_CHANNEL", [SCAN_EVENT_TYPE_FOREIGN_CHANNEL] = "FOREIGN_CHANNEL", [SCAN_EVENT_TYPE_DEQUEUED] = "DEQUEUED", [SCAN_EVENT_TYPE_PREEMPTED] = "PREEMPTED", [SCAN_EVENT_TYPE_START_FAILED] = "START_FAILED", [SCAN_EVENT_TYPE_RESTARTED] = "RESTARTED", [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_EXIT] = "FOREIGN_CHANNEL_EXIT", [SCAN_EVENT_TYPE_SUSPENDED] = "SUSPENDED", [SCAN_EVENT_TYPE_RESUMED] = "RESUMED", [SCAN_EVENT_TYPE_NLO_COMPLETE] = "NLO_COMPLETE", [SCAN_EVENT_TYPE_NLO_MATCH] = "NLO_MATCH", [SCAN_EVENT_TYPE_INVALID] = "INVALID", [SCAN_EVENT_TYPE_GPIO_TIMEOUT] = "GPIO_TIMEOUT", [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_START] = "RADIO_MEASUREMENT_START", [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_END] = "RADIO_MEASUREMENT_END", [SCAN_EVENT_TYPE_BSSID_MATCH] = "BSSID_MATCH", [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_GET_NF] = "FOREIGN_CHANNEL_GET_NF", }; if (type >= SCAN_EVENT_TYPE_MAX) return "UNKNOWN"; return event_name[type]; } const char* util_scan_get_ev_reason_name(enum scan_completion_reason reason) { static const char * const reason_name[] = { [SCAN_REASON_NONE] = "NONE", [SCAN_REASON_COMPLETED] = "COMPLETED", [SCAN_REASON_CANCELLED] = "CANCELLED", [SCAN_REASON_PREEMPTED] = "PREEMPTED", [SCAN_REASON_TIMEDOUT] = "TIMEDOUT", [SCAN_REASON_INTERNAL_FAILURE] = "INTERNAL_FAILURE", [SCAN_REASON_SUSPENDED] = "SUSPENDED", [SCAN_REASON_RUN_FAILED] = "RUN_FAILED", [SCAN_REASON_TERMINATION_FUNCTION] = "TERMINATION_FUNCTION", [SCAN_REASON_MAX_OFFCHAN_RETRIES] = "MAX_OFFCHAN_RETRIES", }; if (reason >= SCAN_REASON_MAX) return "UNKNOWN"; return reason_name[reason]; } qdf_time_t util_get_last_scan_time(struct wlan_objmgr_vdev *vdev) { uint8_t pdev_id; struct wlan_scan_obj *scan_obj; if (!vdev) { scm_warn("null vdev"); QDF_ASSERT(0); return 0; } pdev_id = wlan_scan_vdev_get_pdev_id(vdev); scan_obj = wlan_vdev_get_scan_obj(vdev); if (scan_obj) return scan_obj->pdev_info[pdev_id].last_scan_time; else return 0; } enum wlan_band util_scan_scm_chan_to_band(uint32_t chan) { if (WLAN_CHAN_IS_2GHZ(chan)) return WLAN_BAND_2_4_GHZ; return WLAN_BAND_5_GHZ; } enum wlan_band util_scan_scm_freq_to_band(uint16_t freq) { if (WLAN_REG_IS_24GHZ_CH_FREQ(freq)) return WLAN_BAND_2_4_GHZ; return WLAN_BAND_5_GHZ; } bool util_is_scan_entry_match( struct scan_cache_entry *entry1, struct scan_cache_entry *entry2) { if (entry1->cap_info.wlan_caps.ess != entry2->cap_info.wlan_caps.ess) return false; if (entry1->cap_info.wlan_caps.ess && !qdf_mem_cmp(entry1->bssid.bytes, entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) { /* Check for BSS */ if (util_is_ssid_match(&entry1->ssid, &entry2->ssid) || util_scan_is_null_ssid(&entry1->ssid) || util_scan_is_null_ssid(&entry2->ssid)) return true; } else if (entry1->cap_info.wlan_caps.ibss && (entry1->channel.chan_idx == entry2->channel.chan_idx)) { /* * Same channel cannot have same SSID for * different IBSS, so no need to check BSSID */ if (util_is_ssid_match( &entry1->ssid, &entry2->ssid)) return true; } else if (!entry1->cap_info.wlan_caps.ibss && !entry1->cap_info.wlan_caps.ess && !qdf_mem_cmp(entry1->bssid.bytes, entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) { /* In case of P2P devices, ess and ibss will be set to zero */ return true; } return false; } static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates) { static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108}; bool pureg = false; uint8_t i, j; for (i = 0; i < nrates; i++) { for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) { if (WLAN_RV(rates[i]) == g_rates[j]) { pureg = true; break; } } if (pureg) break; } return pureg; } static enum wlan_phymode util_scan_get_phymode_5g(struct scan_cache_entry *scan_params) { enum wlan_phymode phymode = WLAN_PHYMODE_AUTO; uint16_t ht_cap = 0; struct htcap_cmn_ie *htcap; struct wlan_ie_htinfo_cmn *htinfo; struct wlan_ie_vhtop *vhtop; htcap = (struct htcap_cmn_ie *) util_scan_entry_htcap(scan_params); htinfo = (struct wlan_ie_htinfo_cmn *) util_scan_entry_htinfo(scan_params); vhtop = (struct wlan_ie_vhtop *) util_scan_entry_vhtop(scan_params); if (!(htcap && htinfo)) return WLAN_PHYMODE_11A; if (htcap) ht_cap = le16toh(htcap->hc_cap); if (ht_cap & WLAN_HTCAP_C_CHWIDTH40) phymode = WLAN_PHYMODE_11NA_HT40; else phymode = WLAN_PHYMODE_11NA_HT20; if (util_scan_entry_vhtcap(scan_params) && vhtop) { switch (vhtop->vht_op_chwidth) { case WLAN_VHTOP_CHWIDTH_2040: if (ht_cap & WLAN_HTCAP_C_CHWIDTH40) phymode = WLAN_PHYMODE_11AC_VHT40; else phymode = WLAN_PHYMODE_11AC_VHT20; break; case WLAN_VHTOP_CHWIDTH_80: if (WLAN_IS_REVSIG_VHT80_80(vhtop)) phymode = WLAN_PHYMODE_11AC_VHT80_80; else if (WLAN_IS_REVSIG_VHT160(vhtop)) phymode = WLAN_PHYMODE_11AC_VHT160; else phymode = WLAN_PHYMODE_11AC_VHT80; break; case WLAN_VHTOP_CHWIDTH_160: phymode = WLAN_PHYMODE_11AC_VHT160; break; case WLAN_VHTOP_CHWIDTH_80_80: phymode = WLAN_PHYMODE_11AC_VHT80_80; break; default: scm_err("bad channel: %d", vhtop->vht_op_chwidth); phymode = WLAN_PHYMODE_11AC_VHT20; break; } } return phymode; } static enum wlan_phymode util_scan_get_phymode_2g(struct scan_cache_entry *scan_params) { enum wlan_phymode phymode = WLAN_PHYMODE_AUTO; uint16_t ht_cap = 0; struct htcap_cmn_ie *htcap; struct wlan_ie_htinfo_cmn *htinfo; struct wlan_ie_vhtop *vhtop; htcap = (struct htcap_cmn_ie *) util_scan_entry_htcap(scan_params); htinfo = (struct wlan_ie_htinfo_cmn *) util_scan_entry_htinfo(scan_params); vhtop = (struct wlan_ie_vhtop *) util_scan_entry_vhtop(scan_params); if (htcap) ht_cap = le16toh(htcap->hc_cap); if (htcap && htinfo) { if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE)) phymode = WLAN_PHYMODE_11NG_HT40PLUS; else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW)) phymode = WLAN_PHYMODE_11NG_HT40MINUS; else phymode = WLAN_PHYMODE_11NG_HT20; } else if (util_scan_entry_xrates(scan_params)) { /* only 11G stations will have more than 8 rates */ phymode = WLAN_PHYMODE_11G; } else { /* Some mischievous g-only APs do not set extended rates */ if (util_scan_entry_rates(scan_params)) { if (util_is_pureg_rate(&scan_params->ie_list.rates[2], scan_params->ie_list.rates[1])) phymode = WLAN_PHYMODE_11G; else phymode = WLAN_PHYMODE_11B; } else { phymode = WLAN_PHYMODE_11B; } } /* Check for VHT only if HT cap is present */ if (!IS_WLAN_PHYMODE_HT(phymode)) return phymode; if (util_scan_entry_vhtcap(scan_params) && vhtop) { switch (vhtop->vht_op_chwidth) { case WLAN_VHTOP_CHWIDTH_2040: if (phymode == WLAN_PHYMODE_11NG_HT40PLUS) phymode = WLAN_PHYMODE_11AC_VHT40PLUS_2G; else if (phymode == WLAN_PHYMODE_11NG_HT40MINUS) phymode = WLAN_PHYMODE_11AC_VHT40MINUS_2G; else phymode = WLAN_PHYMODE_11AC_VHT20_2G; break; default: scm_info("bad vht_op_chwidth: %d", vhtop->vht_op_chwidth); phymode = WLAN_PHYMODE_11AC_VHT20_2G; break; } } return phymode; } static QDF_STATUS util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params, struct ie_header *sub_ie, qdf_size_t sub_ie_len) { /* Walk through to check nothing is malformed */ while (sub_ie_len >= sizeof(struct ie_header)) { /* At least one more header is present */ sub_ie_len -= sizeof(struct ie_header); if (sub_ie->ie_len == 0) { sub_ie += 1; continue; } if (sub_ie_len < sub_ie->ie_len) { scm_err("Incomplete corrupted IE:%x", WLAN_ELEMID_CHAN_SWITCH_WRAP); return QDF_STATUS_E_INVAL; } switch (sub_ie->ie_id) { case WLAN_ELEMID_COUNTRY: scan_params->ie_list.country = (uint8_t *)sub_ie; break; case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH: scan_params->ie_list.widebw = (uint8_t *)sub_ie; break; case WLAN_ELEMID_VHT_TX_PWR_ENVLP: scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie; break; } /* Consume sub info element */ sub_ie_len -= sub_ie->ie_len; /* go to next Sub IE */ sub_ie = (struct ie_header *) (((uint8_t *) sub_ie) + sizeof(struct ie_header) + sub_ie->ie_len); } return QDF_STATUS_SUCCESS; } bool util_scan_is_hidden_ssid(struct ie_ssid *ssid) { uint8_t i; /* * We flag this as Hidden SSID if the Length is 0 * of the SSID only contains 0's */ if (!ssid || !ssid->ssid_len) return true; for (i = 0; i < ssid->ssid_len; i++) if (ssid->ssid[i] != 0) return false; /* All 0's */ return true; } static QDF_STATUS util_scan_parse_extn_ie(struct scan_cache_entry *scan_params, struct ie_header *ie) { struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie; switch (extn_ie->ie_extn_id) { case WLAN_EXTN_ELEMID_SRP: scan_params->ie_list.srp = (uint8_t *)ie; break; case WLAN_EXTN_ELEMID_HECAP: scan_params->ie_list.hecap = (uint8_t *)ie; break; case WLAN_EXTN_ELEMID_HEOP: scan_params->ie_list.heop = (uint8_t *)ie; break; case WLAN_EXTN_ELEMID_ESP: scan_params->ie_list.esp = (uint8_t *)ie; break; case WLAN_EXTN_ELEMID_MUEDCA: scan_params->ie_list.muedca = (uint8_t *)ie; break; default: break; } return QDF_STATUS_SUCCESS; } static QDF_STATUS util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params, struct ie_header *ie) { if (scan_params->ie_list.vendor == NULL) scan_params->ie_list.vendor = (uint8_t *)ie; if (is_wpa_oui((uint8_t *)ie)) { scan_params->ie_list.wpa = (uint8_t *)ie; } else if (is_wps_oui((uint8_t *)ie)) { scan_params->ie_list.wps = (uint8_t *)ie; /* WCN IE should be a subset of WPS IE */ if (is_wcn_oui((uint8_t *)ie)) scan_params->ie_list.wcn = (uint8_t *)ie; } else if (is_wme_param((uint8_t *)ie)) { scan_params->ie_list.wmeparam = (uint8_t *)ie; } else if (is_wme_info((uint8_t *)ie)) { scan_params->ie_list.wmeinfo = (uint8_t *)ie; } else if (is_atheros_oui((uint8_t *)ie)) { scan_params->ie_list.athcaps = (uint8_t *)ie; } else if (is_atheros_extcap_oui((uint8_t *)ie)) { scan_params->ie_list.athextcaps = (uint8_t *)ie; } else if (is_sfa_oui((uint8_t *)ie)) { scan_params->ie_list.sfa = (uint8_t *)ie; } else if (is_p2p_oui((uint8_t *)ie)) { scan_params->ie_list.p2p = (uint8_t *)ie; } else if (is_qca_son_oui((uint8_t *)ie, QCA_OUI_WHC_AP_INFO_SUBTYPE)) { scan_params->ie_list.sonadv = (uint8_t *)ie; } else if (is_ht_cap((uint8_t *)ie)) { /* we only care if there isn't already an HT IE (ANA) */ if (scan_params->ie_list.htcap == NULL) { if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN + sizeof(struct htcap_cmn_ie))) return QDF_STATUS_E_INVAL; scan_params->ie_list.htcap = (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie); } } else if (is_ht_info((uint8_t *)ie)) { /* we only care if there isn't already an HT IE (ANA) */ if (scan_params->ie_list.htinfo == NULL) { if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN + sizeof(struct wlan_ie_htinfo_cmn)) return QDF_STATUS_E_INVAL; scan_params->ie_list.htinfo = (uint8_t *)&(((struct wlan_vendor_ie_htinfo *) ie)->hi_ie); } } else if (is_interop_vht((uint8_t *)ie) && !(scan_params->ie_list.vhtcap)) { uint8_t *vendor_ie = (uint8_t *)(ie); if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET + sizeof(struct wlan_ie_vhtcaps)) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET; if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) - sizeof(struct ie_header)) return QDF_STATUS_E_INVAL; /* location where Interop Vht Cap IE and VHT OP IE Present */ scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET); if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET + sizeof(struct wlan_ie_vhtcaps)) - sizeof(struct ie_header))) { if (ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET + sizeof(struct wlan_ie_vhtop)) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTOP_IE_OFFSET; if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; scan_params->ie_list.vhtop = (((uint8_t *)(ie)) + WLAN_VENDOR_VHTOP_IE_OFFSET); } } else if (is_bwnss_oui((uint8_t *)ie)) { /* * Bandwidth-NSS map has sub-type & version. * hence copy data just after version byte */ scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8); } else if (is_mbo_oce_oui((uint8_t *)ie)) { scan_params->ie_list.mbo_oce = (uint8_t *)ie; } else if (is_adaptive_11r_oui((uint8_t *)ie)) { if (ie->ie_len < OUI_LENGTH || ie->ie_len > MAX_ADAPTIVE_11R_IE_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.adaptive_11r = (uint8_t *)ie + sizeof(struct ie_header); } else if (is_sae_single_pmk_oui((uint8_t *)ie)) { if (ie->ie_len < OUI_LENGTH || ie->ie_len > MAX_SAE_SINGLE_PMK_IE_LEN) { scm_debug("Invalid sae single pmk OUI"); return QDF_STATUS_E_INVAL; } scan_params->ie_list.single_pmk = (uint8_t *)ie + sizeof(struct ie_header); } return QDF_STATUS_SUCCESS; } static QDF_STATUS util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params) { struct ie_header *ie, *sub_ie; uint32_t ie_len, sub_ie_len; QDF_STATUS status; ie_len = util_scan_entry_ie_len(scan_params); ie = (struct ie_header *) util_scan_entry_ie_data(scan_params); while (ie_len >= sizeof(struct ie_header)) { ie_len -= sizeof(struct ie_header); if (!ie->ie_len) { ie += 1; continue; } if (ie_len < ie->ie_len) { scm_debug("Incomplete corrupted IE:%x", ie->ie_id); return QDF_STATUS_E_INVAL; } switch (ie->ie_id) { case WLAN_ELEMID_SSID: if (ie->ie_len > (sizeof(struct ie_ssid) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; scan_params->ie_list.ssid = (uint8_t *)ie; break; case WLAN_ELEMID_RATES: if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.rates = (uint8_t *)ie; break; case WLAN_ELEMID_DSPARMS: if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.ds_param = (uint8_t *)ie; scan_params->channel.chan_idx = ((struct ds_ie *)ie)->cur_chan; break; case WLAN_ELEMID_TIM: if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH) return QDF_STATUS_E_INVAL; scan_params->ie_list.tim = (uint8_t *)ie; scan_params->dtim_period = ((struct wlan_tim_ie *)ie)->tim_period; break; case WLAN_ELEMID_COUNTRY: if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.country = (uint8_t *)ie; break; case WLAN_ELEMID_QBSS_LOAD: if (ie->ie_len != sizeof(struct qbss_load_ie) - sizeof(struct ie_header)) { /* * Expected QBSS IE length is 5Bytes; For some * old cisco AP, QBSS IE length is 4Bytes, which * doesn't match with latest spec, So ignore * QBSS IE in such case. */ break; } scan_params->ie_list.qbssload = (uint8_t *)ie; break; case WLAN_ELEMID_CHANSWITCHANN: if (ie->ie_len != WLAN_CSA_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.csa = (uint8_t *)ie; break; case WLAN_ELEMID_IBSSDFS: if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.ibssdfs = (uint8_t *)ie; break; case WLAN_ELEMID_QUIET: if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.quiet = (uint8_t *)ie; break; case WLAN_ELEMID_ERP: if (ie->ie_len != (sizeof(struct erp_ie) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; scan_params->erp = ((struct erp_ie *)ie)->value; break; case WLAN_ELEMID_HTCAP_ANA: if (ie->ie_len != sizeof(struct htcap_cmn_ie)) return QDF_STATUS_E_INVAL; scan_params->ie_list.htcap = (uint8_t *)&(((struct htcap_ie *)ie)->ie); break; case WLAN_ELEMID_RSN: if (ie->ie_len < WLAN_RSN_IE_MIN_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.rsn = (uint8_t *)ie; break; case WLAN_ELEMID_XRATES: scan_params->ie_list.xrates = (uint8_t *)ie; break; case WLAN_ELEMID_EXTCHANSWITCHANN: if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.xcsa = (uint8_t *)ie; break; case WLAN_ELEMID_SECCHANOFFSET: if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.secchanoff = (uint8_t *)ie; break; case WLAN_ELEMID_HTINFO_ANA: if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn)) return QDF_STATUS_E_INVAL; scan_params->ie_list.htinfo = (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie); scan_params->channel.chan_idx = ((struct wlan_ie_htinfo_cmn *) (scan_params->ie_list.htinfo))->hi_ctrlchannel; break; case WLAN_ELEMID_WAPI: if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.wapi = (uint8_t *)ie; break; case WLAN_ELEMID_XCAPS: if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.extcaps = (uint8_t *)ie; break; case WLAN_ELEMID_VHTCAP: if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; scan_params->ie_list.vhtcap = (uint8_t *)ie; break; case WLAN_ELEMID_VHTOP: if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) - sizeof(struct ie_header))) return QDF_STATUS_E_INVAL; scan_params->ie_list.vhtop = (uint8_t *)ie; break; case WLAN_ELEMID_OP_MODE_NOTIFY: if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.opmode = (uint8_t *)ie; break; case WLAN_ELEMID_MOBILITY_DOMAIN: if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.mdie = (uint8_t *)ie; break; case WLAN_ELEMID_VENDOR: status = util_scan_parse_vendor_ie(scan_params, ie); if (QDF_IS_STATUS_ERROR(status)) return status; break; case WLAN_ELEMID_CHAN_SWITCH_WRAP: scan_params->ie_list.cswrp = (uint8_t *)ie; /* Go to next sub IE */ sub_ie = (struct ie_header *) (((uint8_t *)ie) + sizeof(struct ie_header)); sub_ie_len = ie->ie_len; status = util_scan_parse_chan_switch_wrapper_ie( scan_params, sub_ie, sub_ie_len); if (QDF_IS_STATUS_ERROR(status)) { scm_err("failed to parse chan_switch_wrapper_ie"); return status; } break; case WLAN_ELEMID_FILS_INDICATION: if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN) return QDF_STATUS_E_INVAL; scan_params->ie_list.fils_indication = (uint8_t *)ie; break; case WLAN_ELEMID_EXTN_ELEM: status = util_scan_parse_extn_ie(scan_params, ie); if (QDF_IS_STATUS_ERROR(status)) return status; break; default: break; } /* Consume info element */ ie_len -= ie->ie_len; /* Go to next IE */ ie = (struct ie_header *) (((uint8_t *) ie) + sizeof(struct ie_header) + ie->ie_len); } return QDF_STATUS_SUCCESS; } /** * util_scan_update_esp_data: update ESP params from beacon/probe response * @esp_information: pointer to wlan_esp_information * @scan_entry: new received entry * * The Estimated Service Parameters element is * used by a AP to provide information to another STA which * can then use the information as input to an algorithm to * generate an estimate of throughput between the two STAs. * The ESP Information List field contains from 1 to 4 ESP * Information fields(each field 24 bits), each corresponding * to an access category for which estimated service parameters * information is provided. * * Return: None */ static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information, struct scan_cache_entry *scan_entry) { uint8_t *data; int i = 0; uint64_t total_elements; struct wlan_esp_info *esp_info; struct wlan_esp_ie *esp_ie; esp_ie = (struct wlan_esp_ie *) util_scan_entry_esp_info(scan_entry); total_elements = esp_ie->esp_len; data = (uint8_t *)esp_ie + 3; do_div(total_elements, ESP_INFORMATION_LIST_LENGTH); if (total_elements > MAX_ESP_INFORMATION_FIELD) { scm_err("No of Air time fractions are greater than supported"); return; } for (i = 0; i < total_elements; i++) { esp_info = (struct wlan_esp_info *)data; if (esp_info->access_category == ESP_AC_BK) { qdf_mem_copy(&esp_information->esp_info_AC_BK, data, 3); data = data + ESP_INFORMATION_LIST_LENGTH; continue; } if (esp_info->access_category == ESP_AC_BE) { qdf_mem_copy(&esp_information->esp_info_AC_BE, data, 3); data = data + ESP_INFORMATION_LIST_LENGTH; continue; } if (esp_info->access_category == ESP_AC_VI) { qdf_mem_copy(&esp_information->esp_info_AC_VI, data, 3); data = data + ESP_INFORMATION_LIST_LENGTH; continue; } if (esp_info->access_category == ESP_AC_VO) { qdf_mem_copy(&esp_information->esp_info_AC_VO, data, 3); data = data + ESP_INFORMATION_LIST_LENGTH; break; } } } /** * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time * fraction * @scan_entry: new received entry * * This function process all Access category ESP params and provide * best effort air time fraction. * If best effort is not available, it will choose VI, VO and BK in sequence * */ static void util_scan_scm_update_bss_with_esp_data( struct scan_cache_entry *scan_entry) { uint8_t air_time_fraction = 0; struct wlan_esp_ie esp_information; if (!scan_entry->ie_list.esp) return; util_scan_update_esp_data(&esp_information, scan_entry); /* * If the ESP metric is transmitting multiple airtime fractions, then * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is * the first one available */ if (esp_information.esp_info_AC_BE.access_category == ESP_AC_BE) air_time_fraction = esp_information.esp_info_AC_BE. estimated_air_fraction; else if (esp_information.esp_info_AC_VI.access_category == ESP_AC_VI) air_time_fraction = esp_information.esp_info_AC_VI. estimated_air_fraction; else if (esp_information.esp_info_AC_VO.access_category == ESP_AC_VO) air_time_fraction = esp_information.esp_info_AC_VO. estimated_air_fraction; else if (esp_information.esp_info_AC_BK.access_category == ESP_AC_BK) air_time_fraction = esp_information.esp_info_AC_BK. estimated_air_fraction; scan_entry->air_time_fraction = air_time_fraction; } /** * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP * @scan_entry: new received entry * * Return: number of nss advertised by AP */ static int util_scan_scm_calc_nss_supported_by_ap( struct scan_cache_entry *scan_params) { struct htcap_cmn_ie *htcap; struct wlan_ie_vhtcaps *vhtcaps; uint8_t rx_mcs_map; htcap = (struct htcap_cmn_ie *) util_scan_entry_htcap(scan_params); vhtcaps = (struct wlan_ie_vhtcaps *) util_scan_entry_vhtcap(scan_params); if (vhtcaps) { rx_mcs_map = vhtcaps->rx_mcs_map; if ((rx_mcs_map & 0xC0) != 0xC0) return 4; if ((rx_mcs_map & 0x30) != 0x30) return 3; if ((rx_mcs_map & 0x0C) != 0x0C) return 2; } else if (htcap) { if (htcap->mcsset[3]) return 4; if (htcap->mcsset[2]) return 3; if (htcap->mcsset[1]) return 2; } return 1; } #ifdef WLAN_ADAPTIVE_11R /** * scm_fill_adaptive_11r_cap() - Check if the AP supports adaptive 11r * @scan_entry: Pointer to the scan entry * * Return: true if adaptive 11r is advertised else false */ static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry) { uint8_t *ie; uint8_t data; bool adaptive_11r; ie = util_scan_entry_adaptive_11r(scan_entry); if (!ie) return; data = *(ie + OUI_LENGTH); adaptive_11r = (data & 0x1) ? true : false; scan_entry->adaptive_11r_ap = adaptive_11r; } #else static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry) { scan_entry->adaptive_11r_ap = false; } #endif static void util_scan_set_security(struct scan_cache_entry *scan_params) { if (util_scan_entry_wpa(scan_params)) scan_params->security_type |= SCAN_SECURITY_TYPE_WPA; if (util_scan_entry_rsn(scan_params)) scan_params->security_type |= SCAN_SECURITY_TYPE_RSN; if (util_scan_entry_wapi(scan_params)) scan_params->security_type |= SCAN_SECURITY_TYPE_WAPI; if (!scan_params->security_type && scan_params->cap_info.wlan_caps.privacy) scan_params->security_type |= SCAN_SECURITY_TYPE_WEP; } qdf_list_t * util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame, qdf_size_t frame_len, uint32_t frm_subtype, struct mgmt_rx_event_params *rx_param) { struct wlan_frame_hdr *hdr; struct wlan_bcn_frame *bcn; QDF_STATUS status; struct ie_ssid *ssid; struct scan_cache_entry *scan_entry; struct qbss_load_ie *qbss_load; qdf_list_t *scan_list; struct scan_cache_node *scan_node; scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list)); if (!scan_list) { scm_err("failed to allocate scan_list"); return NULL; } qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE); scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry)); if (!scan_entry) { scm_err("failed to allocate memory for scan_entry"); qdf_mem_free(scan_list); return NULL; } scan_entry->raw_frame.ptr = qdf_mem_malloc_atomic(frame_len); if (!scan_entry->raw_frame.ptr) { scm_err("failed to allocate memory for frame"); qdf_mem_free(scan_entry); qdf_mem_free(scan_list); return NULL; } bcn = (struct wlan_bcn_frame *) (frame + sizeof(*hdr)); hdr = (struct wlan_frame_hdr *)frame; /* update timestamp in nanoseconds needed by kernel layers */ scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns(); scan_entry->frm_subtype = frm_subtype; qdf_mem_copy(scan_entry->bssid.bytes, hdr->i_addr3, QDF_MAC_ADDR_SIZE); /* Scr addr */ qdf_mem_copy(scan_entry->mac_addr.bytes, hdr->i_addr2, QDF_MAC_ADDR_SIZE); scan_entry->seq_num = (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT); scan_entry->rssi_raw = rx_param->rssi; scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw); scan_entry->tsf_delta = rx_param->tsf_delta; /* Copy per chain rssi to scan entry */ qdf_mem_copy(scan_entry->per_chain_snr, rx_param->rssi_ctl, WLAN_MGMT_TXRX_HOST_MAX_ANTENNA); /* store jiffies */ scan_entry->rrm_parent_tsf = (u_int32_t) qdf_system_ticks(); scan_entry->bcn_int = le16toh(bcn->beacon_interval); /* * In case if the beacon dosnt have * valid beacon interval falback to def */ if (!scan_entry->bcn_int) scan_entry->bcn_int = 100; scan_entry->cap_info.value = le16toh(bcn->capability.value); qdf_mem_copy(scan_entry->tsf_info.data, bcn->timestamp, 8); scan_entry->erp = ERP_NON_ERP_PRESENT; scan_entry->scan_entry_time = qdf_mc_timer_get_system_time(); scan_entry->raw_frame.len = frame_len; qdf_mem_copy(scan_entry->raw_frame.ptr, frame, frame_len); status = util_scan_populate_bcn_ie_list(scan_entry); if (QDF_IS_STATUS_ERROR(status)) { scm_debug("failed to parse beacon IE"); qdf_mem_free(scan_entry->raw_frame.ptr); qdf_mem_free(scan_entry); qdf_mem_free(scan_list); return NULL; } ssid = (struct ie_ssid *) scan_entry->ie_list.ssid; if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) { qdf_mem_free(scan_entry->raw_frame.ptr); qdf_mem_free(scan_entry); qdf_mem_free(scan_list); return NULL; } if (scan_entry->ie_list.p2p) scan_entry->is_p2p = true; /* If no channel info is present in beacon use meta channel */ if (!scan_entry->channel.chan_idx) { scan_entry->channel.chan_idx = rx_param->channel; } else if (rx_param->channel != scan_entry->channel.chan_idx) { if (!wlan_reg_chan_is_49ghz(pdev, scan_entry->channel.chan_idx)) scan_entry->channel_mismatch = true; } if (util_scan_is_hidden_ssid(ssid)) { scan_entry->ie_list.ssid = NULL; scan_entry->is_hidden_ssid = true; } else { qdf_mem_copy(scan_entry->ssid.ssid, ssid->ssid, ssid->ssid_len); scan_entry->ssid.length = ssid->ssid_len; scan_entry->hidden_ssid_timestamp = scan_entry->scan_entry_time; } if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx)) scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry); else scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry); scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry); scm_fill_adaptive_11r_cap(scan_entry); util_scan_set_security(scan_entry); util_scan_scm_update_bss_with_esp_data(scan_entry); qbss_load = (struct qbss_load_ie *) util_scan_entry_qbssload(scan_entry); if (qbss_load) scan_entry->qbss_chan_load = qbss_load->qbss_chan_load; scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node)); if (!scan_node) { qdf_mem_free(scan_entry->raw_frame.ptr); qdf_mem_free(scan_entry); qdf_mem_free(scan_list); return NULL; } scan_node->entry = scan_entry; qdf_list_insert_front(scan_list, &scan_node->node); /* TODO calculate channel struct */ return scan_list; } QDF_STATUS util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev, struct scan_cache_entry *scan_entry) { if (!pdev || !scan_entry) { scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry); return QDF_STATUS_E_INVAL; } return scm_update_scan_mlme_info(pdev, scan_entry); } bool util_is_scan_completed(struct scan_event *event, bool *success) { if ((event->type == SCAN_EVENT_TYPE_COMPLETED) || (event->type == SCAN_EVENT_TYPE_DEQUEUED) || (event->type == SCAN_EVENT_TYPE_START_FAILED)) { if ((event->type == SCAN_EVENT_TYPE_COMPLETED) && (event->reason == SCAN_REASON_COMPLETED)) *success = true; else *success = false; return true; } *success = false; return false; }
28.641613
76
0.724334
77e0fbdcfa6ae4f8ddfcd0065ba3149053516404
1,600
h
C
remoting/host/it2me/it2me_confirmation_dialog_proxy.h
Wzzzx/chromium-crosswalk
768dde8efa71169f1c1113ca6ef322f1e8c9e7de
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
2
2019-01-28T08:09:58.000Z
2021-11-15T15:32:10.000Z
remoting/host/it2me/it2me_confirmation_dialog_proxy.h
maidiHaitai/haitaibrowser
a232a56bcfb177913a14210e7733e0ea83a6b18d
[ "BSD-3-Clause" ]
null
null
null
remoting/host/it2me/it2me_confirmation_dialog_proxy.h
maidiHaitai/haitaibrowser
a232a56bcfb177913a14210e7733e0ea83a6b18d
[ "BSD-3-Clause" ]
6
2020-09-23T08:56:12.000Z
2021-11-18T03:40:49.000Z
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef REMOTING_HOST_IT2ME_IT2ME_CONFIRMATION_DIALOG_PROXY_H_ #define REMOTING_HOST_IT2ME_IT2ME_CONFIRMATION_DIALOG_PROXY_H_ #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/single_thread_task_runner.h" #include "base/threading/non_thread_safe.h" #include "remoting/host/it2me/it2me_confirmation_dialog.h" namespace remoting { // A helper class to use an It2MeConfirmationDialog from a non-UI thread. class It2MeConfirmationDialogProxy : public It2MeConfirmationDialog { public: // |ui_task_runner| must be the UI thread. It will be used to call into the // wrapped dialog. // |dialog| is the dialog being wrapped. It2MeConfirmationDialogProxy( scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, std::unique_ptr<It2MeConfirmationDialog> dialog); ~It2MeConfirmationDialogProxy() override; // It2MeConfirmationDialog implementation. void Show(const It2MeConfirmationDialog::ResultCallback& callback) override; private: class Core; void ReportResult(It2MeConfirmationDialog::Result result); std::unique_ptr<Core> core_; It2MeConfirmationDialog::ResultCallback callback_; base::WeakPtrFactory<It2MeConfirmationDialogProxy> weak_factory_; DISALLOW_COPY_AND_ASSIGN(It2MeConfirmationDialogProxy); }; } // namespace remoting #endif // REMOTING_HOST_IT2ME_IT2ME_CONFIRMATION_DIALOG_PROXY_H_
33.333333
78
0.80375
cbe86db37350a69078b8826cad0696a73aac08ac
2,562
c
C
keyboards/keebio/levinson/keymaps/valgrahf/keymap.c
fzf/qmk_toolbox
10d6b425bd24b45002555022baf16fb11254118b
[ "MIT" ]
null
null
null
keyboards/keebio/levinson/keymaps/valgrahf/keymap.c
fzf/qmk_toolbox
10d6b425bd24b45002555022baf16fb11254118b
[ "MIT" ]
null
null
null
keyboards/keebio/levinson/keymaps/valgrahf/keymap.c
fzf/qmk_toolbox
10d6b425bd24b45002555022baf16fb11254118b
[ "MIT" ]
null
null
null
#include QMK_KEYBOARD_H extern keymap_config_t keymap_config; #define _BASE 0 #define _FN1 1 #define _FN2 2 #define KC_ KC_TRNS #define KC_FN1 LT(_FN1, KC_NO) #define KC_FN2 LT(_FN2, KC_NO) #define KC_SPFN LT(_FN1, KC_SPACE) #define KC_RST RESET #define KC_DBUG DEBUG #define KC_RTOG RGB_TOG #define KC_RMOD RGB_MOD #define KC_RHUI RGB_HUI #define KC_RHUD RGB_HUD #define KC_RSAI RGB_SAI #define KC_RSAD RGB_SAD #define KC_RVAI RGB_VAI #define KC_RVAD RGB_VAD const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_BASE] = LAYOUT_kc_ortho_4x12( //,----+----+----+----+----+----. ,----+----+----+----+----+----. TAB, Q , W , E , R , T , Y , U , I , O , P ,BSPC, //|----+----+----+----+----+----| |----+----+----+----+----+----| ESC, A , S , D , F , G , H , J , K , L ,SCLN,QUOT, //|----+----+----+----+----+----| |----+----+----+----+----+----| LSFT, Z , X , C , V , B , N , M ,COMM, DOT,SLSH,PGUP, //|----+----+----+----+----+----| |----+----+----+----+----+----| LCTL,LGUI,LALT, FN1, ENT, ENT, SPC, SPC, FN2,HOME, END,PGDN //`----+----+----+----+----+----' `----+----+----+----+----+----' ), [_FN1] = LAYOUT_kc_ortho_4x12( //,----+----+----+----+----+----. ,----+----+----+----+----+----. GRV, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , , //|----+----+----+----+----+----| |----+----+----+----+----+----| DEL, F1, F2, F3, F4, F5, F6,MINS, EQL,LBRC,RBRC,BSLS, //|----+----+----+----+----+----| |----+----+----+----+----+----| , F7, F8, F9, F10, F11, F12, , , , UP, , //|----+----+----+----+----+----| |----+----+----+----+----+----| , , , , , , , , ,LEFT,DOWN,RIGHT //`----+----+----+----+----+----' `----+----+----+----+----+----' ), [_FN2] = LAYOUT_kc_ortho_4x12( //,----+----+----+----+----+----. ,----+----+----+----+----+----. TILD,EXLM, AT ,HASH,DLR ,PERC, CIRC,AMPR,ASTR,LPRN,RPRN, , //|----+----+----+----+----+----| |----+----+----+----+----+----| DEL,RHUI,RSAI,RVAI, , , ,UNDS,PLUS,LCBR,RCBR,PIPE, //|----+----+----+----+----+----| |----+----+----+----+----+----| ,RHUD,RSAD,RVAD, , , , , , , , , //|----+----+----+----+----+----| |----+----+----+----+----+----| ,RTOG,RMOD, , , , , , , , , //`----+----+----+----+----+----' `----+----+----+----+----+----' ), };
40.03125
70
0.301327
0ee57d68782c65994349c8f0ff1089dd62675f4f
2,295
h
C
applications/physbam/physbam-lib/Public_Library/PhysBAM_Dynamics/Coupled_Evolution/FLUID_TO_SOLID_INTERPOLATION_BASE.h
schinmayee/nimbus
170cd15e24a7a88243a6ea80aabadc0fc0e6e177
[ "BSD-3-Clause" ]
20
2017-07-03T19:09:09.000Z
2021-09-10T02:53:56.000Z
applications/physbam/physbam-lib/Public_Library/PhysBAM_Dynamics/Coupled_Evolution/FLUID_TO_SOLID_INTERPOLATION_BASE.h
schinmayee/nimbus
170cd15e24a7a88243a6ea80aabadc0fc0e6e177
[ "BSD-3-Clause" ]
null
null
null
applications/physbam/physbam-lib/Public_Library/PhysBAM_Dynamics/Coupled_Evolution/FLUID_TO_SOLID_INTERPOLATION_BASE.h
schinmayee/nimbus
170cd15e24a7a88243a6ea80aabadc0fc0e6e177
[ "BSD-3-Clause" ]
9
2017-09-17T02:05:06.000Z
2020-01-31T00:12:01.000Z
//##################################################################### // Copyright 2010. // This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt. //##################################################################### // Class FLUID_TO_SOLID_INTERPOLATION_BASE //##################################################################### #ifndef __FLUID_TO_SOLID_INTERPOLATION_BASE__ #define __FLUID_TO_SOLID_INTERPOLATION_BASE__ #include <PhysBAM_Tools/Arrays/ARRAYS_FORWARD.h> #include <PhysBAM_Tools/Data_Structures/TRIPLE.h> #include <PhysBAM_Tools/Utilities/NONCOPYABLE.h> #include <PhysBAM_Dynamics/Coupled_Evolution/COUPLING_CONSTRAINT_ID.h> #include <PhysBAM_Dynamics/Coupled_Evolution/SYSTEM_MATRIX_HELPER.h> namespace PhysBAM{ template<class TV> class GENERALIZED_VELOCITY; template<class TV> class GENERALIZED_MASS; template<class TV> class GRID; template<class TV> class COLLISION_AWARE_INDEX_MAP; template<class TV> class FLUID_TO_SOLID_INTERPOLATION_BASE:public NONCOPYABLE,public SYSTEM_MATRIX_BASE<typename TV::SCALAR> { typedef typename TV::SCALAR T; protected: const COLLISION_AWARE_INDEX_MAP<TV>& index_map; public: FLUID_TO_SOLID_INTERPOLATION_BASE(const COLLISION_AWARE_INDEX_MAP<TV>& map); virtual ~FLUID_TO_SOLID_INTERPOLATION_BASE(); int V_size; const ARRAY<int>* V_indices; //##################################################################### virtual void Compute(const int ghost_cells)=0; virtual void Times_Add(const VECTOR_ND<T>& fluid_velocity,GENERALIZED_VELOCITY<TV>& solid_velocity) const=0; void Times(const VECTOR_ND<T>& fluid_velocity,GENERALIZED_VELOCITY<TV>& solid_velocity) const; virtual void Transpose_Times_Add(const GENERALIZED_VELOCITY<TV>& solid_force,VECTOR_ND<T>& fluid_force) const=0; void Transpose_Times(const GENERALIZED_VELOCITY<TV>& solid_force,VECTOR_ND<T>& fluid_force) const; void Test_Matrix(int number_fluid_faces,int number_particles,int number_rigid_particles) const; virtual void Print_Each_Matrix(int n,int fluid_faces,GENERALIZED_VELOCITY<TV>& G) const=0; void Store_Maps(const GENERALIZED_VELOCITY<TV>& G); //##################################################################### }; } #endif
46.836735
135
0.688453
858090c31919ebd182254083a33ef6a2d17d4fcc
1,992
c
C
src/passive.c
thibautcornolti/MyFTP
5775e8d8e4b15e62078cbc5046a7c474a3b02d05
[ "MIT" ]
null
null
null
src/passive.c
thibautcornolti/MyFTP
5775e8d8e4b15e62078cbc5046a7c474a3b02d05
[ "MIT" ]
null
null
null
src/passive.c
thibautcornolti/MyFTP
5775e8d8e4b15e62078cbc5046a7c474a3b02d05
[ "MIT" ]
null
null
null
/* ** EPITECH PROJECT, 2018 ** myftp ** File description: ** myftp */ #include "../include/ftp.h" #include "../include/passive.h" static bool threading_passive_mode_setup(sess_t *sess) { if (!create_socket(&sess->pasv_listen) || !bind_socket(0, &sess->pasv_listen)) return (false); if (!listen_socket(1, &sess->pasv_listen)) { close_socket(&sess->pasv_listen); return (false); } return (true); } static void *threading_passive_mode(void *d) { sess_t *sess = d; if (!threading_passive_mode_setup(sess)) { pthread_cond_broadcast(&sess->pasv_cond); return (NULL); } getsockname(sess->pasv_listen.fd, (struct sockaddr *) &sess->pasv_listen.s_in, &sess->pasv_listen.s_in_len); sess->active = false; sess->netted = true; pthread_cond_broadcast(&sess->pasv_cond); pthread_mutex_lock(&sess->pasv_mutex); if (!accept_socket(&sess->client, &sess->pasv_listen)) { close_socket(&sess->pasv_listen); sess->netted = false; pthread_mutex_unlock(&sess->pasv_mutex); } else pthread_mutex_unlock(&sess->pasv_mutex); return (NULL); } void start_passive_mode(sess_t *sess) { kill_passive_mode(sess); pthread_create(&sess->pasv_thread, NULL, &threading_passive_mode, sess); pthread_cond_wait(&sess->pasv_cond, &sess->pasv_cond_mutex); usleep(10000); } void kill_passive_mode(sess_t *sess) { struct sockaddr_in temp_sock = {0}; struct hostent *server = gethostbyname("0"); struct protoent *proto = getprotobyname("TCP"); int fd; if (!proto) return ; if ((fd = socket(AF_INET, SOCK_STREAM, proto->p_proto)) < 0) return ; temp_sock.sin_family = AF_INET; temp_sock.sin_port = sess->pasv_listen.s_in.sin_port; memcpy(server->h_addr, &temp_sock.sin_addr.s_addr, server->h_length); if (connect(fd, (struct sockaddr *) &temp_sock, sizeof(temp_sock))) return ; close_passive_mode(sess); close(fd); } void close_passive_mode(sess_t *sess) { sess->netted = false; sess->active = false; close_socket(&sess->pasv_listen); close_socket(&sess->client); }
24.292683
73
0.719378
3f532ec23b2008895d6c8c435fe18ead30e80cc2
516
h
C
junkbox/Classes/Bookmark/Login/JBBookmarkLoginController.h
kenzan8000/junky
99fccc9b414e3eb15772c5ce3268226a19c7a5a7
[ "WTFPL" ]
1
2016-02-08T15:30:41.000Z
2016-02-08T15:30:41.000Z
junkbox/Classes/Bookmark/Login/JBBookmarkLoginController.h
kenzan8000/junky
99fccc9b414e3eb15772c5ce3268226a19c7a5a7
[ "WTFPL" ]
null
null
null
junkbox/Classes/Bookmark/Login/JBBookmarkLoginController.h
kenzan8000/junky
99fccc9b414e3eb15772c5ce3268226a19c7a5a7
[ "WTFPL" ]
null
null
null
#import "JBBarButtonView.h" // Pods #import "HTBLoginWebViewController.h" #pragma mark - class @class TYMActivityIndicatorView; #pragma mark - JBBookmarkLoginController /// ブックマークログインViewController @interface JBBookmarkLoginController : HTBLoginWebViewController <JBBarButtonViewDelegate> { } #pragma mark - property /// 閉じるボタン @property (nonatomic, strong) JBBarButtonView *closeButton; /// インジケーター @property (nonatomic, strong) TYMActivityIndicatorView *indicatorView; #pragma mark - event listener @end
19.111111
92
0.792636
6be9f6157b36bf5eff22c4552bac72622690b714
620
h
C
uboot/arch/arm/include/asm/arch-tegra/gpu.h
bingchunjin/1806_SDK
d5ed0258fc22f60e00ec025b802d175f33da6e41
[ "MIT" ]
31
2018-01-16T17:11:44.000Z
2022-03-16T13:51:24.000Z
uboot/arch/arm/include/asm/arch-tegra/gpu.h
bingchunjin/1806_SDK
d5ed0258fc22f60e00ec025b802d175f33da6e41
[ "MIT" ]
4
2016-08-30T11:30:25.000Z
2020-12-27T09:58:07.000Z
uboot/arch/arm/include/asm/arch-tegra/gpu.h
bingchunjin/1806_SDK
d5ed0258fc22f60e00ec025b802d175f33da6e41
[ "MIT" ]
30
2018-05-02T08:43:27.000Z
2022-01-23T03:25:54.000Z
/* * (C) Copyright 2015 * NVIDIA Corporation <www.nvidia.com> * * SPDX-License-Identifier: GPL-2.0+ */ #ifndef __ASM_ARCH_TEGRA_GPU_H #define __ASM_ARCH_TEGRA_GPU_H #if defined(CONFIG_TEGRA_GPU) void tegra_gpu_config(void); #else /* CONFIG_TEGRA_GPU */ static inline void tegra_gpu_config(void) { } #endif /* CONFIG_TEGRA_GPU */ #if defined(CONFIG_OF_LIBFDT) int tegra_gpu_enable_node(void *blob, const char *gpupath); #else /* CONFIG_OF_LIBFDT */ static inline int tegra_gpu_enable_node(void *blob, const char *compat) { return 0; } #endif /* CONFIG_OF_LIBFDT */ #endif /* __ASM_ARCH_TEGRA_GPU_H */
16.756757
71
0.73871
acc0ba97ebca975fb8d9c7d13c986791632aa1a1
104
h
C
src/NSStringDigest.h
bickfordb/Shotwell
66af42218c4dc582909f10c0cd6fb8a8b0d8569b
[ "Apache-2.0" ]
5
2015-02-09T15:08:24.000Z
2021-03-17T22:22:53.000Z
src/NSStringDigest.h
bickfordb/Shotwell
66af42218c4dc582909f10c0cd6fb8a8b0d8569b
[ "Apache-2.0" ]
null
null
null
src/NSStringDigest.h
bickfordb/Shotwell
66af42218c4dc582909f10c0cd6fb8a8b0d8569b
[ "Apache-2.0" ]
1
2016-02-16T18:29:39.000Z
2016-02-16T18:29:39.000Z
#import <Cocoa/Cocoa.h> @interface NSString (Digest) - (NSString *)sha1; @end // vim: filetype=objcpp
13
28
0.692308
6b6d5833242f5b75c2088b57a3a0370a55a1bc2c
174
h
C
ios/versioned-react-native/ABI7_0_0/Exponent/Modules/Api/ABI7_0_0EXFacebook.h
L8RMedia/exponent
c9f3012826f0fe797b30a07e52505cfb16cdee54
[ "Apache-2.0", "BSD-3-Clause" ]
null
null
null
ios/versioned-react-native/ABI7_0_0/Exponent/Modules/Api/ABI7_0_0EXFacebook.h
L8RMedia/exponent
c9f3012826f0fe797b30a07e52505cfb16cdee54
[ "Apache-2.0", "BSD-3-Clause" ]
null
null
null
ios/versioned-react-native/ABI7_0_0/Exponent/Modules/Api/ABI7_0_0EXFacebook.h
L8RMedia/exponent
c9f3012826f0fe797b30a07e52505cfb16cdee54
[ "Apache-2.0", "BSD-3-Clause" ]
null
null
null
// Copyright 2016-present 650 Industries. All rights reserved. #import "ABI7_0_0RCTBridgeModule.h" @interface ABI7_0_0EXFacebook : NSObject <ABI7_0_0RCTBridgeModule> @end
21.75
66
0.810345
5c782bf51d8c7914b8a1101604854163b8d36ae7
772
h
C
Archived/v1/WCDistractionFreeXcodePlugin/Headers/PlugIns/Xcode3UI/Xcode3BuildPropertyConfigFileColumnContext.h
wokalski/Distraction-Free-Xcode-plugin
54ab4b9d9825e8370855b7985d6ff39d64c19f25
[ "MIT" ]
25
2016-03-03T07:43:56.000Z
2021-09-05T08:47:40.000Z
Archived/v1/WCDistractionFreeXcodePlugin/Headers/PlugIns/Xcode3UI/Xcode3BuildPropertyConfigFileColumnContext.h
wokalski/Distraction-Free-Xcode-plugin
54ab4b9d9825e8370855b7985d6ff39d64c19f25
[ "MIT" ]
8
2016-02-23T18:40:20.000Z
2016-08-18T13:21:05.000Z
Archived/v1/WCDistractionFreeXcodePlugin/Headers/PlugIns/Xcode3UI/Xcode3BuildPropertyConfigFileColumnContext.h
wokalski/Distraction-Free-Xcode-plugin
54ab4b9d9825e8370855b7985d6ff39d64c19f25
[ "MIT" ]
4
2016-02-24T13:24:27.000Z
2016-06-28T12:50:36.000Z
// // Generated by class-dump 3.5 (64 bit). // // class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard. // #import <Xcode3UI/Xcode3BuildPropertyBlueprintColumnContext.h> @interface Xcode3BuildPropertyConfigFileColumnContext : Xcode3BuildPropertyBlueprintColumnContext { int _level; } @property int level; // @synthesize level=_level; - (void)configureForConfigurationFileInLevelsMode:(BOOL)arg1; - (id)customTitleForName:(id)arg1; - (BOOL)hasAssignmentForRowContext:(id)arg1; - (id)expandedPropertyValueForRowContext:(id)arg1; - (id)expandedValueForRowContext:(id)arg1 withConditionSet:(id)arg2 macroEditingContext:(id)arg3; - (id)propertyDefinitionValueForRowContext:(id)arg1; - (int)definitionLevelForConfigFile; - (id)init; @end
29.692308
97
0.778497
583a3bb1451f30087528de50bc1e1b1a6fc60994
429
h
C
include/lab1/parabola.h
Jovvik/methopt-lab-1
2c3acaf653c7214a925ed1292b9d1d30a33d2737
[ "Unlicense" ]
null
null
null
include/lab1/parabola.h
Jovvik/methopt-lab-1
2c3acaf653c7214a925ed1292b9d1d30a33d2737
[ "Unlicense" ]
null
null
null
include/lab1/parabola.h
Jovvik/methopt-lab-1
2c3acaf653c7214a925ed1292b9d1d30a33d2737
[ "Unlicense" ]
null
null
null
#pragma once #include "lab1/optimizer.h" namespace lab1 { /** * Оптимизатор на основе метода парабол */ class Parabola : public Optimizer { public: Parabola(const func& optimized_function, double epsilon, double start, double end); protected: void step(); double answer(); private: double f_start, f_mid, f_end; }; } // namespace lab1
19.5
78
0.582751
388cb19fd6e4fd751c1e51d2c1f7212cfeef0b40
5,007
h
C
include/ubit_devices.h
Geymerson/ubit_project
6d283890961e4479335cdfea278ac22943f2cc1f
[ "MIT" ]
null
null
null
include/ubit_devices.h
Geymerson/ubit_project
6d283890961e4479335cdfea278ac22943f2cc1f
[ "MIT" ]
null
null
null
include/ubit_devices.h
Geymerson/ubit_project
6d283890961e4479335cdfea278ac22943f2cc1f
[ "MIT" ]
null
null
null
#ifndef __UBIT_DEVICES_H #define __UBIT_DEVICES_H /*! \file ubit_devices.h \brief Device functions definition. This library will define functions to initiate sensors, read data and print to microbit's display. */ #include <display/mb_display.h> #include <sensor.h> #define ACC_DEV_ADDR 0x1D #define ACC_WHO_AM_I_REG 0x0D #define ACC_TEST_VALUE 0x5A #define ACC_CTRL_REG 0x2A #define ACC_OUT_X_MSB 0x01 #define ACC_OUT_X_LSB 0x02 #define ACC_OUT_Y_MSB 0x03 #define ACC_OUT_Y_LSB 0x04 #define ACC_OUT_Z_MSB 0x05 #define ACC_OUT_Z_LSB 0x06 #define COMPASS_DEV_ADDR 0x0e #define COMPASS_WHO_AM_I_REG 0x07 #define COMPASS_TEST_VALUE 0xC4 #define COMPASS_CTRL_REG 0x10 #define MAG_OUT_X_MSB 0x01 #define MAG_OUT_X_LSB 0x02 #define MAG_OUT_Y_MSB 0x03 #define MAG_OUT_Y_LSB 0x04 #define MAG_OUT_Z_MSB 0x05 #define MAG_OUT_Z_LSB 0x06 /*! \fn u16_t get_sleep_time() \brief Get the required sleep time to the current device. When temperature, accelerometer or magnetometer sensors are being used, their information require a certain time the be shown on microbit's display. This function return the required time. */ u16_t get_sleep_time(); /*! \fn void init_display() \brief Initiate the display device. This function must be called before printing anything to microbit's display. */ void init_display(); /*! \fn void init_temperature_sensor() \brief Initiate the display device. This function must be called in order to use the temperature sensor. */ void init_temperature_sensor(); /*! \fn void init_accelerometer_sensor() \brief Initiate the accelerometer device. This function must be called in order to use the accelerometer sensor. */ void init_accelerometer_sensor(); /*! \fn void init_magnetometer_sensor() \brief Initiate the magnetometer device. This function must be called in order to use the magnetometer sensor. */ void init_magnetometer_sensor(); /*! \fn void print_to_display(() \brief Print the message "ECOM042.2017.2" to microbit's display */ void print_to_display(); /*! \fn void read_temperature() \brief Read temperature value in degrees Celsius */ void read_temperature(); /*! \fn void read_accelerometer() \brief Read accelerometer x, y and z axis values */ void read_accelerometer(); /*! \fn void get_accelerometer_x() \brief Return accelerometer's x value Before use this function, read_accelerometer() must be called. */ u16_t get_accelerometer_x(); /*! \fn void get_accelerometer_y() \brief Return accelerometer's y value Before use this function, read_accelerometer() must be called. */ u16_t get_accelerometer_y(); /*! \fn void get_accelerometer_z() \brief Return accelerometer's z value Before use this function, read_accelerometer() must be called. */ u16_t get_accelerometer_z(); /*! \fn u8_t get_accel_col(u16_t x_accel) \brief Return the a display column \param x_accel The accelerometer x reading This function receives the current x acceleration data and returns a valid column value to be set on the microbits display */ u8_t get_accel_col(u16_t x_accel); /*! \fn u8_t get_accel_row(u16_t y_accel) \brief Return the a display column \param y_accel The accelerometer y reading This function receives the current y acceleration data and returns a valid row value to be set on the microbits display */ u8_t get_accel_row(u16_t y_accel); //Print a dot on microbit display //according with the accelerometer readings /*! \fn void update_accel_display() \brief Update a display pixel position This function shows a moving dot on microbit's display. The dot moves according to the accelerometer sensor readings */ void update_accel_display(); /*! \fn void read_magnetometer() \brief Read magnetometer axis values */ void read_magnetometer(); /*! \fn u16_t read_compass_x() \brief Return magnetometer's x value Before use this function, read_magnetometer() must be called. */ u16_t read_compass_x(); /*! \fn u16_t read_compass_y() \brief Return magnetometer's y value Before use this function, read_magnetometer() must be called. */ u16_t read_compass_y(); /*! \fn u16_t read_compass_z() \brief Return magnetometer's z value Before use this function, read_magnetometer() must be called. */ u16_t read_compass_z(); /*! \fn print_compass_direction() \brief Print the direction which the board is pointing Print the direction which the board is pointing based on the magnetometer sensor readings. Possible directions are 'N', 'S', 'L' and 'O'. If no direction is detected, a '?' will be displayed. */ void print_compass_direction(); /*! \fn connect_to_bluetooth() \brief Stablish a bluetooth connection with an external device */ void connect_to_bluetooth(); #endif //__UBIT_DEVICESL_H
26.919355
73
0.727581
1d5bf2499dd080f5fb8b9bb77f1aeff316fa832d
3,409
c
C
src/pobj/queue.c
Zhoutall/stasis
65a9ae5ce1468e3d8073e62fbcb15b120ec344f5
[ "TCL" ]
null
null
null
src/pobj/queue.c
Zhoutall/stasis
65a9ae5ce1468e3d8073e62fbcb15b120ec344f5
[ "TCL" ]
null
null
null
src/pobj/queue.c
Zhoutall/stasis
65a9ae5ce1468e3d8073e62fbcb15b120ec344f5
[ "TCL" ]
1
2019-11-21T07:21:32.000Z
2019-11-21T07:21:32.000Z
#include <string.h> #include "common.h" #include "debug.h" #include "xmem.h" #define QUEUE_SEG_MAX_EXP 10 #define QUEUE_SEG_MAX (1 << QUEUE_SEG_MAX_EXP) struct queue_seg { int head; int tail; struct queue_seg *next; }; #define SEG_OFFSET ALIGN(sizeof(struct queue_seg)) #define SEG_TOTAL_SIZE(n) (SEG_OFFSET + ((n) * sizeof(unsigned long))) #define SEG_BUF(s) ((unsigned long *) ((char *)s + SEG_OFFSET)) struct queue { struct queue_seg *head_seg; struct queue_seg *tail_seg; struct queue_seg *recycle_seg; int seg_size; }; static struct queue_seg * queue_seg_alloc (int seg_size) { struct queue_seg *seg; seg = (struct queue_seg *) XMALLOC (SEG_TOTAL_SIZE (seg_size)); if (! seg) return NULL; memset (seg, 0, sizeof (struct queue_seg)); return seg; } struct queue * queue_new (int seg_size) { struct queue *q; debug_start (); q = (struct queue *) XMALLOC (sizeof (struct queue)); if (q) q->tail_seg = q->head_seg = queue_seg_alloc (seg_size); if (! (q && q->head_seg)) { if (q) XFREE (q); debug ("allocation failed"); debug_end (); return NULL; } q->recycle_seg = NULL; q->seg_size = seg_size; debug_end (); return q; } void queue_free (struct queue *q) { struct queue_seg *seg, *next; for (seg = q->head_seg; seg; seg = next) { next = seg->next; XFREE (seg); } if (q->recycle_seg) XFREE (q->recycle_seg); XFREE (q); } unsigned long queue_deq (struct queue *q) { struct queue_seg *seg = q->head_seg; unsigned long *buf = SEG_BUF (seg); unsigned long val; debug_start (); /* Verify head segment is not empty. */ if (seg->head == seg->tail && ! seg->next) { debug ("queue empty"); debug_end (); return 0; } debug ("dequeued %lu (%p) seg=%p slot=%d", buf[seg->head], (void *) buf[seg->head], seg, seg->head); /* Dequeue head value. */ val = buf[seg->head++]; if (seg->head == q->seg_size) seg->head = 0; /* Deallocate empty head segment, if it isn't the last one. * Note: we "recycle" a single segment, to avoid repeated allocation / * deallocation when a contant length cyclic enq/deq sequence is due. */ if (seg->head == seg->tail && seg->next) { q->head_seg = seg->next; if (q->recycle_seg) XFREE (seg); else { debug ("recycling seg=%p", seg); memset (seg, 0, sizeof (struct queue_seg)); q->recycle_seg = seg; } } debug_end (); return val; } int queue_enq (struct queue *q, unsigned long val) { struct queue_seg *seg = q->tail_seg; unsigned long *buf = SEG_BUF (seg); debug_start (); debug ("enqueued %lu (%p) seg=%p slot=%d", val, (void *) val, seg, seg->tail); /* Enqueue value. */ buf[seg->tail++] = val; if (seg->tail == q->seg_size) seg->tail = 0; /* Allocate new segment if current was exhausted. */ if (seg->head == seg->tail) { if (q->recycle_seg) { debug ("using recycled segment seg=%p", q->recycle_seg); seg->next = q->recycle_seg; q->recycle_seg = NULL; } else { seg->next = queue_seg_alloc (q->seg_size); if (! seg->next) { if (! seg->tail--) seg->tail += q->seg_size; debug ("segment allocation failed, enqueue undone"); debug_end (); return -1; } } q->tail_seg = seg->next; } debug_end (); return 0; }
21.440252
76
0.597829
ce5dcd201017dcc206e6baadaa3bcc62fe076daa
4,404
c
C
main/audio.c
tbuen/music-esp
d7f6d65859ec8c788ced727648300ffb67b95337
[ "MIT" ]
null
null
null
main/audio.c
tbuen/music-esp
d7f6d65859ec8c788ced727648300ffb67b95337
[ "MIT" ]
null
null
null
main/audio.c
tbuen/music-esp
d7f6d65859ec8c788ced727648300ffb67b95337
[ "MIT" ]
null
null
null
#include "errno.h" #include "esp_log.h" #include "fcntl.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/task.h" #include "string.h" #include "sys/dirent.h" #include "sys/stat.h" #include "unistd.h" #include "vs1053.h" #include "audio.h" #define TASK_CORE 1 #define TASK_PRIO 19 #define STACK_SIZE 4096 static const char *TAG = "audio"; static SemaphoreHandle_t mutex; static TaskHandle_t handle; static audio_track *tracks; static char *file2play; static void audio_task(void *param); static esp_err_t read_dir(const char *path, audio_track **tracks); void audio_init(void) { if (handle) return; mutex = xSemaphoreCreateMutex(); if (xTaskCreatePinnedToCore(&audio_task, "audio-task", STACK_SIZE, NULL, TASK_PRIO, &handle, TASK_CORE) != pdPASS) { ESP_LOGE(TAG, "could not create task"); } } const audio_track *audio_get_tracks(void) { audio_track *t = NULL; if (xSemaphoreTake(mutex, pdMS_TO_TICKS(1000))) { t = tracks; } return t; } void audio_release_tracks(void) { xSemaphoreGive(mutex); } void audio_volume(volume_t *vol, bool set) { if (set) { if (vol->left > 0) vol->left = 0; if (vol->left < -127) vol->left = -127; if (vol->right > 0) vol->right = 0; if (vol->right < -127) vol->right = -127; uint8_t left = -2 * vol->left; uint8_t right = -2 * vol->right; vs_set_volume((left << 8) | right); } uint16_t v = vs_get_volume(); vol->left = (v >> 8) / -2; vol->right = (v & 0xFF) / -2; } bool audio_play(const char *filename) { if (!file2play) { file2play = strdup(filename); return true; } return false; } static uint8_t data[4096]; static void audio_task(void *param) { const char *path = "/sdcard"; esp_err_t res = ESP_FAIL; vs_init(); vs_set_volume(0x1414); for (;;) { if (res == ESP_FAIL) { res = vs_card_init(path); if (res == ESP_OK) { if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) { res = read_dir(path, &tracks); xSemaphoreGive(mutex); } } } if (res == ESP_OK) { if (file2play) { // start playing struct stat st; if (stat(file2play, &st) == 0) { ESP_LOGI(TAG, "Play file %s, size %ld", file2play, st.st_size); int fd = open(file2play, O_RDONLY, 0); if (fd >= 0) { int n; while ((n = read(fd, data, sizeof(data))) > 0) { //ESP_LOGI(TAG, "read %d bytes", n); vs_send_data(data, n); ESP_LOGI(TAG, "status: %s", vs_get_status()); taskYIELD(); } if (n == 0) { ESP_LOGI(TAG, "reached EOF!"); } else { ESP_LOGI(TAG, "error reading file!"); } close(fd); } } else { ESP_LOGI(TAG, "File file %s does not exist!", file2play); } free(file2play); file2play = NULL; } } vTaskDelay(pdMS_TO_TICKS(100)); } } static esp_err_t read_dir(const char *path, audio_track **tracks) { while (*tracks) { audio_track *tmp = *tracks; *tracks = tmp->next; free(tmp->filename); free(tmp); } DIR *dir = opendir(path); if (!dir) { ESP_LOGE(TAG, "error opening directory"); return ESP_FAIL; } struct dirent *entry; do { errno = 0; entry = readdir(dir); if (errno) { ESP_LOGE(TAG, "error reading directory"); return ESP_FAIL; } if (entry) { ESP_LOGI(TAG, "File found: %s", entry->d_name); if (strstr(entry->d_name, ".OGG")) { *tracks = calloc(1, sizeof(audio_track)); asprintf(&(*tracks)->filename, "%s/%s", path, entry->d_name); tracks = &(*tracks)->next; } } } while (entry); closedir(dir); return ESP_OK; }
27.018405
120
0.499546
0e039145a3b1ddc7f4b65994d53f501cfa23d012
297
h
C
JPAspect/Base/NSInvocation+OCAspects.h
CoderZhuXH/JPAspect
d34e5981b56dda2da77be1d5b1a5d12bd28defe5
[ "MIT" ]
1
2020-10-07T16:10:14.000Z
2020-10-07T16:10:14.000Z
JPAspect/Base/NSInvocation+OCAspects.h
CoderZhuXH/JPAspect
d34e5981b56dda2da77be1d5b1a5d12bd28defe5
[ "MIT" ]
null
null
null
JPAspect/Base/NSInvocation+OCAspects.h
CoderZhuXH/JPAspect
d34e5981b56dda2da77be1d5b1a5d12bd28defe5
[ "MIT" ]
null
null
null
// // NSInvocation+OCAspects.h // JPAspect // // Created by zzyong on 2018/10/18. // Copyright © 2018 zzyong. All rights reserved. // #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface NSInvocation (OCAspects) - (NSArray *)aspects_arguments; @end NS_ASSUME_NONNULL_END
14.85
49
0.737374
b892a00eb17a7f23734443c33031f1bb466941b7
1,319
h
C
code/src/localsearch.h
wtong1989/PFSP
eec9c5adbebe041296a634dafdd996439fd70cfa
[ "MIT" ]
1
2020-08-13T11:30:11.000Z
2020-08-13T11:30:11.000Z
code/src/localsearch.h
wtong1989/PFSP
eec9c5adbebe041296a634dafdd996439fd70cfa
[ "MIT" ]
null
null
null
code/src/localsearch.h
wtong1989/PFSP
eec9c5adbebe041296a634dafdd996439fd70cfa
[ "MIT" ]
2
2019-11-08T08:30:09.000Z
2021-11-22T14:44:29.000Z
#ifndef LOCAL_SEARCH_H #define LOCAL_SEARCH_H #include "pfspinstance.h" #include "utils.h" /* transpose move */ void transpose(std::vector<int>& sol, int pos); /* exchange move */ void exchange(std::vector<int>& sol, int elt1, int elt2); /* insert move */ void insert(std::vector<int>& sol, int elt, int pos); /* transpose improvement */ bool transposeImprovement(PfspInstance& instance, std::vector<int>& sol, long int& cost, bool bestImp); /* exchange improvement */ bool exchangeImprovement(PfspInstance& instance, std::vector<int>& sol, long int& cost, bool bestImp); /* insert improvement */ bool insertImprovement(PfspInstance& instance, std::vector<int>& sol, long int& cost, bool bestImp); /* transpose improvement with Metropolis condition */ bool transposeImprovementMetro(PfspInstance& instance, std::vector<int>& sol, long int& cost, double T); /* insert improvement with Metropolis condition */ bool insertImprovementMetro(PfspInstance& instance, std::vector<int>& sol, long int& cost, double T); /* Improve the solution */ void iterativeImprovement(PfspInstance& instance, std::vector< int > & sol, long int& cost, parameters& param); /* Variable neighbourhood Descent heuristic */ void VNDHeuristic(PfspInstance& instance, std::vector< int > & sol, long int& cost, parameters& param); #endif
34.710526
111
0.743745
33275eca53bd350fece8aa296fb576bc313c095a
2,785
h
C
api_emu.h
mraleph/dartvm_api_vs_ffi
d634ca401ced4a83e82a7299f6bef9cdc7de1109
[ "BSD-3-Clause" ]
2
2020-11-26T22:26:46.000Z
2021-04-15T02:13:37.000Z
api_emu.h
mraleph/dartvm_api_vs_ffi
d634ca401ced4a83e82a7299f6bef9cdc7de1109
[ "BSD-3-Clause" ]
null
null
null
api_emu.h
mraleph/dartvm_api_vs_ffi
d634ca401ced4a83e82a7299f6bef9cdc7de1109
[ "BSD-3-Clause" ]
3
2021-02-15T16:36:52.000Z
2021-04-15T02:13:41.000Z
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #ifndef API_EMU_H #define API_EMU_H #include <cstdarg> #include <cstdint> #include <cstdio> #include <utility> namespace emu { struct __Dart_Handle; typedef __Dart_Handle* Dart_Handle; struct Api { Dart_Handle (*Dart_IntegerToInt64)(Dart_Handle handle, int64_t* value); Dart_Handle (*Dart_NewInteger)(int64_t value); Dart_Handle (*Dart_GetPeer)(Dart_Handle handle, intptr_t* peer); Dart_Handle (*Dart_SetPeer)(Dart_Handle handle, intptr_t); Dart_Handle (*Dart_NewObject0)(const char* cls, const char* ctor); Dart_Handle (*Dart_Null)(); }; typedef struct { uint32_t argc; Dart_Handle result; Dart_Handle args[10]; // Don't care about more than 10 args. } NativeArguments, *Dart_NativeArguments; typedef void (*Dart_NativeFunction)(Dart_NativeArguments); typedef void* (*Dart_NativeFunctionTrampoline)(); Dart_Handle Dart_Null(); template <Dart_NativeFunction target> void* TrampolineTo0() { NativeArguments args; args.argc = 0; args.result = nullptr; target(&args); if (args.result == nullptr) { return Dart_Null(); } return args.result; } template <Dart_NativeFunction target> void* TrampolineTo1(Dart_Handle arg0) { NativeArguments args; args.argc = 1; args.result = nullptr; args.args[0] = arg0; target(&args); if (args.result == nullptr) { return args.args[0]; } return args.result; } template <Dart_NativeFunction target> void* TrampolineTo2(Dart_Handle arg0, Dart_Handle arg1) { NativeArguments args; args.argc = 2; args.result = nullptr; args.args[0] = arg0; args.args[1] = arg1; target(&args); if (args.result == nullptr) { return args.args[0]; } return args.result; } #define TRAMPOLINE_TO(Argc, F) \ (Dart_NativeFunctionTrampoline)(TrampolineTo##Argc<F>) void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle handle); Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, intptr_t n); Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, intptr_t n, int64_t* value); Dart_Handle Dart_NewInteger(int64_t value); Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, intptr_t* peer); Dart_Handle Dart_PropagateError(Dart_Handle error); bool Dart_IsError(Dart_Handle error); void Dart_AttachFinalizer(Dart_Handle handle, void* peer, intptr_t native_size, void (*finalizer)(void*)); } // namespace emu extern "C" emu::Api* __api_emu; #endif // API_EMU_H
26.273585
78
0.707002
c3075d5fc78728c21e911604b19b9363cedc3a2e
532
h
C
src/Generic/tokens/xx_Untokenizer.h
BBN-E/serif
1e2662d82fb1c377ec3c79355a5a9b0644606cb4
[ "Apache-2.0" ]
1
2022-03-24T19:57:00.000Z
2022-03-24T19:57:00.000Z
src/Generic/tokens/xx_Untokenizer.h
BBN-E/serif
1e2662d82fb1c377ec3c79355a5a9b0644606cb4
[ "Apache-2.0" ]
null
null
null
src/Generic/tokens/xx_Untokenizer.h
BBN-E/serif
1e2662d82fb1c377ec3c79355a5a9b0644606cb4
[ "Apache-2.0" ]
null
null
null
// Copyright 2008 by BBN Technologies Corp. // All Rights Reserved. #ifndef xx_UNTOKENIZER_H #define xx_UNTOKENIZER_H #include "Generic/tokens/Untokenizer.h" class GenericUntokenizer : public Untokenizer { private: friend class GenericUntokenizerFactory; public: void untokenize(LocatedString& source) const { }; private: GenericUntokenizer() {}; }; class GenericUntokenizerFactory: public Untokenizer::Factory { virtual Untokenizer *build() { return _new GenericUntokenizer(); } }; #endif
19
68
0.731203
473f3ddd3d2572ef33b82b32eb1dc8ba06bd6d9d
205
h
C
hello_scheduler/led.h
8bitgeek/GD32VF103_templates
ab2bc15353c6a581c1c681b0f6bc6af53f41d2a9
[ "MIT" ]
1
2020-07-30T09:18:38.000Z
2020-07-30T09:18:38.000Z
hello_scheduler/led.h
8bitgeek/GD32VF103_templates
ab2bc15353c6a581c1c681b0f6bc6af53f41d2a9
[ "MIT" ]
null
null
null
hello_scheduler/led.h
8bitgeek/GD32VF103_templates
ab2bc15353c6a581c1c681b0f6bc6af53f41d2a9
[ "MIT" ]
null
null
null
#ifndef _LED_H_ #define _LED_H_ #include <stdint.h> #include <stddef.h> #include <stdbool.h> extern void led_green(bool state); extern void led_red(bool state); extern void led_blue(bool state); #endif
15.769231
34
0.756098
546d9e9b82da70a0e792ce7a2f4b78be6e5fe2ff
4,452
c
C
kernel/lge/msm8226/drivers/usb/host/pehci/host/otg.c
Uswer/LineageOS-14.1_jag3gds
6fe76987fad4fca7b3c08743b067d5e79892e77f
[ "Apache-2.0" ]
1
2020-06-01T10:53:47.000Z
2020-06-01T10:53:47.000Z
kernel/lge/msm8226/drivers/usb/host/pehci/host/otg.c
Uswer/LineageOS-14.1_jag3gds
6fe76987fad4fca7b3c08743b067d5e79892e77f
[ "Apache-2.0" ]
1
2020-05-28T13:06:06.000Z
2020-05-28T13:13:15.000Z
kernel/lge/msm8226/drivers/usb/host/pehci/host/otg.c
Uswer/LineageOS-14.1_jag3gds
6fe76987fad4fca7b3c08743b067d5e79892e77f
[ "Apache-2.0" ]
null
null
null
/* * Copyright (C) ST-Ericsson AP Pte Ltd 2010 * * ISP1763 Linux OTG Controller driver : host * * This program is free software; you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by the Free Software Foundation; version * 2 of the License. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * This is a host controller driver file. OTG related events are handled here. * * Author : wired support <wired.support@stericsson.com> * */ /*hub device which connected with root port*/ struct usb_device *hubdev = 0; /* hub interrupt urb*/ struct urb *huburb; /*return otghub from here*/ struct usb_device * phci_register_otg_device(struct isp1763_dev *dev) { printk("OTG dev %x %d\n",(u32) hubdev, hubdev->devnum); if (hubdev && hubdev->devnum >= 0x2) { return hubdev; } return NULL; } EXPORT_SYMBOL(phci_register_otg_device); /*suspend the otg port(0) * needed when port is switching * from host to device * */ int phci_suspend_otg_port(struct isp1763_dev *dev, u32 command) { int status = 0; hubdev->otgstate = USB_OTG_SUSPEND; if (huburb->status == -EINPROGRESS) { huburb->status = 0; } huburb->status = 0; huburb->complete(huburb); return status; } EXPORT_SYMBOL(phci_suspend_otg_port); /*set the flag to enumerate the device*/ int phci_enumerate_otg_port(struct isp1763_dev *dev, u32 command) { /*set the flag to enumerate */ /*connect change interrupt will happen from * phci_intl_worker only * */ hubdev->otgstate = USB_OTG_ENUMERATE; if (huburb->status == -EINPROGRESS) { huburb->status = 0; } /*complete the urb */ huburb->complete(huburb); /*reset the otghub urb status */ huburb->status = -EINPROGRESS; return 0; } EXPORT_SYMBOL(phci_enumerate_otg_port); /*host controller resume sequence at otg port*/ int phci_resume_otg_port(struct isp1763_dev *dev, u32 command) { printk("Resume is called\n"); hubdev->otgstate = USB_OTG_RESUME; if (huburb->status == -EINPROGRESS) { huburb->status = 0; } /*complete the urb */ huburb->complete(huburb); /*reset the otghub urb status */ huburb->status = -EINPROGRESS; return 0; } EXPORT_SYMBOL(phci_resume_otg_port); /*host controller remote wakeup sequence at otg port*/ int phci_remotewakeup(struct isp1763_dev *dev) { printk("phci_remotewakeup_otg_port is called\n"); hubdev->otgstate = USB_OTG_REMOTEWAKEUP; if(huburb->status == -EINPROGRESS) huburb->status = 0; /*complete the urb*/ #if ((defined LINUX_269) || defined (LINUX_2611)) huburb->complete(huburb,NULL); #else huburb->complete(huburb); #endif /*reset the otghub urb status*/ huburb->status = -EINPROGRESS; return 0; } EXPORT_SYMBOL(phci_remotewakeup); /*host controller wakeup sequence at otg port*/ int phci_resume_wakeup(struct isp1763_dev *dev) { printk("phci_wakeup_otg_port is called\n"); #if 0 hubdev->otgstate = USB_OTG_WAKEUP_ALL; if(huburb->status == -EINPROGRESS) #endif huburb->status = 0; /*complete the urb*/ #if ((defined LINUX_269) || defined (LINUX_2611)) huburb->complete(huburb,NULL); #else huburb->complete(huburb); #endif /*reset the otghub urb status*/ huburb->status = -EINPROGRESS; return 0; } EXPORT_SYMBOL(phci_resume_wakeup); struct isp1763_driver *host_driver; struct isp1763_driver *device_driver; void pehci_delrhtimer(struct isp1763_dev *dev) { struct usb_hcd *usb_hcd = container_of(huburb->dev->parent->bus, struct usb_hcd, self); del_timer_sync(&usb_hcd->rh_timer); del_timer(&usb_hcd->rh_timer); } EXPORT_SYMBOL(pehci_delrhtimer); int pehci_Deinitialize(struct isp1763_dev *dev) { dev -= 2; if (dev->index == 0) { if (dev->driver) { if (dev->driver->powerdown) { dev->driver->powerdown(dev); } } } return 0; } EXPORT_SYMBOL(pehci_Deinitialize); int pehci_Reinitialize(struct isp1763_dev *dev) { dev -= 2; if (dev->index == 0) { if(dev->driver->powerup){ dev->driver->powerup(dev); } } return 0; } EXPORT_SYMBOL(pehci_Reinitialize);
23.431579
93
0.712938
b8624f34bd8b05d1491b133639fc5a43f4c162f9
1,584
h
C
FsmManager.h
Tyler716/FiniteStateMachine
3230121b7325daebca0d337e05a46fba72cbf72e
[ "Apache-2.0" ]
null
null
null
FsmManager.h
Tyler716/FiniteStateMachine
3230121b7325daebca0d337e05a46fba72cbf72e
[ "Apache-2.0" ]
null
null
null
FsmManager.h
Tyler716/FiniteStateMachine
3230121b7325daebca0d337e05a46fba72cbf72e
[ "Apache-2.0" ]
null
null
null
#ifndef _FSMMANAGER_H_ #define _FSMMANAGER_H_ #include "FiniteStateMachine.h" using namespace std; class FsmMapBase { public: virtual ~FsmMapBase() {} template<typename T> map<int, FiniteStateMachine<T>*> get(); }; template<typename T> class FsmMap : public FsmMapBase { public: FsmMap(){}; virtual ~FsmMap() { for(map<int, FiniteStateMachine<T>* >::iterator it = _fsmMap.begin(); it != _fsmMap.end(); ++it) { delete it->second; } _fsmMap.clear(); } map<int, FiniteStateMachine<T>*> get() { return _fsmMap; } private: map<int, FiniteStateMachine<T>*> _fsmMap; }; template<typename T> map<int, FiniteStateMachine<T>*> FsmMapBase::get() { return dynamic_cast<FsmMap<T>*>(this)->get(); } class FsmManager { public: static FsmManager *Instance(); public: template<typename T> FiniteStateMachine<T>* CreateStateMachine(int id); protected: FsmManager(); virtual ~FsmManager(); private: FsmMapBase _fsmMap; }; template<typename T> FiniteStateMachine<T>* FsmManager::CreateStateMachine(int id) { FiniteStateMachine<T> *fsm = NULL; map<int, FiniteStateMachine<T>* > fsmMap = _fsmMap.get<T>(); if(fsmMap.find(id) != fsmMap.end()) { fsm = fsmMap[id]; } else { pair<map<int, FiniteStateMachine<T>* >::iterator, bool> Insert_Pair = fsmMap.insert(make_pair(id, new FiniteStateMachine<T>())); if(Insert_Pair.second) { fsm = Insert_Pair.first->second; } } return fsm; } #endif
19.8
136
0.626263
5038f92cea72a4433f70958c9a70edaf06778d6c
654
h
C
jata/libraries/RestKit-RestKit-991bd5c/Code/ObjectMapping/RKObjectPropertyInspector.h
JordanForeman/Just-Another-Twitter-App--JATA-
50559f541ad6a9d8cfb08e8f91824e664a18fbfe
[ "MIT" ]
null
null
null
jata/libraries/RestKit-RestKit-991bd5c/Code/ObjectMapping/RKObjectPropertyInspector.h
JordanForeman/Just-Another-Twitter-App--JATA-
50559f541ad6a9d8cfb08e8f91824e664a18fbfe
[ "MIT" ]
null
null
null
jata/libraries/RestKit-RestKit-991bd5c/Code/ObjectMapping/RKObjectPropertyInspector.h
JordanForeman/Just-Another-Twitter-App--JATA-
50559f541ad6a9d8cfb08e8f91824e664a18fbfe
[ "MIT" ]
null
null
null
// // RKObjectPropertyInspector.h // RestKit // // Created by Blake Watters on 3/4/10. // Copyright 2010 Two Toasters. All rights reserved. // #import <Foundation/Foundation.h> @interface RKObjectPropertyInspector : NSObject { NSMutableDictionary* _cachedPropertyNamesAndTypes; } + (RKObjectPropertyInspector*)sharedInspector; /** * Returns a dictionary of names and types for the properties of a given class */ - (NSDictionary *)propertyNamesAndTypesForClass:(Class)objectClass; /** Returns the Class type of the specified property on the object class */ - (Class)typeForProperty:(NSString*)propertyName ofClass:(Class)objectClass; @end
22.551724
78
0.762997
fd51cdb36919b674a15dec521ba81fef5fe1a26d
441
c
C
exercises/perimetro_triangulo.c
KarlaCP/C
3ff3a991c981cfed6fa6a17566cbba5b4f366b50
[ "MIT" ]
null
null
null
exercises/perimetro_triangulo.c
KarlaCP/C
3ff3a991c981cfed6fa6a17566cbba5b4f366b50
[ "MIT" ]
null
null
null
exercises/perimetro_triangulo.c
KarlaCP/C
3ff3a991c981cfed6fa6a17566cbba5b4f366b50
[ "MIT" ]
1
2020-10-29T17:28:45.000Z
2020-10-29T17:28:45.000Z
#include <stdio.h> int main(){ float a, b, c, P; //Declarando variables de tipo flotante printf("Ingresa la longitud del lado a: "); scanf("%f", &a); printf("Ingresa la longitud del lado b: "); scanf("%f", &b); printf("Ingresa la longitud del lado c: "); scanf("%f", &c); printf("Perimetro\n"); //Imprimiendo título P=a+b+c; //Suma de los lados del triángulo printf("\tEl perimetro del triangulo es = %0.2f.\n",P); return 0; }
27.5625
58
0.641723
25da7583fbab8dbf245e6e3ccab0fb0602e50d32
972
h
C
MACHINATH/MACHINATH/pickup.h
susajin/MACHINATH
1e75097f86218f143411885240bbcf211a6e9c99
[ "MIT" ]
null
null
null
MACHINATH/MACHINATH/pickup.h
susajin/MACHINATH
1e75097f86218f143411885240bbcf211a6e9c99
[ "MIT" ]
null
null
null
MACHINATH/MACHINATH/pickup.h
susajin/MACHINATH
1e75097f86218f143411885240bbcf211a6e9c99
[ "MIT" ]
null
null
null
#pragma once #include "collider.h" #include "mesh.h" #include "map.h" // pickup class - medals, powerups etc class Pickup : public MeshObject { public: BoxCollider col; int mapId; // constructor Pickup(int mapId, Transform trans, MESH_NAME mesh, SHADER_TYPE type, float width, float height, float depth, bool isStatic = true, GameObject* parent = nullptr) : mapId(mapId), MeshObject(trans, mesh, type, parent), col(BoxCollider(this, width, height, depth, {0,0,0}, isStatic)) {} // destructor ~Pickup() {} // draw void Draw() override; }; // spawn pickup at position void SpawnPickup(D3DXVECTOR3 position, Map* parent = nullptr); void SpawnPickup(float posX, float posY, float posZ, Map* parent = nullptr); // delete every pickup with the given mapId void CleanPickup(int mapId); // returns a vector of every pickup std::vector<Pickup*>* GetPickup(); void InitPickup(); void UninitPickup(); void UpdatePickup();
24.3
164
0.691358
46c4d420a68b2dac57dac80aa75646facb73c001
985
c
C
user/pingpong.c
AlexPeng0829/xv6-riscv-fall19
515c084bb2bcce71fe8417d4bae206dfa142d9e1
[ "MIT-0" ]
null
null
null
user/pingpong.c
AlexPeng0829/xv6-riscv-fall19
515c084bb2bcce71fe8417d4bae206dfa142d9e1
[ "MIT-0" ]
null
null
null
user/pingpong.c
AlexPeng0829/xv6-riscv-fall19
515c084bb2bcce71fe8417d4bae206dfa142d9e1
[ "MIT-0" ]
null
null
null
#include "kernel/types.h" #include "kernel/stat.h" #include "user/user.h" int main(int argc, char **argv) { int parent_fd[2]; int child_fd[2]; char *ping = "ping"; char *pong = "pong"; char buffer[8]; // store "ping" or "pong", at least 5 bytes if (argc != 1) { fprintf(2, "usage: pingpong\n"); exit(-1); } pipe(parent_fd); pipe(child_fd); if (fork() == 0) { if (read(parent_fd[0], (void *)buffer, sizeof(buffer)) > 0) { write(child_fd[1], (void *)pong, sizeof(pong)); printf("%d: received %s\n", getpid(), buffer); } else { fprintf(2, "read error!\n"); } exit(0); } write(parent_fd[1], (void *)ping, sizeof(ping)); if (read(child_fd[0], (void *)buffer, sizeof(buffer)) > 0) { printf("%d: received %s\n", getpid(), buffer); } else { fprintf(2, "read error!\n"); } exit(0); }
22.386364
67
0.490355
9433be62c3a0df0488580e83e138b6af239a6f15
4,591
h
C
src/Microsoft.DotNet.Wpf/src/WpfGfx/core/resources/TileBrushUtils.h
jonfortescue/wpf
6d35e1a0539cc5cc7a6111a11b781f52cfc71fc2
[ "MIT" ]
5,937
2018-12-04T16:32:50.000Z
2022-03-31T09:48:37.000Z
src/Microsoft.DotNet.Wpf/src/WpfGfx/core/resources/TileBrushUtils.h
jonfortescue/wpf
6d35e1a0539cc5cc7a6111a11b781f52cfc71fc2
[ "MIT" ]
4,151
2018-12-04T16:38:19.000Z
2022-03-31T18:41:14.000Z
src/Microsoft.DotNet.Wpf/src/WpfGfx/core/resources/TileBrushUtils.h
jonfortescue/wpf
6d35e1a0539cc5cc7a6111a11b781f52cfc71fc2
[ "MIT" ]
1,084
2018-12-04T16:24:21.000Z
2022-03-30T13:52:03.000Z
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. //+----------------------------------------------------------------------------- // // // $TAG ENGR // $Module: win_mil_graphics_brush // $Keywords: // // $Description: // Definition of tile brush methods used to create intermediate // representations from user-defined state. // // $ENDTAG // //------------------------------------------------------------------------------ //+----------------------------------------------------------------------------- // // Class: // CTileBrushUtils // // Synopsis: // Contains static utility methods for creating tile brush representations // from user-specified state. // //------------------------------------------------------------------------------ class CTileBrushUtils { public: static HRESULT CreateTileBrushIntermediate( __in_ecount(1) const BrushContext *pBrushContext, __in_ecount(1) const CMILMatrix *pmatContentToViewport, __in_ecount(1) const CMILMatrix *pmatViewportToWorld, __in_ecount(1) const MilPointAndSizeD *prcdViewport, __in_ecount_opt(1) const BrushCachingParameters *pCachingParams, MilTileMode::Enum tileMode, __deref_out_ecount_opt(1) IWGXBitmapSource **ppCachedSurface, __deref_out_ecount_opt(1) IMILRenderTargetBitmap **ppIRenderTarget, __deref_out_ecount_opt(1) CDrawingContext **ppDrawingContext, __out_ecount(1) CMILMatrix* pmatSurfaceToXSpace, __out_ecount(1) BOOL *pfBrushIsEmpty, __out_ecount_opt(1) BOOL *pfUseSourceClip, __out_ecount_opt(1) BOOL *pfSourceClipIsEntireSource, __out_ecount_opt(1) CParallelogram *pSourceClipXSpace, __out_ecount(1) XSpaceDefinition *pXSpaceDefinition ); static HRESULT GetIntermediateBaseTile( __in_ecount(1) CMilTileBrushDuce *pTileBrush, __in_ecount(1) const BrushContext *pBrushContext, __in_ecount(1) const CMILMatrix *pContentToViewport, __in_ecount(1) const CMILMatrix *pmatViewportToWorld, __in_ecount(1) const MilPointAndSizeD *pViewport, __in_ecount_opt(1) const BrushCachingParameters *pCachingParams, __in MilTileMode::Enum tileMode, __out_ecount(1) IWGXBitmapSource **ppBaseTile, __out_ecount(1) CMILMatrix *pmatIntermediateBitmapToXSpace, __out_ecount(1) BOOL *pfTileIsEmpty, __out_ecount(1) BOOL *pfUseSourceClip, __out_ecount(1) BOOL *pfSourceClipIsEntireSource, __out_ecount(1) CParallelogram *pSourceClipXeSpace, __out_ecount(1) XSpaceDefinition *pXSpaceDefinition ); static VOID CalculateTileBrushMapping( __in_ecount_opt(1) const CMILMatrix *pTransform, __in_ecount_opt(1) const CMILMatrix *pRelativeTransform, MilStretch::Enum stretch, MilHorizontalAlignment::Enum alignmentX, MilVerticalAlignment::Enum alignmentY, MilBrushMappingMode::Enum viewportUnits, MilBrushMappingMode::Enum viewboxUnits, __in_ecount(1) const MilPointAndSizeD *pBrushSizingBounds, __in_ecount(1) const MilPointAndSizeD *pContentBounds, REAL rContentScaleX, REAL rContentScaleY, __inout_ecount(1) MilPointAndSizeD *pViewport, __inout_ecount(1) MilPointAndSizeD *pViewbox, __out_ecount_opt(1) CMILMatrix *pContentToViewport, __out_ecount_opt(1) CMILMatrix *pmatViewportToWorld, __out_ecount(1) CMILMatrix *pContentToWorld, __out_ecount(1) BOOL *pfBrushIsEmpty ); static VOID CalculateViewboxToViewportMapping( __in_ecount(1) const MilPointAndSizeD *prcViewport, __in_ecount(1) const MilPointAndSizeD *prcViewbox, MilStretch::Enum stretch, MilHorizontalAlignment::Enum halign, MilVerticalAlignment::Enum valign, __out_ecount(1) CMILMatrix *pmatViewboxToViewport ); private: static VOID GetAbsoluteViewRectangles( MilBrushMappingMode::Enum viewportUnits, MilBrushMappingMode::Enum viewboxUnits, __in_ecount(1) const MilPointAndSizeD *pBrushSizingBounds, __in_ecount(1) const MilPointAndSizeD *pContentBounds, __inout_ecount(1) MilPointAndSizeD *pViewport, __inout_ecount(1) MilPointAndSizeD *pViewbox, __out_ecount(1) BOOL *pfIsEmpty ); };
38.90678
80
0.656937
5a498c898cd6494cb6ef9d725b5c500058d463b3
1,776
h
C
eip/include/huaweicloud/eip/v2/model/BatchDeletePublicipTagsRequestBody.h
yangzhaofeng/huaweicloud-sdk-cpp-v3
4f3caac5ba9a9b75b4e5fd61683d1c4d57ec1c23
[ "Apache-2.0" ]
5
2021-03-03T08:23:43.000Z
2022-02-16T02:16:39.000Z
eip/include/huaweicloud/eip/v2/model/BatchDeletePublicipTagsRequestBody.h
yangzhaofeng/huaweicloud-sdk-cpp-v3
4f3caac5ba9a9b75b4e5fd61683d1c4d57ec1c23
[ "Apache-2.0" ]
null
null
null
eip/include/huaweicloud/eip/v2/model/BatchDeletePublicipTagsRequestBody.h
yangzhaofeng/huaweicloud-sdk-cpp-v3
4f3caac5ba9a9b75b4e5fd61683d1c4d57ec1c23
[ "Apache-2.0" ]
7
2021-02-26T13:53:35.000Z
2022-03-18T02:36:43.000Z
#ifndef HUAWEICLOUD_SDK_EIP_V2_MODEL_BatchDeletePublicipTagsRequestBody_H_ #define HUAWEICLOUD_SDK_EIP_V2_MODEL_BatchDeletePublicipTagsRequestBody_H_ #include <huaweicloud/eip/v2/EipExport.h> #include <huaweicloud/core/utils/ModelBase.h> #include <huaweicloud/core/http/HttpResponse.h> #include <huaweicloud/eip/v2/model/ResourceTagOption.h> #include <string> #include <vector> namespace HuaweiCloud { namespace Sdk { namespace Eip { namespace V2 { namespace Model { using namespace HuaweiCloud::Sdk::Core::Utils; using namespace HuaweiCloud::Sdk::Core::Http; /// <summary> /// 批量操作资源标签的请求体 /// </summary> class HUAWEICLOUD_EIP_V2_EXPORT BatchDeletePublicipTagsRequestBody : public ModelBase { public: BatchDeletePublicipTagsRequestBody(); virtual ~BatchDeletePublicipTagsRequestBody(); ///////////////////////////////////////////// /// ModelBase overrides void validate() override; web::json::value toJson() const override; bool fromJson(const web::json::value& json) override; ///////////////////////////////////////////// /// BatchDeletePublicipTagsRequestBody members /// <summary> /// 标签列表 /// </summary> std::vector<ResourceTagOption>& getTags(); bool tagsIsSet() const; void unsettags(); void setTags(const std::vector<ResourceTagOption>& value); /// <summary> /// 操作标识 delete:删除 action为delete时,value可选 /// </summary> std::string getAction() const; bool actionIsSet() const; void unsetaction(); void setAction(const std::string& value); protected: std::vector<ResourceTagOption> tags_; bool tagsIsSet_; std::string action_; bool actionIsSet_; }; } } } } } #endif // HUAWEICLOUD_SDK_EIP_V2_MODEL_BatchDeletePublicipTagsRequestBody_H_
22.481013
76
0.690878
0c8e9fba0d7078a9310bfa59c44bb7846b8b3cd7
792
h
C
Akel_Studio/src/Panels/browser.h
NurissGames/Akel
9580f7eb1d4a0dbe20459bd83a5e681a040c29de
[ "MIT" ]
3
2021-12-01T17:59:30.000Z
2022-01-22T20:29:08.000Z
Akel_Studio/src/Panels/browser.h
NurissGames/Akel
9580f7eb1d4a0dbe20459bd83a5e681a040c29de
[ "MIT" ]
null
null
null
Akel_Studio/src/Panels/browser.h
NurissGames/Akel
9580f7eb1d4a0dbe20459bd83a5e681a040c29de
[ "MIT" ]
1
2021-12-01T17:59:32.000Z
2021-12-01T17:59:32.000Z
// This file is a part of Akel Studio // Authors : @kbz_8 // Created : 10/03/2022 // Updated : 12/03/2022 #ifndef __AK_STUDIO_BROWSER__ #define __AK_STUDIO_BROWSER__ #include <AkSpch.h> #include <Panels/Base/panel.h> class Browser : public Panel { public: Browser(std::shared_ptr<Ak::ELTM> eltm); void onUpdate(Ak::Maths::Vec2<int>& size) override; ~Browser() = default; private: void browser(); void content(); bool is_there_subdir(std::string dir); std::string getSize(std::uintmax_t size); void dir(std::string directory); std::string _current_file; std::string _parent = Ak::Core::getMainDirPath(); std::set<std::filesystem::directory_entry> _files; }; #endif // __AK_STUDIO_BROWSER__
24
59
0.646465
677715fed07785b170b437c029b06d0bd40241f5
4,688
h
C
terrain/voxel_terrain.h
blockspacer/godot_voxel
7ced53ba6bcefefb42efe5f458d357932ccdf84a
[ "MIT" ]
1
2019-08-06T23:32:41.000Z
2019-08-06T23:32:41.000Z
terrain/voxel_terrain.h
blockspacer/godot_voxel
7ced53ba6bcefefb42efe5f458d357932ccdf84a
[ "MIT" ]
null
null
null
terrain/voxel_terrain.h
blockspacer/godot_voxel
7ced53ba6bcefefb42efe5f458d357932ccdf84a
[ "MIT" ]
null
null
null
#ifndef VOXEL_TERRAIN_H #define VOXEL_TERRAIN_H #include "../math/rect3i.h" #include "../math/vector3i.h" #include "../streams/voxel_stream.h" #include "../util/zprofiling.h" #include "voxel_data_loader.h" #include "voxel_mesh_updater.h" #include <scene/3d/spatial.h> class VoxelMap; class VoxelLibrary; // Infinite paged terrain made of voxel blocks all with the same level of detail. // Voxels are polygonized around the viewer by distance in a large cubic space. // Data is streamed using a VoxelStream. class VoxelTerrain : public Spatial { GDCLASS(VoxelTerrain, Spatial) public: // TODO Remove this, it's obsoleted by VoxelBlock::MeshState enum BlockDirtyState { BLOCK_NONE, // There is no block BLOCK_LOAD, // The block is loading BLOCK_UPDATE_NOT_SENT, // The block needs an update but wasn't sent yet BLOCK_UPDATE_SENT, // The block needs an update which was sent BLOCK_IDLE // The block is up to date }; VoxelTerrain(); ~VoxelTerrain(); void set_stream(Ref<VoxelStream> stream); Ref<VoxelStream> get_stream() const; void set_voxel_library(Ref<VoxelLibrary> library); Ref<VoxelLibrary> get_voxel_library() const; void make_block_dirty(Vector3i bpos); //void make_blocks_dirty(Vector3i min, Vector3i size); void make_voxel_dirty(Vector3i pos); void make_area_dirty(Rect3i box); bool is_block_dirty(Vector3i bpos) const; void set_generate_collisions(bool enabled); bool get_generate_collisions() const { return _generate_collisions; } int get_view_distance() const; void set_view_distance(int distance_in_voxels); void set_viewer_path(NodePath path); NodePath get_viewer_path() const; void set_material(unsigned int id, Ref<Material> material); Ref<Material> get_material(unsigned int id) const; bool is_smooth_meshing_enabled() const; void set_smooth_meshing_enabled(bool enabled); Ref<VoxelMap> get_map() { return _map; } struct Stats { VoxelMeshUpdater::Stats updater; VoxelDataLoader::Stats stream; uint32_t mesh_alloc_time; int updated_blocks; int dropped_stream_blocks; int dropped_updater_blocks; int remaining_main_thread_blocks; uint64_t time_detect_required_blocks; uint64_t time_send_load_requests; uint64_t time_process_load_responses; uint64_t time_send_update_requests; uint64_t time_process_update_responses; Stats() : mesh_alloc_time(0), updated_blocks(0), dropped_stream_blocks(0), dropped_updater_blocks(0), remaining_main_thread_blocks(0), time_detect_required_blocks(0), time_send_load_requests(0), time_process_load_responses(0), time_send_update_requests(0), time_process_update_responses(0) {} }; protected: void _notification(int p_what); private: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; void _process(); void make_all_view_dirty_deferred(); void reset_updater(); Spatial *get_viewer(NodePath path) const; void immerge_block(Vector3i bpos); Dictionary get_statistics() const; static void _bind_methods(); // Convenience Vector3 _voxel_to_block_binding(Vector3 pos); Vector3 _block_to_voxel_binding(Vector3 pos); //void _force_load_blocks_binding(Vector3 center, Vector3 extents) { force_load_blocks(center, extents); } void _make_voxel_dirty_binding(Vector3 pos) { make_voxel_dirty(pos); } void _make_area_dirty_binding(AABB aabb); Variant _raycast_binding(Vector3 origin, Vector3 direction, real_t max_distance); void set_voxel(Vector3 pos, int value, int c); int get_voxel(Vector3 pos, int c); BlockDirtyState get_block_state(Vector3 p_bpos) const; private: // Voxel storage Ref<VoxelMap> _map; // How many blocks to load around the viewer int _view_distance_blocks; // TODO Terrains only need to handle the visible portion of voxels, which reduces the bounds blocks to handle. // Therefore, could a simple grid be better to use than a hashmap? Vector<Vector3i> _blocks_pending_load; Vector<Vector3i> _blocks_pending_update; HashMap<Vector3i, BlockDirtyState, Vector3iHasher> _dirty_blocks; // TODO Rename _block_states Vector<VoxelMeshUpdater::OutputBlock> _blocks_pending_main_thread_update; Ref<VoxelStream> _stream; VoxelDataLoader *_stream_thread; Ref<VoxelLibrary> _library; VoxelMeshUpdater *_block_updater; NodePath _viewer_path; Vector3i _last_viewer_block_pos; int _last_view_distance_blocks; bool _generate_collisions; bool _run_in_editor; bool _smooth_meshing_enabled; Ref<Material> _materials[VoxelMesherBlocky::MAX_MATERIALS]; Stats _stats; }; VARIANT_ENUM_CAST(VoxelTerrain::BlockDirtyState) #endif // VOXEL_TERRAIN_H
29.484277
111
0.787756
efca9441747a316ed6bb46cae116571061f81c1e
35,440
h
C
virtools/VxVector.h
yyc12345/BallanceModLoader
a03ff7ea163c0648e444c4d04cbd1de5071bdd6a
[ "MIT" ]
36
2020-05-30T10:00:49.000Z
2022-03-20T09:01:54.000Z
virtools/VxVector.h
yyc12345/BallanceModLoader
a03ff7ea163c0648e444c4d04cbd1de5071bdd6a
[ "MIT" ]
17
2020-07-16T15:50:31.000Z
2022-02-11T12:40:17.000Z
virtools/VxVector.h
yyc12345/BallanceModLoader
a03ff7ea163c0648e444c4d04cbd1de5071bdd6a
[ "MIT" ]
5
2020-08-02T01:45:40.000Z
2021-12-01T02:25:08.000Z
/*************************************************************************/ /* File : VxVector.h */ /* Author : Romain SIDIDRIS */ /* */ /* Virtools SDK */ /* Copyright (c) Virtools 2000, All Rights Reserved. */ /*************************************************************************/ #ifndef VXVECTOR_H #define VXVECTOR_H #ifdef macintosh #include "VxMacHeader.h" #endif VX_EXPORT int radToAngle(float val); VX_EXPORT float Tsin(int angle); VX_EXPORT float Tcos(int angle); struct VxCompressedVector; struct VxCompressedVectorOld; class VxMatrix; //______________________ // some global variables /******************************************************* {filename:VxVector} Name: VxVector Summary: Class representation of a Vector in 3 dimensions Remarks: A VxVector is defined as: typedef struct VxVector { union { struct { float x,y,z; }; float v[3]; }; } Elements can be accessed with x,y,z value or through the array v. ***********************************************************/ struct VxVector { #if defined(_LINUX) float x,y,z; #else union { struct { float x,y,z; }; float v[3]; }; #endif public: // ===================================== // Constructors // ===================================== VxVector(); VxVector(float f); VxVector(float _x, float _y, float _z); VxVector(const float f[3]); void Absolute(); /************************************************* Summary: Returns the square magnitude(length) of a vector. Return Value: Square magnitude of the vector Remarks: This method returns the square magnitude (length*length) of the vector v. See also: Magnitude *************************************************/ float SquareMagnitude () const {return x*x + y*y + z*z;} /************************************************* Summary: Returns the magnitude(length) of a vector. Return Value: Magnitude of the vector Remarks: This method returns the length of the vector v. WARNING: Calling this function with a null vector (0,0,0) will return an indefinite value (constant NaN - not a number) See also: SquareMagnitude *************************************************/ float Magnitude () const {return sqrtf(SquareMagnitude());} // ===================================== // Access grants // ===================================== const float& operator[](int i) const; float& operator[](int i); void Set(float X,float Y,float Z); VxVector& operator += (const VxVector& v); VxVector& operator -= (const VxVector& v); VxVector& operator *= (const VxVector& v); VxVector& operator /= (const VxVector& v); VxVector& operator *= (float s); VxVector& operator /= (float s); VX_EXPORT VxVector& operator = (const VxCompressedVector& v); float Dot(const VxVector& iV) const {return x*iV.x + y * iV.y + z * iV.z;} VxVector operator + (float s) const {return VxVector(x+s,y+s,z+s);} VxVector operator - (float s) const {return VxVector(x-s,y-s,z-s);} // ===================================== // Unary operators // ===================================== friend const VxVector operator + (const VxVector& v); friend const VxVector operator - (const VxVector& v); // ===================================== // Binary operators // ===================================== // Addition and subtraction friend const VxVector operator + (const VxVector& v1, const VxVector& v2); friend const VxVector operator - (const VxVector& v1, const VxVector& v2); // Scalar multiplication and division friend const VxVector operator * (const VxVector& v, float s); friend const VxVector operator * (float s, const VxVector& v); friend const VxVector operator / (const VxVector& v, float s); // Memberwise multiplication and division friend const VxVector operator * (const VxVector& v1, const VxVector& v2); friend const VxVector operator / (const VxVector& v1, const VxVector& v2); // Vector dominance friend int operator < (const VxVector& v1, const VxVector& v2); friend int operator <= (const VxVector& v1, const VxVector& v2); // Bitwise equality friend int operator == (const VxVector& v1, const VxVector& v2); friend int operator != (const VxVector& v1, const VxVector& v2); // Return min/max component of the input vector friend float Min (const VxVector& v); friend float Max (const VxVector& v); // Return memberwise min/max of input vectors friend const VxVector Minimize (const VxVector& v1, const VxVector& v2); friend const VxVector Maximize (const VxVector& v1, const VxVector& v2); // Interpolate two vectors friend const VxVector Interpolate (float step, const VxVector& v1, const VxVector& v2); VX_EXPORT void Normalize(); VX_EXPORT void Rotate(const VxMatrix& M); VX_EXPORT const static VxVector& axisX(); VX_EXPORT const static VxVector& axisY(); VX_EXPORT const static VxVector& axisZ(); VX_EXPORT const static VxVector& axis0(); VX_EXPORT const static VxVector& axis1(); const static VxVector m_AxisX; const static VxVector m_AxisY; const static VxVector m_AxisZ; const static VxVector m_Axis0; const static VxVector m_Axis1; }; /************************************************* Name: SquareMagnitude Summary: Returns the square magnitude(length) of a vector. Input Arguments: v: a pointer to a VxVector which magnitude should be returned Return Value: Square magnitude of v Remarks: This method returns the square magnitude (length*length) of the vector v. See also: Magnitude *************************************************/ inline float SquareMagnitude (const VxVector& v) {return v.x*v.x + v.y*v.y + v.z*v.z;} /************************************************* Name: Magnitude Summary: Returns the magnitude(length) of a vector. Input Arguments: v: a pointer to a VxVector which magnitude should be returned Return Value: Magnitude of v Remarks: This method returns the length of the vector v. WARNING: Calling this function with a null vector (0,0,0) will return an indefinite value (constant NaN - not a number) See also: SquareMagnitude *************************************************/ inline float Magnitude (const VxVector& v) {return sqrtf(SquareMagnitude(v));} /************************************************* Name: InvSquareMagnitude Summary: Returns the inverse square magnitude(length) of a vector. Input Arguments: v: a pointer to a VxVector which inverse magnitude should be returned Return Value: Inverse Square magnitude of v Remarks: This method returns the inverse square magnitude (1/(length*length)) of the vector v. See also: SquareMagnitude *************************************************/ inline float InvSquareMagnitude (const VxVector& v) {return 1.0f/SquareMagnitude(v);} /************************************************* Name: InvMagnitude Summary: Returns the inverse magnitude(length) of a vector. Input Arguments: v: a pointer to a VxVector which inverse magnitude should be returned Remarks: This method returns the inverse magnitude (1/length) of the vector v. WARNING: Calling this function with a null vector (0,0,0) will return an indefinite value (constant NaN - not a number) Return Value: Inverse magnitude of v See also: Magnitude *************************************************/ inline float InvMagnitude (const VxVector& v) {return 1.0f/Magnitude(v);} /************************************************* Name: Normalize Summary: Returns a normalized vector (length=1). Input Arguments: Vect: a pointer to a VxVector v: Vector to normalize. Return Value: A Vector equal to Vect Normalized. Remarks: This method returns a vector equal to Vect normalized to length 1.0. WARNING: Calling this function with a null vector (0,0,0) will return an indefinite vector (constant NaN - not a number). This function is more precise than VxVector::Normalize. See also: Magnitude,VxVector,Vx2DVector *************************************************/ inline const VxVector Normalize (const VxVector& v) {return v*InvMagnitude(v);} // Necessary for binding in VSL #if defined(macintosh) || defined(PSX2) const VxVector NormalizeVectorNotInlined(const VxVector& v); #endif inline const VxVector Normalize (const VxVector *vect) {return Normalize(*vect);} /************************************************* Name: DotProduct Summary: Calculates the dot product of two vectors. Input Arguments: Vect1: First source Vector. Vect2: Second source Vector. Return Value: A float result of the dot product of Vect1.Vect2. Remarks: See also: VxVector,Vx2DVector *************************************************/ inline float DotProduct (const VxVector& v1, const VxVector& v2) { return v1.x*v2.x + v1.y * v2.y + v1.z * v2.z; } /************************************************* Name: CrossProduct Summary: Calculates the cross product of two vectors. Input Arguments: Vect1: First source Vector. Vect2: Second source Vector. Return Value: A VxVector result of the cross product of Vect1^Vect2. See also: VxVector *************************************************/ inline const VxVector CrossProduct (const VxVector& Vect1, const VxVector& Vect2) { return VxVector(Vect1.y * Vect2.z - Vect1.z * Vect2.y, Vect1.z * Vect2.x - Vect1.x * Vect2.z ,Vect1.x * Vect2.y - Vect1.y * Vect2.x); } /************************************************* Summary: Returns the reflection of vector against a plane. Input Arguments: v1: A pointer to a VxVector giving the incident vector (pointing away from the plane) Norm: A VxVector giving the normal point away from the plane of reflection. Return Value: A Vector equal to the reflection of v1. Remarks: This method calculates the vector reflection of v1 against the plane described by normal Norm. using the following equation : R = 2*(V dot N)*N - V It is expected that the incident vector v1 is pointing away from the plane. The resultant vector R will also be pointing away from the plane. See also: DotProduct *************************************************/ inline const VxVector Reflect(const VxVector& v1,const VxVector& Norm) { float dp2 = 2.0f*(DotProduct(v1,Norm)); return VxVector(dp2*Norm.x-v1.x,dp2*Norm.y-v1.y,dp2*Norm.z-v1.z); } VX_EXPORT const VxVector Rotate(const VxMatrix& mat,const VxVector& pt); VX_EXPORT const VxVector Rotate(const VxVector& v1, const VxVector& v2,float angle); VX_EXPORT const VxVector Rotate(const VxVector* v1, const VxVector* v2,float angle); // For VSL Binding #if defined(macintosh) || defined(PSX2) VX_EXPORT const VxVector RotateMV(const VxMatrix& mat,const VxVector& pt); VX_EXPORT const VxVector RotateVVF(const VxVector& v1, const VxVector& v2,float angle); #endif /******************************************************* Name: VxCompressedVector Summary: Class representation of a unit vector in 3 dimensions Remarks: A VxCompressedVector is defined as: typedef struct VxCompressedVector { short int xa,ya } The xa and ya members are polar angles This representation can be used to store normals or unit vectors using less memory than a conventionnal vector. ***********************************************************/ typedef struct VxCompressedVector { public: short int xa,ya; // Polar Angles VxCompressedVector() { xa=ya=0; } VxCompressedVector(float _x, float _y, float _z) { Set(_x,_y,_z); } void Set(float X,float Y,float Z); void Slerp(float step,VxCompressedVector &v1,VxCompressedVector &v2); // ===================================== // Unary operators // ===================================== VxCompressedVector& operator = (const VxVector& v); VxCompressedVector& operator = (const VxCompressedVectorOld& v); } VxCompressedVector; typedef struct VxCompressedVectorOld { public: int xa,ya; // Polar Angles VxCompressedVectorOld() { xa=ya=0; } VxCompressedVectorOld(float _x, float _y, float _z) { Set(_x,_y,_z); } void Set(float X,float Y,float Z); void Slerp(float step,VxCompressedVectorOld &v1,VxCompressedVectorOld &v2); // ===================================== // Unary operators // ===================================== VxCompressedVectorOld& operator = (const VxVector& v); VxCompressedVectorOld& operator = (const VxCompressedVector& v); } VxCompressedVectorOld; /******************************************************* {filename:VxVector4} Name: VxVector4 Summary: Class representation of a Vector of 4 elements (x,y,z,w) Remarks: VxVector4 is used for 3D Transformation when the w component is used for perspective information. Most of the methods available for a VxVector are also implemented for the VxVector4 A VxVector4 is defined as: typedef struct VxVector4 { union { struct { float x,y,z,w; }; float v[4]; }; } ***********************************************************/ class VxVector4 : public VxVector { public: float w; VxVector4() { x=y=z=w=0.0f; } VxVector4(float f) { x=y=z=w=f; } VxVector4(float _x, float _y, float _z,float _w) { x=_x; y=_y; z=_z; w=_w; } VxVector4(const float f[4]){ x=f[0]; y=f[1]; z=f[2]; w=f[3]; } VxVector4& operator = (const VxVector& v) {x=v.x;y=v.y;z=v.z;return *this;} // ===================================== // Access grants // ===================================== const float&operator[](int i) const; float&operator[](int i); #if defined(_LINUX) operator float*() const {return (float*)&x;} #else operator float*() const {return (float*)&v[0];} #endif // Initialization void Set(float X,float Y,float Z,float W); void Set(float X,float Y,float Z); float Dot(const VxVector4& iV) const {return x*iV.x + y * iV.y + z * iV.z;} VxVector4& operator += (const VxVector4& v); VxVector4& operator -= (const VxVector4& v); VxVector4& operator *= (const VxVector4& v); VxVector4& operator /= (const VxVector4& v); VxVector4& operator += (const VxVector& v); VxVector4& operator -= (const VxVector& v); VxVector4& operator *= (const VxVector& v); VxVector4& operator /= (const VxVector& v); VxVector4& operator *= (float s); VxVector4& operator /= (float s); VxVector4 operator + (float s) const {return VxVector4(x+s,y+s,z+s,w+s);} VxVector4 operator - (float s) const {return VxVector4(x-s,y-s,z-s,w-s);} // ===================================== // Unary operators // ===================================== friend const VxVector4 operator + (const VxVector4& v); friend const VxVector4 operator - (const VxVector4& v); // ===================================== // Binary operators // ===================================== // Addition and subtraction friend const VxVector4 operator + (const VxVector4& v1, const VxVector4& v2); friend const VxVector4 operator - (const VxVector4& v1, const VxVector4& v2); // Scalar multiplication and division friend const VxVector4 operator * (const VxVector4& v, float s); friend const VxVector4 operator * (float s, const VxVector4& v); friend const VxVector4 operator / (const VxVector4& v, float s); // Memberwise multiplication and division friend const VxVector4 operator * (const VxVector4& v1, const VxVector4& v2); friend const VxVector4 operator / (const VxVector4& v1, const VxVector4& v2); // Bitwise equality friend int operator == (const VxVector4& v1, const VxVector4& v2); friend int operator != (const VxVector4& v1, const VxVector4& v2); }; /******************************************************* {filename:VxBbox} Name: VxBbox Summary: Class representation of a Bounding Box The VxBbox structure contains two VxVector Min and Max to represents the Minimum and Maximum coordinates of the corners of a box. A VxBbox is defined as: typedef struct VxBbox { union { struct { VxVector Max; VxVector Min; } }; float v[6]; }; } ***********************************************************/ typedef struct VxBbox { #if defined(_LINUX) || defined(PSX2) VxVector Max; // Maximum corner of the box VxVector Min; // Minimum corner of the box #else union { struct { VxVector Max; // Maximum corner of the box VxVector Min; // Minimum corner of the box }; float v[6]; }; #endif public: VxBbox():Max(-1e6f,-1e6f,-1e6f),Min(1e6f,1e6f,1e6f) {} VxBbox(VxVector iMin, VxVector iMax):Max(iMax),Min(iMin) {} VxBbox( float value ) { Max.x=value; Max.y=value; Max.z=value; Min.x=-value; Min.y=-value; Min.z=-value; } BOOL IsValid() const { if (Min.x > Max.x) return FALSE; if (Min.y > Max.y) return FALSE; if (Min.z > Max.z) return FALSE; return TRUE; } VxVector GetSize() const {return Max - Min;} VxVector GetHalfSize() const {return (Max-Min)*0.5f;} VxVector GetCenter() const {return (Max+Min)*0.5f;} void SetCorners(const VxVector& min,const VxVector& max){Min = min;Max = max;} void SetDimension(const VxVector& position,const VxVector& size){Min = position;Max = position+size;} void SetCenter(const VxVector& center,const VxVector& halfsize) { Min = center-halfsize; Max = center+halfsize; } //------------------------------------------------------- // Name: Reset // Summary: Resets the minimum and maximum values of the box // Remarks: // The Reset method sets the Minimum Value to (1E6,1E6,1E6) // and maximum value to (-1E6,-1E6,-1E6) //------------------------------------------------------- void Reset() { Max.x=-1e6f; Max.y=-1e6f; Max.z=-1e6f; Min.x=1e6f; Min.y=1e6f; Min.z=1e6f; } //------------------------------------------------------- // Name: Merge // Summary: Merges two boxes // Arguments: // v : A VxBbox to merge to this box // Remarks: // The Merge method calculates the new extents of this box // so it contains the v Box //------------------------------------------------------- void Merge (const VxBbox& v) { Max.x = XMax(v.Max.x,Max.x); Max.y = XMax(v.Max.y,Max.y); Max.z = XMax(v.Max.z,Max.z); Min.x = XMin(v.Min.x,Min.x); Min.y = XMin(v.Min.y,Min.y); Min.z = XMin(v.Min.z,Min.z); } //------------------------------------------------------- // Name: Merge // Summary: Merges a vector with a box // Arguments: // v : A vector to merge to this box // Remarks: // The Merge method calculates the new extents of this box // so it contains the v point //------------------------------------------------------- void Merge (const VxVector& v) { if (v.x > Max.x) Max.x = v.x; if (v.x < Min.x) Min.x = v.x; if (v.y > Max.y) Max.y = v.y; if (v.y < Min.y) Min.y = v.y; if (v.z > Max.z) Max.z = v.z; if (v.z < Min.z) Min.z = v.z; } //------------------------------------------------------- // Name: Classify // Summary: Returns on which side a point is // Remarks: // // Return Value: // A combination of the culling flags // //------------------------------------------------------- DWORD Classify(const VxVector& iPoint) const { DWORD flag = 0; if (iPoint.x < Min.x) flag |= VXCLIP_LEFT; else if (iPoint.x > Max.x) flag |= VXCLIP_RIGHT; if (iPoint.y < Min.y) flag |= VXCLIP_BOTTOM; else if (iPoint.y > Max.y) flag |= VXCLIP_TOP; if (iPoint.z < Min.z) flag |= VXCLIP_BACK; else if (iPoint.z > Max.z) flag |= VXCLIP_FRONT; return flag; } //------------------------------------------------------- // Name: Classify // Summary: Returns on which side a box is // Remarks: // // Return Value: // A combination of the culling flags // //------------------------------------------------------- DWORD Classify(const VxBbox& iBox) const { DWORD flag = 0; if (iBox.Max.z<Min.z) flag |= VXCLIP_BACK; else if (iBox.Min.z>Max.z) flag |= VXCLIP_FRONT; if (iBox.Max.x<Min.x) flag |= VXCLIP_LEFT; else if (iBox.Min.x>Max.x) flag |= VXCLIP_RIGHT; if (iBox.Max.y<Min.y) flag |= VXCLIP_BOTTOM; else if (iBox.Min.y>Max.y) flag |= VXCLIP_TOP; return flag; } //------------------------------------------------------- // Name: Classify // Summary: Returns on which side a box is compared to point // Remarks: // // Return Value: // 2 : If viewed from point pt the box box2 is on the opposite side of this box // 1 : box2 is inside this box // 0 : No idea where the box is // //------------------------------------------------------- VX_EXPORT int Classify(const VxBbox& box2,const VxVector& pt) const; //------------------------------------------------------- // Summary: classify an array of vertices against // the box. An array of dword is filled with // flags from the enum VXCLIP_BOXFLAGS // Remarks: // //------------------------------------------------------- VX_EXPORT void ClassifyVertices(const int iVcount, BYTE* iVertices, DWORD iStride, DWORD* oFlags) const; //------------------------------------------------------- // Summary: classify an array of vertices against // one axis of the box. An array of dword is filled with // flags 0x01 if < min, 0x10 if > max // Remarks: // //------------------------------------------------------- VX_EXPORT void ClassifyVerticesOneAxis(const int iVcount, BYTE* iVertices, DWORD iStride, const int iAxis,DWORD* oFlags) const; //------------------------------------------------------- // Name: Intersect // Summary: Intersects two boxes // Arguments: // v : A VxBbox to intersect with this box // Remarks: // The Intersect method calculates the new extents of this box // so it only contains the intersection with the v Box //------------------------------------------------------- void Intersect(const VxBbox& v) { Max.x = XMin(v.Max.x,Max.x); Max.y = XMin(v.Max.y,Max.y); Max.z = XMin(v.Max.z,Max.z); Min.x = XMax(v.Min.x,Min.x); Min.y = XMax(v.Min.y,Min.y); Min.z = XMax(v.Min.z,Min.z); } //------------------------------------------------------- // Name: VectorIn // Summary: Tests if a point is inside the box. // Arguments: // v : A VxVector to test if it is inside the box. // // Return Value: TRUE if v is inside this box, FALSE otherwise //------------------------------------------------------- BOOL VectorIn(const VxVector& v) const { if (v.x<Min.x) return FALSE; if (v.x>Max.x) return FALSE; if (v.y<Min.y) return FALSE; if (v.y>Max.y) return FALSE; if (v.z<Min.z) return FALSE; if (v.z>Max.z) return FALSE; return TRUE; } //------------------------------------------------------- // Name: IsBoxInside // Summary: Tests if a box is totally inside this box. // Arguments: // b : A VxBbox to test if it is inside the box. // // Return Value: TRUE if b is inside this box, FALSE otherwise //------------------------------------------------------- BOOL IsBoxInside(const VxBbox& b) const { if (b.Min.x<Min.x) return 0; if (b.Min.y<Min.y) return 0; if (b.Min.z<Min.z) return 0; if (b.Max.x>Max.x) return 0; if (b.Max.y>Max.y) return 0; if (b.Max.z>Max.z) return 0; return 1; } bool operator == (const VxBbox& iBox) const { return (Max == iBox.Max) && (Min == iBox.Min); } // Transform this box to eight points according to matrix mat VX_EXPORT void TransformTo(VxVector *pts,const VxMatrix& Mat) const; // Creates this box from sbox acording to matrix mat VX_EXPORT void TransformFrom(const VxBbox& sbox,const VxMatrix& Mat); } VxBbox; inline VxVector::VxVector():x(0),y(0),z(0) { } inline VxVector::VxVector(float f):x(f),y(f),z(f) { } inline VxVector::VxVector(float _x, float _y, float _z):x(_x),y(_y),z(_z) { } inline VxVector::VxVector(const float f[3]):x(f[0]),y(f[1]),z(f[2]) { } // Initialization inline void VxVector::Set(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } inline const float& VxVector::operator[](int i) const { return *((&x)+i); } inline float& VxVector::operator[](int i) { return *((&x)+i); } inline VxVector& VxVector::operator += (const VxVector& v) { x += v.x; y += v.y; z += v.z; return *this; } inline VxVector& VxVector::operator -= (const VxVector& v) { x -= v.x; y -= v.y; z -= v.z; return *this; } inline VxVector& VxVector::operator *= (const VxVector& v) { x *= v.x; y *= v.y; z *= v.z; return *this; } inline VxVector& VxVector::operator /= (const VxVector& v) { x /= v.x; y /= v.y; z /= v.z; return *this; } inline VxVector& VxVector::operator *= (float s) { x *= s; y *= s; z *= s; return *this; } inline VxVector& VxVector::operator /= (float s) { float temp=1.0f/s; x *= temp; y *= temp; z *= temp; return *this; } // inline const VxVector operator + (const VxVector& v) { return v; } // inline const VxVector operator - (const VxVector& v) { return VxVector(-v.x, -v.y, -v.z); } inline const VxVector operator + (const VxVector& v1, const VxVector& v2) { return VxVector(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z); } inline const VxVector operator - (const VxVector& v1, const VxVector& v2) { return VxVector(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z); } // inline const VxVector operator * (const VxVector& v1, const VxVector& v2) { return VxVector(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z); } // inline const VxVector operator / (const VxVector& v1, const VxVector& v2) { return VxVector(v1.x/v2.x, v1.y/v2.y, v1.z/v2.z); } // inline int operator < (const VxVector& v1, const VxVector& v2) { return v1[0] < v2[0] && v1[1] < v2[1] && v1[2] < v2[2]; } // inline int operator <= (const VxVector& v1, const VxVector& v2) { return v1[0] <= v2[0] && v1[1] <= v2[1] && v1[2] <= v2[2]; } inline const VxVector operator * (const VxVector& v, float s) { return VxVector(s*v.x, s*v.y, s*v.z); } inline const VxVector operator * (float s, const VxVector& v) { return VxVector(s*v.x, s*v.y, s*v.z); } inline const VxVector operator / (const VxVector& v, float s) { float temp=1.0f/s; return VxVector(v.x*temp, v.y*temp, v.z*temp); } // inline int operator == (const VxVector& v1, const VxVector& v2) { return ( (v1.x==v2.x) && (v1.y==v2.y) && (v1.z==v2.z) ); } // inline int operator != (const VxVector& v1, const VxVector& v2) { return !(v1==v2); } /************************************************* Name: Absolute Summary: Calculates absolute value of a vector. - v: A reference to a VxVector. Return value: A VxVector with each element set to the absolute value of the corresponding element in v. See also: VxVector, *************************************************/ inline const VxVector Absolute (const VxVector& v) { return VxVector(XAbs(v.x),XAbs(v.y),XAbs(v.z)); } /************************************************* Name: Absolute Summary: Calculates absolute value of a vector. Each element is set to its absolute value. See also: VxVector *************************************************/ void inline VxVector::Absolute () { x = XAbs(x); y = XAbs(y); z = XAbs(z); } /************************************************* Name: Min Summary: Calculates the minimum value among the elements of a vector. Arguments: v: A Vector. Return value: A float value containing the minimum of the elements of v. See also: VxVector,Vx2DVector *************************************************/ inline float Min (const VxVector& v) { return XMin(v.x,v.y,v.z); } /************************************************* Name: Max Summary: Calculates the maximum value among the elements of a vector. Arguments: v: A Vector. Return value: A float value containing the maximum of the elements of v. See also: VxVector,Vx2DVector ************************************************/ inline float Max (const VxVector& v) { float ret = v.x; if (ret < v.y) ret = v.y; if (ret < v.z) ret = v.z; return ret; } /************************************************* Name: Minimize Summary: Constructs a vector containing minimum values of two vectors. Arguments: v1: A Vector. v2: A Vector. Return value: A VxVector containing with each element equal to the smallest element of v1 or v2. See also: VxVector *************************************************/ inline const VxVector Minimize (const VxVector& v1, const VxVector& v2) { return VxVector(XMin(v1[0],v2[0]),XMin(v1[1],v2[1]),XMin(v1[2],v2[2])); } /************************************************* Name: Maximize Summary: Constructs a vector containing maximum values of two vectors. Arguments: v1: A reference to a VxVector. v2: A reference to a VxVector. Return value: A VxVector containing with each element equal to the greatest element of v1 or v2. See also: VxVector *************************************************/ inline const VxVector Maximize (const VxVector& v1, const VxVector& v2) { return VxVector(XMax(v1[0],v2[0]),XMax(v1[1],v2[1]),XMax(v1[2],v2[2])); } /************************************************* Name: Interpolate Summary: Constructs a vector representing the interpolation of two vectors. Arguments: step : The interpolation factor. v1: A reference to a VxVector. v2: A reference to a VxVector. Return value: A VxVector . See also: VxVector *************************************************/ inline const VxVector Interpolate (float step, const VxVector& v1, const VxVector& v2) { return VxVector( v1.x + (v2.x-v1.x) * step, v1.y + (v2.y-v1.y) * step, v1.z + (v2.z-v1.z) * step); } //------------------------------------------------------------------------------------------------------ // VxVector4 //------------------------------------------------------------------------------------------------------- inline VxVector4& VxVector4::operator += (const VxVector4& v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } inline VxVector4& VxVector4::operator -= (const VxVector4& v) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; } inline VxVector4& VxVector4::operator *= (const VxVector4& v) { x *= v.x; y *= v.y; z *= v.z; w *= v.w; return *this; } inline VxVector4& VxVector4::operator /= (const VxVector4& v) { x /= v.x; y /= v.y; z /= v.z; w /= v.w; return *this; } inline VxVector4& VxVector4::operator += (const VxVector& v) { x += v.x; y += v.y; z += v.z; return *this; } inline VxVector4& VxVector4::operator -= (const VxVector& v) { x -= v.x; y -= v.y; z -= v.z; return *this; } inline VxVector4& VxVector4::operator *= (const VxVector& v) { x *= v.x; y *= v.y; z *= v.z; return *this; } inline VxVector4& VxVector4::operator /= (const VxVector& v) { x /= v.x; y /= v.y; z /= v.z; return *this; } inline VxVector4& VxVector4::operator *= (float s) { x *= s; y *= s; z *= s; w *= s; return *this; } inline VxVector4& VxVector4::operator /= (float s) { float temp=1.0f/s; x *= temp; y *= temp; z *= temp; w *= temp; return *this; } // inline const VxVector4 operator + (const VxVector4& v) { return v; } // inline const VxVector4 operator - (const VxVector4& v) { return VxVector4(-v.x, -v.y, -v.z,-v.w); } inline const VxVector4 operator + (const VxVector4& v1, const VxVector4& v2) { return VxVector4(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z,v1.w+v2.w); } inline const VxVector4 operator - (const VxVector4& v1, const VxVector4& v2) { return VxVector4(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z,v1.w - v2.w); } // inline const VxVector4 operator * (const VxVector4& v1, const VxVector4& v2) { return VxVector4(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z,v1.w * v2.w); } // inline const VxVector4 operator / (const VxVector4& v1, const VxVector4& v2) { return VxVector4(v1.x/v2.x, v1.y/v2.y, v1.z/v2.z,v1.w/v2.w); } inline const VxVector4 operator * (const VxVector4& v, float s) { return VxVector4(s*v.x, s*v.y, s*v.z,s*v.w); } inline const VxVector4 operator * (float s, const VxVector4& v) { return VxVector4(s*v.x, s*v.y, s*v.z,s*v.w); } inline const VxVector4 operator / (const VxVector4& v, float s) { float invs = 1.0f / s; return VxVector4(invs*v.x, invs*v.y, invs*v.z,invs*v.w); } // inline int operator == (const VxVector4& v1, const VxVector4& v2) { return ((v1.x==v2.x) && (v1.y == v2.y) && (v1.z == v2.z) && (v1.w == v2.w)); } // inline int operator != (const VxVector4& v1, const VxVector4& v2) { return !(v1==v2); } // Initialization inline void VxVector4::Set(float _x, float _y, float _z,float _w) { x = _x; y = _y; z = _z; w=_w; } // Initialization inline void VxVector4::Set(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } inline const float& VxVector4::operator[](int i) const { #if defined(_LINUX) return *((&x)+i); #else return v[i]; #endif } inline float& VxVector4::operator[](int i) { #if defined(_LINUX) return *((&x)+i); #else return v[i]; #endif } //------------------------------------------------------------------------------------------------------ // VxCompressed Vector //------------------------------------------------------------------------------------------------------- /************************************************* Name: Slerp Summary: Performs a linear interpolation between two vectors. Arguments: v1: A reference to a VxCompressedVectorOld. v2: A reference to a VxCompressedVectorOld. step: The interpolation factor, 0 means v1 and 1 means v2. Remarks: See also: VxVector *************************************************/ inline void VxCompressedVectorOld::Slerp(float step,VxCompressedVectorOld &v1,VxCompressedVectorOld &v2) { int v1y=((int)v1.ya+16384) & 16383; int v2y=((int)v2.ya+16384) & 16383; v2y=(v2y-v1y); if (v2y>8192) v2y=16384-v2y; else if (v2y<-8192) v2y=16384+v2y; xa=(int)((float)v1.xa+(float)(v2.xa-v1.xa)*step); ya=(int)((float)v1y+(float)v2y*step); } // inline VxCompressedVectorOld& VxCompressedVectorOld::operator = (const VxVector& v) { Set(v.x,v.y,v.z); return *this; } /************************************************* Name: Set Summary: Creates a VxCompressedVectorOld from 3 components. Arguments: X,Y,Z: float components. Remarks: See also: VxVector *************************************************/ inline void VxCompressedVectorOld::Set(float X,float Y,float Z) { // calcul de l'angle x xa = -radToAngle((float)asin(Y)); // calcul de l'angle y ya = radToAngle((float)atan2(X,Z)); } inline void VxCompressedVector::Slerp(float step,VxCompressedVector &v1,VxCompressedVector &v2) { int coef = (int) (65536.0f * step); int v1y = ((int)v1.ya+16384) & 16383; int v2y = ((int)v2.ya+16384) & 16383; v2y=(v2y-v1y); if (v2y>8192) v2y=16384-v2y; else if (v2y<-8192) v2y=16384+v2y; xa=(short int)( (int)v1.xa + (((int)(v2.xa-v1.xa) * coef) >> 16)); ya=(short int)( v1y + ((v2y * coef) >> 16) ); } // inline VxCompressedVector& VxCompressedVector::operator = (const VxVector& v) { Set(v.x,v.y,v.z); return *this; } inline void VxCompressedVector::Set(float X,float Y,float Z) { // calcul de l'angle x xa = (short int)-radToAngle((float)asin(Y)); // calcul de l'angle y ya = (short int)radToAngle((float)atan2(X,Z)); } // inline VxCompressedVectorOld& VxCompressedVectorOld::operator = (const VxCompressedVector& v) { xa=(int)v.xa; ya=(int)v.ya; return *this; } // inline VxCompressedVector& VxCompressedVector::operator = (const VxCompressedVectorOld& v) { xa=(short int)v.xa; ya=(short int)v.ya; return *this; } #endif
26.116433
127
0.579628
552c963e41db742dc8ef978b7a6ef58dec9be995
4,590
h
C
apx/include/apx/port_signature_map_entry.h
cogu/c-apx
d1f9cfca6258c6e5b27a8b69ce0fbf0fdca53dec
[ "MIT" ]
6
2018-04-15T15:44:01.000Z
2021-08-10T11:22:22.000Z
apx/include/apx/port_signature_map_entry.h
cogu/c-apx
d1f9cfca6258c6e5b27a8b69ce0fbf0fdca53dec
[ "MIT" ]
23
2018-04-27T06:42:57.000Z
2021-02-14T11:11:58.000Z
apx/include/apx/port_signature_map_entry.h
cogu/c-apx
d1f9cfca6258c6e5b27a8b69ce0fbf0fdca53dec
[ "MIT" ]
9
2017-09-12T09:34:58.000Z
2020-08-12T05:11:48.000Z
/***************************************************************************** * \file port_signature_entry.h * \author Conny Gustafsson * \date 2020-02-18 * \brief An element in an apx_portSignatureMap_t * * Copyright (c) 2020-2021 Conny Gustafsson * 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. * ******************************************************************************/ #ifndef APX_PORT_SIGNATURE_MAP_ENTRY_H #define APX_PORT_SIGNATURE_MAP_ENTRY_H ////////////////////////////////////////////////////////////////////////////// // INCLUDES ////////////////////////////////////////////////////////////////////////////// #include "adt_list.h" #include "apx/types.h" #include "apx/port_instance.h" ////////////////////////////////////////////////////////////////////////////// // PUBLIC CONSTANTS AND DATA TYPES ////////////////////////////////////////////////////////////////////////////// //forward declarations struct apx_nodeData_tag; struct apx_port_tag; typedef struct apx_portSignatureMapEntry_tag { apx_portInstance_t *preferred_provider; adt_list_t require_ports; //weak references to apx_portInstance_t adt_list_t provide_ports; //weak references to apx_portInstance_t } apx_portSignatureMapEntry_t; ////////////////////////////////////////////////////////////////////////////// // PUBLIC FUNCTION PROTOTYPES ////////////////////////////////////////////////////////////////////////////// void apx_portSignatureMapEntry_create(apx_portSignatureMapEntry_t *self); void apx_portSignatureMapEntry_destroy(apx_portSignatureMapEntry_t *self); apx_portSignatureMapEntry_t *apx_portSignatureMapEntry_new(void); void apx_portSignatureMapEntry_delete(apx_portSignatureMapEntry_t *self); void apx_portSignatureMapEntry_vdelete(void *arg); void apx_portSignatureMapEntry_attach_require_port(apx_portSignatureMapEntry_t *self, apx_portInstance_t* port_instance); void apx_portSignatureMapEntry_attach_provide_port(apx_portSignatureMapEntry_t *self, apx_portInstance_t* port_instance, bool is_preferred); void apx_portSignatureMapEntry_detach_require_port(apx_portSignatureMapEntry_t *self, apx_portInstance_t* port_instance); void apx_portSignatureMapEntry_detach_provide_port(apx_portSignatureMapEntry_t *self, apx_portInstance_t* port_instance); bool apx_portSignatureMapEntry_is_empty(apx_portSignatureMapEntry_t *self); int32_t apx_portSignatureMapEntry_get_num_providers(apx_portSignatureMapEntry_t* self); int32_t apx_portSignatureMapEntry_get_num_requesters(apx_portSignatureMapEntry_t* self); apx_portInstance_t*apx_portSignatureMapEntry_get_first_provider(apx_portSignatureMapEntry_t *self); apx_portInstance_t*apx_portSignatureMapEntry_get_last_provider(apx_portSignatureMapEntry_t *self); apx_portInstance_t* apx_portSignatureMapEntry_get_first_requester(apx_portSignatureMapEntry_t* self); apx_portInstance_t* apx_portSignatureMapEntry_get_last_requester(apx_portSignatureMapEntry_t* self); void apx_portSignatureMapEntry_set_preferred_provider(apx_portSignatureMapEntry_t *self, apx_portInstance_t* port_instance); apx_portInstance_t*apx_portSignatureMapEntry_get_preferred_provider(apx_portSignatureMapEntry_t *self); apx_error_t apx_portSignatureMapEntry_notify_require_ports_about_provide_port_change(apx_portSignatureMapEntry_t *self, apx_portInstance_t* provide_port, apx_portConnectorEvent_t event_type); apx_error_t apx_portSignatureMapEntry_notify_provide_ports_about_require_port_change(apx_portSignatureMapEntry_t *self, apx_portInstance_t* require_port, apx_portConnectorEvent_t event_type); #endif //APX_ROUTING_TABLE_ENTRY_H
59.61039
191
0.738344
553fd2f4632b4476ce8fa1e0656f712c66122c88
1,957
c
C
A/04/27/task1.c
elsys/po-2015
28d352ab8d7d4eb55620b01f9176f8e3f6838744
[ "MIT" ]
27
2015-09-28T19:47:23.000Z
2016-07-25T15:17:32.000Z
A/04/27/task1.c
elsys/po-2015
28d352ab8d7d4eb55620b01f9176f8e3f6838744
[ "MIT" ]
391
2015-09-28T05:57:05.000Z
2016-06-09T16:43:53.000Z
A/04/27/task1.c
elsys/po-2015
28d352ab8d7d4eb55620b01f9176f8e3f6838744
[ "MIT" ]
351
2015-06-29T17:17:31.000Z
2016-05-04T17:57:14.000Z
#include <stdio.h> #include <string.h> void check_ISBN_validity(char*); int main() { char ISBN[20]; scanf("%s", ISBN); check_ISBN_validity(ISBN); return 0; } void check_ISBN_validity(char *ISBN) { int valid = 1, dash = 0, i, counter = 0, check_digit = 0, publisher_ptr = 0; char publisher1[6] = "933346", publisher2[5] = "55583", publisher3[4] = "4210", publisher4[2] = "01"; char ex1[4] = "978-", ex2[4] = "979-"; if(strlen(ISBN) != 17) valid = 0; for(i = 0; i < strlen(ISBN); i++) { if(ISBN[i] == '-') dash++; if(dash == 2 && publisher_ptr == 0) publisher_ptr = i + 1; if ( (ISBN[i] < '0' || ISBN[i] > '9') && ISBN[i] != '-' && ISBN[i] != '\n' && ISBN[i] != ' ' ) valid = 0; else if(ISBN[i] >= '0' && ISBN[i] <= '9') { counter++; if(counter <= 12) { if(counter%2) check_digit += ISBN[i]-'0'; else check_digit += (ISBN[i]-'0') * 3; } } } if(dash != 4) valid = 0; else { check_digit %= 10; if(check_digit) check_digit = 10 - check_digit; if(ISBN[16]-'0' != check_digit) valid = 0; } for(i = 0; i < 4; i++) { if(ISBN[i] != ex1[i] && ISBN[i] != ex2[i]) valid = 0; } int publisher1_result = 0; int publisher2_result = 0; int publisher3_result = 0; int publisher4_result = 0; if(valid) { printf("1"); for(i = publisher_ptr; ISBN[i] != '-'; i++) { if(ISBN[i] == publisher1[i-publisher_ptr]) publisher1_result++; else if(ISBN[i] == publisher2[i-publisher_ptr]) publisher2_result++; else if(ISBN[i] == publisher3[i-publisher_ptr]) publisher3_result++; else if(ISBN[i] == publisher4[i-publisher_ptr]) publisher4_result++; } if(i-publisher_ptr == publisher1_result) printf("\nBluebridge"); else if(i-publisher_ptr == publisher2_result) printf("\nAlyson Books"); else if(i-publisher_ptr == publisher3_result) printf("\nFUNimation Productions, Ltd."); else if(i-publisher_ptr == publisher4_result) printf("\nPyramid Books"); } else printf("0"); }
25.089744
89
0.598365
86931708807c544c2fd5b843e4043e114914256f
1,814
h
C
Miners/gpu/avermore-source/winbuild/dist/include/config.h
MSFTserver/RavenCoin-Wallet-Windows
61480b965d4199c65da84fccebc0972d6b106aca
[ "MIT" ]
85
2018-01-28T11:36:04.000Z
2022-03-12T01:50:34.000Z
Miners/gpu/avermore-source/winbuild/dist/include/config.h
MSFTserver/RavenCoin-Wallet-Windows
61480b965d4199c65da84fccebc0972d6b106aca
[ "MIT" ]
3
2018-02-05T03:04:33.000Z
2018-02-08T04:03:57.000Z
Miners/gpu/avermore-source/winbuild/dist/include/config.h
MSFTserver/RavenCoin-Wallet-With-Miners
61480b965d4199c65da84fccebc0972d6b106aca
[ "MIT" ]
39
2018-02-24T21:01:54.000Z
2021-08-15T16:05:02.000Z
#ifndef __CONFIG_H__ #define __CONFIG_H__ #define HAVE_STDINT_H #if defined(_MSC_VER) #define HAVE_LIBCURL 1 #define CURL_HAS_KEEPALIVE 1 #define HAVE_CURSES 1 #define HAVE_ADL 1 #define STDC_HEADERS 1 #define EXECV_2ND_ARG_TYPE char* const* #define HAVE_ALLOCA 1 #define HAVE_ATTRIBUTE_COLD 1 #define HAVE_ATTRIBUTE_CONST 1 #define HAVE_ATTRIBUTE_NORETURN 1 #define HAVE_ATTRIBUTE_PRINTF 1 #define HAVE_ATTRIBUTE_UNUSED 1 #define HAVE_ATTRIBUTE_USED 1 #define HAVE_BUILTIN_CONSTANT_P 1 #define HAVE_BUILTIN_TYPES_COMPATIBLE_P 1 #define HAVE_DECL_MEMMEM 0 #define HAVE_INTTYPES_H 1 #define HAVE_LONG_LONG_INT 1 #define HAVE_MEMORY_H 1 #define HAVE_MPROTECT 1 #define HAVE_RAW_DECL_MEMPCPY 1 #define HAVE_RAW_DECL_STRNCAT 1 #define HAVE_RAW_DECL_STRNLEN 1 #define HAVE_RAW_DECL_STRPBRK 1 #define HAVE_STDLIB_H 1 #define HAVE_STRINGS_H 1 #define HAVE_STRING_H 1 #define HAVE_SYS_STAT_H 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_UNISTD_H 1 #define HAVE_UNSIGNED_LONG_LONG_INT 1 #define HAVE_WARN_UNUSED_RESULT 1 #define HAVE_WCHAR_H 1 #define HAVE_WCHAR_T 1 #define PRIi64 "I64d" #define PRIi32 "I32d" #define PRIu32 "I32u" #define PRIu64 "I64u" #define PATH_MAX MAX_PATH // Libraries to include #pragma comment(lib, "winmm.lib") #pragma comment(lib, "wsock32.lib") #pragma comment(lib, "pthreadVC2.lib") #pragma comment(lib, "OpenCL.lib") #pragma comment(lib, "jansson.lib") #ifdef HAVE_LIBCURL #define CURL_STATICLIB 1 #pragma comment(lib, "libcurl_a.lib") #endif #ifdef HAVE_CURSES #pragma comment(lib, "pdcurses.lib") #endif #endif #define VERSION "v5.2.0" #define PACKAGE_NAME "sgminer" #define PACKAGE_TARNAME "sgminer" #define PACKAGE_VERSION "5.2.0" #define PACKAGE_STRING "sgminer 5.2.0" #define PACKAGE "sgminer" #define SGMINER_PREFIX "" #include "gitversion.h" #include "winbuild.h" #endif
21.855422
41
0.806505
22b8127cc149ce534a96421174703af563136574
151
h
C
project759/src/component496/headers/component496/lib26.h
gradle/perf-native-large
af00fd258fbe9c7d274f386e46847fe12062cc71
[ "Apache-2.0" ]
2
2016-11-23T17:25:24.000Z
2016-11-23T17:25:27.000Z
project759/src/component496/headers/component496/lib26.h
gradle/perf-native-large
af00fd258fbe9c7d274f386e46847fe12062cc71
[ "Apache-2.0" ]
15
2016-09-15T03:19:32.000Z
2016-09-17T09:15:32.000Z
project759/src/component496/headers/component496/lib26.h
gradle/perf-native-large
af00fd258fbe9c7d274f386e46847fe12062cc71
[ "Apache-2.0" ]
2
2019-11-09T16:26:55.000Z
2021-01-13T10:51:09.000Z
#ifndef PROJECT_HEADER_component496_26_H #define PROJECT_HEADER_component496_26_H int component496_26(); #endif // PROJECT_HEADER_component496_26_H
18.875
42
0.86755
c2077f0edbe9aa773880767bc92aed7f4a71cc80
1,759
c
C
pgxexplorer/signals.c
lukaszgryglicki/old_c
07b181a961b571d411615956f7733b8a7f0e6335
[ "Apache-2.0" ]
null
null
null
pgxexplorer/signals.c
lukaszgryglicki/old_c
07b181a961b571d411615956f7733b8a7f0e6335
[ "Apache-2.0" ]
null
null
null
pgxexplorer/signals.c
lukaszgryglicki/old_c
07b181a961b571d411615956f7733b8a7f0e6335
[ "Apache-2.0" ]
null
null
null
/* Written by Morgoth DBMA, morgothdbma@o2.pl This is part of PgXexplorer software, Open Source on BSD licence, Libraries(interaces) used: GNU GCC, AS (all stuff needed to compile C source into executable binary) LibPQ-FE from PostgreSQL, GTK (GIMP Toolkit) written in VIM editor, ctags used, CVS used Currently only one author: MOrgoth DBMA FILE: signals.c */ #include "common.h" #include "signals.h" #include "ilibpq.h" extern INT ping_conn; extern INT cont; extern PGconn* connection; void priv_sig_proc() { debug("%s:%d priv_sig_proc()", __FILE__,__LINE__); ping_conn=0; gtk_dialog_printf("Tiomeout!\nConnection lost!\nSystem will now exit"); exit(1); ping_conn=0; } void sig_abort() { debug("%s:%d sig_abort()", __FILE__,__LINE__); cont=0; } void discoteka() { debug("%s:%d discoteka()", __FILE__,__LINE__); if (connection) PQfinish(connection); else warn("connect is null: %s:%d", __FILE__,__LINE__); connection = NULL; } void sig_int() { debug("%s:%d sig_kill()", __FILE__,__LINE__); cont=0; system("killall -9 pbar"); printf("Exiting by the SIGNAL\n"); discoteka(); exit(0); } void alarm_clock(INT sec) { debug("%s:%d alarm_clock(%d)", __FILE__,__LINE__,sec); alarm(sec); } void alarm_stop() { debug("%s:%d alarm_stop()", __FILE__,__LINE__); alarm(0); } void setup_signals() { static struct sigaction act; static struct sigaction acu; static struct sigaction acv; ping_conn=0; debug("%s:%d setup_signals()", __FILE__,__LINE__); act.sa_handler = priv_sig_proc; sigfillset(&(act.sa_mask)); sigaction(SIGALRM, &act, NULL); acu.sa_handler = sig_abort; sigfillset(&(acu.sa_mask)); sigaction(SIGUSR1, &acu, NULL); acv.sa_handler = sig_int; sigfillset(&(acv.sa_mask)); sigaction(SIGINT, &acv, NULL); }
20.694118
74
0.708926
193bec0811bb69c8f5509c635256e40dc700d361
455
h
C
ImageScaleTool/UIImageView+YBScale.h
wangyingbo/ImageScaleTool
ceac7b65ccd32c9e64fb6c2dffd13e79ad59fae9
[ "MIT" ]
6
2019-10-14T11:22:12.000Z
2020-04-11T08:31:40.000Z
ImageScaleTool/UIImageView+YBScale.h
wangyingbo/ImageScaleTool
ceac7b65ccd32c9e64fb6c2dffd13e79ad59fae9
[ "MIT" ]
null
null
null
ImageScaleTool/UIImageView+YBScale.h
wangyingbo/ImageScaleTool
ceac7b65ccd32c9e64fb6c2dffd13e79ad59fae9
[ "MIT" ]
3
2019-10-14T06:32:40.000Z
2020-02-22T13:05:33.000Z
// // UIImageView+YBScale.h // ImageScaleTool // // Created by fengbang on 2019/10/9. // Copyright © 2019 王颖博. All rights reserved. // #import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface UIImageView (YBScale) - (CGSize)yb_fitImage:(UIImage *)image maxWidth:(CGFloat)maxWidth; - (CGSize)yb_fitImage:(UIImage *)image maxHeight:(CGFloat)maxHeight; - (CGSize)yb_fitImage:(UIImage *)image maxSize:(CGSize)maxSize; @end NS_ASSUME_NONNULL_END
18.958333
68
0.742857
c35248c013ef002633ee652436f06cbcf27c5966
722
h
C
mgfx_core/graphics3d/device/GL/geometryGL.h
cmaughan/mgfx
488453333f23b38b22ba06b984615a8069dadcbf
[ "MIT" ]
36
2017-03-27T16:57:47.000Z
2022-01-12T04:17:55.000Z
mgfx_core/graphics3d/device/GL/geometryGL.h
cmaughan/mgfx
488453333f23b38b22ba06b984615a8069dadcbf
[ "MIT" ]
5
2017-03-04T12:13:54.000Z
2017-03-26T21:55:08.000Z
mgfx_core/graphics3d/device/GL/geometryGL.h
cmaughan/mgfx
488453333f23b38b22ba06b984615a8069dadcbf
[ "MIT" ]
7
2017-03-04T11:01:44.000Z
2018-08-28T09:25:47.000Z
#pragma once namespace Mgfx { class BufferGL; class GeometryGL : public IGeometry { public: GeometryGL(DeviceGL* pDevice); ~GeometryGL(); virtual void EndGeometry() override; virtual void BeginGeometry(uint32_t id, IDeviceBuffer* pVB, IDeviceBuffer* pIB) override; virtual void DrawTriangles( uint32_t VBOffset, uint32_t IBOffset, uint32_t numVertices, uint32_t numIndices) override; private: DeviceGL* m_pDevice = nullptr; uint32_t VertexArrayID = 0; uint32_t m_programID = 0; uint32_t m_samplerID = 0; uint32_t m_projectionID = 0; glm::vec4 lastTarget = glm::vec4(0.0f); glm::vec4 lastCoords = glm::vec4(0.0f); }; } // namespace Mgfx
21.878788
93
0.685596
ba11325b86dba068e1a637d6a4be1f85ba13cba7
1,658
h
C
src/modules/process/win32/win32_process.h
badlee/TideSDK
fe6f6c93c6cab3395121696f48d3b55d43e1eddd
[ "Apache-2.0" ]
1
2021-09-18T10:10:39.000Z
2021-09-18T10:10:39.000Z
src/modules/process/win32/win32_process.h
hexmode/TideSDK
2c0276de08d7b760b53416bbd8038d79b8474fc5
[ "Apache-2.0" ]
1
2022-02-08T08:45:29.000Z
2022-02-08T08:45:29.000Z
src/modules/process/win32/win32_process.h
hexmode/TideSDK
2c0276de08d7b760b53416bbd8038d79b8474fc5
[ "Apache-2.0" ]
null
null
null
/** * Copyright (c) 2012 - 2014 TideSDK contributors * http://www.tidesdk.org * Includes modified sources under the Apache 2 License * Copyright (c) 2008 - 2012 Appcelerator Inc * Refer to LICENSE for details of distribution and use. **/ #ifndef _WIN32_PROCESS_H_ #define _WIN32_PROCESS_H_ #include <sstream> #include "win32_pipe.h" #include "../process.h" namespace ti { class Win32Process : public Process { public: Win32Process(); virtual ~Win32Process(); inline virtual AutoPtr<NativePipe> GetNativeStdin() { return nativeIn; } inline virtual AutoPtr<NativePipe> GetNativeStdout() { return nativeOut; } inline virtual AutoPtr<NativePipe> GetNativeStderr() { return nativeErr; } virtual int GetPID(); virtual void Terminate(); virtual void Kill(); virtual void SendSignal(int signal); virtual void ForkAndExec(); virtual void MonitorAsync(); virtual BytesRef MonitorSync(); virtual int Wait(); virtual std::string ArgumentsToString(); void ReadCallback(const ValueList& args, ValueRef result); virtual void RecreateNativePipes(); protected: std::string ArgListToString(TiListRef argList); Poco::Thread exitMonitorThread; Poco::RunnableAdapter<Win32Process>* exitMonitorAdapter; AutoPtr<Win32Pipe> nativeIn, nativeOut, nativeErr; Poco::Mutex mutex; Poco::Mutex processOutputMutex; std::vector<BytesRef> processOutput; int pid; HANDLE process; Logger* logger; }; } #endif
28.101695
82
0.648975
520610baa0bc4283f5ca87d3116b16be0a437e1b
13,444
c
C
libvirt/pileus-libvirt-1.2.12/src/util/virusb.c
SIIS-cloud/pileus
de7546845cf03862cdd2b9884fefb2033d8b11ab
[ "Apache-2.0" ]
3
2017-09-22T15:10:01.000Z
2018-03-30T02:11:54.000Z
libvirt/pileus-libvirt-1.2.12/src/util/virusb.c
SIIS-cloud/Pileus
de7546845cf03862cdd2b9884fefb2033d8b11ab
[ "Apache-2.0" ]
null
null
null
libvirt/pileus-libvirt-1.2.12/src/util/virusb.c
SIIS-cloud/Pileus
de7546845cf03862cdd2b9884fefb2033d8b11ab
[ "Apache-2.0" ]
null
null
null
/* * virusb.c: helper APIs for managing host USB devices * * Copyright (C) 2009-2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see * <http://www.gnu.org/licenses/>. * * Authors: * Daniel P. Berrange <berrange@redhat.com> */ #include <config.h> #include <dirent.h> #include <fcntl.h> #include <inttypes.h> #include <limits.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include "virusb.h" #include "virlog.h" #include "viralloc.h" #include "virutil.h" #include "virerror.h" #include "virfile.h" #include "virstring.h" #define USB_SYSFS "/sys/bus/usb" #define USB_ID_LEN 10 /* "1234 5678" */ #define USB_ADDR_LEN 8 /* "123:456" */ #define VIR_FROM_THIS VIR_FROM_NONE VIR_LOG_INIT("util.usb"); struct _virUSBDevice { unsigned int bus; unsigned int dev; char name[USB_ADDR_LEN]; /* domain:bus:slot.function */ char id[USB_ID_LEN]; /* product vendor */ char *path; /* driver:domain using this dev */ char *used_by_drvname; char *used_by_domname; }; struct _virUSBDeviceList { virObjectLockable parent; size_t count; virUSBDevicePtr *devs; }; typedef enum { USB_DEVICE_ALL = 0, USB_DEVICE_FIND_BY_VENDOR = 1 << 0, USB_DEVICE_FIND_BY_BUS = 1 << 1, } virUSBDeviceFindFlags; static virClassPtr virUSBDeviceListClass; static void virUSBDeviceListDispose(void *obj); static int virUSBOnceInit(void) { if (!(virUSBDeviceListClass = virClassNew(virClassForObjectLockable(), "virUSBDeviceList", sizeof(virUSBDeviceList), virUSBDeviceListDispose))) return -1; return 0; } VIR_ONCE_GLOBAL_INIT(virUSB) static int virUSBSysReadFile(const char *f_name, const char *d_name, int base, unsigned int *value) { int ret = -1, tmp; char *buf = NULL; char *filename = NULL; char *ignore = NULL; tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name); if (tmp < 0) goto cleanup; if (virFileReadAll(filename, 1024, &buf) < 0) goto cleanup; if (virStrToLong_ui(buf, &ignore, base, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not parse usb file %s"), filename); goto cleanup; } ret = 0; cleanup: VIR_FREE(filename); VIR_FREE(buf); return ret; } static virUSBDeviceListPtr virUSBDeviceSearch(unsigned int vendor, unsigned int product, unsigned int bus, unsigned int devno, const char *vroot, unsigned int flags) { DIR *dir = NULL; bool found = false; char *ignore = NULL; struct dirent *de; virUSBDeviceListPtr list = NULL, ret = NULL; virUSBDevicePtr usb; int direrr; if (!(list = virUSBDeviceListNew())) goto cleanup; dir = opendir(USB_SYSFS "/devices"); if (!dir) { virReportSystemError(errno, _("Could not open directory %s"), USB_SYSFS "/devices"); goto cleanup; } while ((direrr = virDirRead(dir, &de, USB_SYSFS "/devices")) > 0) { unsigned int found_prod, found_vend, found_bus, found_devno; char *tmpstr = de->d_name; if (de->d_name[0] == '.' || strchr(de->d_name, ':')) continue; if (virUSBSysReadFile("idVendor", de->d_name, 16, &found_vend) < 0) goto cleanup; if (virUSBSysReadFile("idProduct", de->d_name, 16, &found_prod) < 0) goto cleanup; if (STRPREFIX(de->d_name, "usb")) tmpstr += 3; if (virStrToLong_ui(tmpstr, &ignore, 10, &found_bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse dir name '%s'"), de->d_name); goto cleanup; } if (virUSBSysReadFile("devnum", de->d_name, 10, &found_devno) < 0) goto cleanup; if ((flags & USB_DEVICE_FIND_BY_VENDOR) && (found_prod != product || found_vend != vendor)) continue; if (flags & USB_DEVICE_FIND_BY_BUS) { if (found_bus != bus || found_devno != devno) continue; found = true; } usb = virUSBDeviceNew(found_bus, found_devno, vroot); if (!usb) goto cleanup; if (virUSBDeviceListAdd(list, usb) < 0) { virUSBDeviceFree(usb); goto cleanup; } if (found) break; } if (direrr < 0) goto cleanup; ret = list; cleanup: if (dir) { int saved_errno = errno; closedir(dir); errno = saved_errno; } if (!ret) virObjectUnref(list); return ret; } int virUSBDeviceFindByVendor(unsigned int vendor, unsigned int product, const char *vroot, bool mandatory, virUSBDeviceListPtr *devices) { virUSBDeviceListPtr list; int count; if (!(list = virUSBDeviceSearch(vendor, product, 0, 0, vroot, USB_DEVICE_FIND_BY_VENDOR))) return -1; if (list->count == 0) { virObjectUnref(list); if (!mandatory) { VIR_DEBUG("Did not find USB device %x:%x", vendor, product); if (devices) *devices = NULL; return 0; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Did not find USB device %x:%x"), vendor, product); return -1; } count = list->count; if (devices) *devices = list; else virObjectUnref(list); return count; } int virUSBDeviceFindByBus(unsigned int bus, unsigned int devno, const char *vroot, bool mandatory, virUSBDevicePtr *usb) { virUSBDeviceListPtr list; if (!(list = virUSBDeviceSearch(0, 0, bus, devno, vroot, USB_DEVICE_FIND_BY_BUS))) return -1; if (list->count == 0) { virObjectUnref(list); if (!mandatory) { VIR_DEBUG("Did not find USB device bus:%u device:%u", bus, devno); if (usb) *usb = NULL; return 0; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Did not find USB device bus:%u device:%u"), bus, devno); return -1; } if (usb) { *usb = virUSBDeviceListGet(list, 0); virUSBDeviceListSteal(list, *usb); } virObjectUnref(list); return 0; } int virUSBDeviceFind(unsigned int vendor, unsigned int product, unsigned int bus, unsigned int devno, const char *vroot, bool mandatory, virUSBDevicePtr *usb) { virUSBDeviceListPtr list; unsigned int flags = USB_DEVICE_FIND_BY_VENDOR|USB_DEVICE_FIND_BY_BUS; if (!(list = virUSBDeviceSearch(vendor, product, bus, devno, vroot, flags))) return -1; if (list->count == 0) { virObjectUnref(list); if (!mandatory) { VIR_DEBUG("Did not find USB device %x:%x bus:%u device:%u", vendor, product, bus, devno); if (usb) *usb = NULL; return 0; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Did not find USB device %x:%x bus:%u device:%u"), vendor, product, bus, devno); return -1; } if (usb) { *usb = virUSBDeviceListGet(list, 0); virUSBDeviceListSteal(list, *usb); } virObjectUnref(list); return 0; } virUSBDevicePtr virUSBDeviceNew(unsigned int bus, unsigned int devno, const char *vroot) { virUSBDevicePtr dev; if (VIR_ALLOC(dev) < 0) return NULL; dev->bus = bus; dev->dev = devno; if (snprintf(dev->name, sizeof(dev->name), "%.3d:%.3d", dev->bus, dev->dev) >= sizeof(dev->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("dev->name buffer overflow: %.3d:%.3d"), dev->bus, dev->dev); virUSBDeviceFree(dev); return NULL; } if (virAsprintf(&dev->path, "%s" USB_DEVFS "%03d/%03d", vroot ? vroot : "", dev->bus, dev->dev) < 0) { virUSBDeviceFree(dev); return NULL; } /* XXX fixme. this should be product/vendor */ if (snprintf(dev->id, sizeof(dev->id), "%d %d", dev->bus, dev->dev) >= sizeof(dev->id)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("dev->id buffer overflow: %d %d"), dev->bus, dev->dev); virUSBDeviceFree(dev); return NULL; } VIR_DEBUG("%s %s: initialized", dev->id, dev->name); return dev; } void virUSBDeviceFree(virUSBDevicePtr dev) { if (!dev) return; VIR_DEBUG("%s %s: freeing", dev->id, dev->name); VIR_FREE(dev->path); VIR_FREE(dev->used_by_drvname); VIR_FREE(dev->used_by_domname); VIR_FREE(dev); } int virUSBDeviceSetUsedBy(virUSBDevicePtr dev, const char *drv_name, const char *dom_name) { VIR_FREE(dev->used_by_drvname); VIR_FREE(dev->used_by_domname); if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0) return -1; if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0) return -1; return 0; } void virUSBDeviceGetUsedBy(virUSBDevicePtr dev, const char **drv_name, const char **dom_name) { *drv_name = dev->used_by_drvname; *dom_name = dev->used_by_domname; } const char *virUSBDeviceGetName(virUSBDevicePtr dev) { return dev->name; } unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev) { return dev->bus; } unsigned int virUSBDeviceGetDevno(virUSBDevicePtr dev) { return dev->dev; } int virUSBDeviceFileIterate(virUSBDevicePtr dev, virUSBDeviceFileActor actor, void *opaque) { return (actor)(dev, dev->path, opaque); } virUSBDeviceListPtr virUSBDeviceListNew(void) { virUSBDeviceListPtr list; if (virUSBInitialize() < 0) return NULL; if (!(list = virObjectLockableNew(virUSBDeviceListClass))) return NULL; return list; } static void virUSBDeviceListDispose(void *obj) { virUSBDeviceListPtr list = obj; size_t i; for (i = 0; i < list->count; i++) virUSBDeviceFree(list->devs[i]); VIR_FREE(list->devs); } int virUSBDeviceListAdd(virUSBDeviceListPtr list, virUSBDevicePtr dev) { if (virUSBDeviceListFind(list, dev)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Device %s is already in use"), dev->name); return -1; } return VIR_APPEND_ELEMENT(list->devs, list->count, dev); } virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list, int idx) { if (idx >= list->count || idx < 0) return NULL; return list->devs[idx]; } size_t virUSBDeviceListCount(virUSBDeviceListPtr list) { return list->count; } virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list, virUSBDevicePtr dev) { virUSBDevicePtr ret = NULL; size_t i; for (i = 0; i < list->count; i++) { if (list->devs[i]->bus == dev->bus && list->devs[i]->dev == dev->dev) { ret = list->devs[i]; VIR_DELETE_ELEMENT(list->devs, i, list->count); break; } } return ret; } void virUSBDeviceListDel(virUSBDeviceListPtr list, virUSBDevicePtr dev) { virUSBDevicePtr ret = virUSBDeviceListSteal(list, dev); virUSBDeviceFree(ret); } virUSBDevicePtr virUSBDeviceListFind(virUSBDeviceListPtr list, virUSBDevicePtr dev) { size_t i; for (i = 0; i < list->count; i++) { if (list->devs[i]->bus == dev->bus && list->devs[i]->dev == dev->dev) return list->devs[i]; } return NULL; }
25.17603
77
0.55006
fe17d9988e317c25c51ed233c94c1c9fa323f51e
1,725
c
C
hexutils.c
udoprog/bgrep2
031869a83c1a87ba05e5126b34b03673f2c2ac8b
[ "BSD-2-Clause" ]
4
2015-02-05T09:01:17.000Z
2021-03-06T17:36:43.000Z
hexutils.c
udoprog/bgrep2
031869a83c1a87ba05e5126b34b03673f2c2ac8b
[ "BSD-2-Clause" ]
1
2020-06-26T22:06:21.000Z
2020-06-27T10:51:03.000Z
hexutils.c
udoprog/bgrep2
031869a83c1a87ba05e5126b34b03673f2c2ac8b
[ "BSD-2-Clause" ]
null
null
null
#include "hexutils.h" char hex[3] = {'\0', '\0', '\0'}; char hextable[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; char hexmap[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; const char* bytetohex(char c) { hex[0] = hextable[(c >> 4) & 0xf]; hex[1] = hextable[(c >> 0) & 0xf]; hex[2] = '\0'; return hex; } char hextobyte(const char* h) { return (hexmap[(int)h[0]] << 4) | hexmap[(int)h[1]]; }
45.394737
81
0.554203
f1e8412165fe3e69e5f1d753391a0a4bdee196a1
3,071
c
C
code/integral_solution_parallel.c
lpmatos/parallel-programing
47930f05b30b858bd4317c7ca6f7a4a46df60e63
[ "MIT" ]
null
null
null
code/integral_solution_parallel.c
lpmatos/parallel-programing
47930f05b30b858bd4317c7ca6f7a4a46df60e63
[ "MIT" ]
null
null
null
code/integral_solution_parallel.c
lpmatos/parallel-programing
47930f05b30b858bd4317c7ca6f7a4a46df60e63
[ "MIT" ]
2
2020-09-25T16:42:18.000Z
2021-06-10T13:01:46.000Z
// integral_solution_parallel.c // compile with: /openmp /* ############################################################################# ## DESCRIPTION: Integral Solutin in Parallel using OpenMP - PI Value. ## NAME: integral_solution_parallel.c ## AUTHOR: Lucca Pessoa da Silva Matos ## DATE: 10.04.2020 ## VERSION: 1.0 ## EXEMPLE: ## PS C:\> gcc -fopenmp -o integral_solution_parallel integral_solution_parallel.c ##############################################################################*/ // ============================================================================= // LIBRARYS // ============================================================================= #include <omp.h> #include <math.h> #include <stdio.h> #include <locale.h> #include <stdlib.h> // ============================================================================= // MACROS // ============================================================================= #define STEPS 100000000 #define NUM_THREADS 12 #define LOOP(i, n) for(int i = 0; i < n; i++) // ============================================================================= // CALL FUNCTIONS // ============================================================================= void cabecalho(); void set_portuguese(); double step; // ============================================================================= // MAIN // ============================================================================= int main(int argc, char const *argv[]){ set_portuguese(); cabecalho(); printf("\nHey! Nesse script iremos calcular o valor de PI com base em calculos de integral."); int i; double x, pi, sum = 0.0, tempo_inicial, tempo_final; printf("\n\nSetando o numero de Threads para %d\n", NUM_THREADS); omp_set_num_threads(NUM_THREADS); step = 1.0/(double) STEPS; tempo_inicial = omp_get_wtime(); printf("\n1 - Estamos fora do contexto paralelo. Entrando...\n"); #pragma omp parallel for default(none) shared(x, step) reduction(+:sum) LOOP(i, STEPS){ sum += 4.0 / (1.0 + pow((i + 0.5) * step, 2)); } printf("\n2 - Estamos fora do contexto paralelo. Saindo...\n"); tempo_final = omp_get_wtime() - tempo_inicial; printf("\nO tempo gasto no contexto paralelo foi de: %lf\n", tempo_final); pi = sum * step; printf("\nO valor de PI = %f\n\n", pi); return 0; } // ============================================================================= // FUNCTIONS // ============================================================================= void set_portuguese(){ setlocale(LC_ALL, "Portuguese"); } void cabecalho(){ printf("\n**************************************************"); printf("\n* *"); printf("\n* *"); printf("\n* PROGRAMACAO PARALELA COM OPENMP - LUCCA PESSOA *"); printf("\n* *"); printf("\n* *"); printf("\n**************************************************\n"); }
30.71
96
0.388147
e0b633c853543e687b6a17e7ffd670476353cb08
2,487
h
C
sourcecode/iOS-Blocks/headers/WeatherFoundation/WFAirQualityConditions.h
nickkgar/Nepeta-Mirror
fee9095771a9754982a560d3e3fd86bf94a8da5d
[ "MIT" ]
1
2020-04-05T07:00:22.000Z
2020-04-05T07:00:22.000Z
sourcecode/iOS-Blocks/headers/WeatherFoundation/WFAirQualityConditions.h
nickkgar/Nepeta-Mirror
fee9095771a9754982a560d3e3fd86bf94a8da5d
[ "MIT" ]
7
2020-09-08T01:12:27.000Z
2022-02-27T02:26:35.000Z
sourcecode/iOS-Blocks/headers/WeatherFoundation/WFAirQualityConditions.h
digic3ll/Nepeta-Mirror
903a8134f649f180c944b82df9b7509fb3fcf0e3
[ "MIT" ]
null
null
null
#import "WFLocation.h" @interface WFAirQualityConditions : NSObject <NSSecureCoding> { WFLocation* _location; NSLocale* _locale; NSDate* _date; NSString* _provider; NSInteger _localizedAirQualityIndex; NSString* _localizedAirQualityCategory; NSArray* _pollutants; NSDate* _expirationDate; NSUInteger _category; } @property (nonatomic,retain) WFLocation * location; //@synthesize location=_location - In the implementation block @property (nonatomic,copy) NSLocale * locale; //@synthesize locale=_locale - In the implementation block @property (nonatomic,retain) NSDate * expirationDate; //@synthesize expirationDate=_expirationDate - In the implementation block @property (nonatomic,copy) NSDate * date; //@synthesize date=_date - In the implementation block @property (nonatomic,copy) NSString * provider; //@synthesize provider=_provider - In the implementation block @property (nonatomic,readonly) BOOL isExpired; @property (assign,nonatomic) NSUInteger category; //@synthesize category=_category - In the implementation block @property (assign,nonatomic) NSInteger localizedAirQualityIndex; //@synthesize localizedAirQualityIndex=_localizedAirQualityIndex - In the implementation block @property (nonatomic,copy) NSString * localizedAirQualityCategory; //@synthesize localizedAirQualityCategory=_localizedAirQualityCategory - In the implementation block @property (nonatomic,copy) NSArray * pollutants; //@synthesize pollutants=_pollutants - In the implementation block +(BOOL)supportsSecureCoding; -(id)initWithCoder:(id)arg1 ; -(void)encodeWithCoder:(id)arg1 ; -(void)setCategory:(NSUInteger)arg1 ; -(NSUInteger)category; -(NSDate *)date; -(void)setLocale:(NSLocale *)arg1 ; -(void)setDate:(NSDate *)arg1 ; -(WFLocation *)location; -(NSLocale *)locale; -(void)setLocation:(WFLocation *)arg1 ; -(NSDate *)expirationDate; -(void)setExpirationDate:(NSDate *)arg1 ; -(NSString *)provider; -(void)setProvider:(NSString *)arg1 ; -(NSInteger)airQualityIndex; -(NSArray *)pollutants; -(void)setPollutants:(NSArray *)arg1 ; -(void)setLocalizedAirQualityIndex:(NSInteger)arg1 ; -(NSInteger)localizedAirQualityIndex; -(BOOL)isExpired; -(void)setLocalizedAirQualityCategory:(NSString *)arg1 ; -(NSString *)localizedAirQualityCategory; @end
48.764706
180
0.715722
f22c2567e05fb2935b73b61dd4ea99808a5dab5a
996
c
C
lib/wizards/jhary/room/dwarves/dwarf7.c
vlehtola/questmud
8bc3099b5ad00a9e0261faeb6637c76b521b6dbe
[ "MIT" ]
null
null
null
lib/wizards/jhary/room/dwarves/dwarf7.c
vlehtola/questmud
8bc3099b5ad00a9e0261faeb6637c76b521b6dbe
[ "MIT" ]
null
null
null
lib/wizards/jhary/room/dwarves/dwarf7.c
vlehtola/questmud
8bc3099b5ad00a9e0261faeb6637c76b521b6dbe
[ "MIT" ]
null
null
null
inherit "room/room"; object monster; reset(arg) { if(arg) return; add_exit("northwest","/wizards/jhary/room/dwarves/dwarf6"); add_exit("northeast","/wizards/jhary/room/dwarves/dwarf8"); short_desc = "At a south lane"; long_desc = "Here you are at the south-side of the church. It's \n"+ "located to the north and the wall describes a half \n"+ "circle. there are seven small windows, each lighted \n"+ "with a candle in the wall. The main circle widens here \n"+ "into a small square and a road to the mines turns south. \n"+ "The entrance to the mines is closed at the moment. \n"+ "West from here you can see the cave wall raising into the \n"+ "darkness.Some shops and houses are situated to the east. \n"+ "Instead of going into the mines you can walk further on \n"+ "the circle to northeast or northwest.\n"; }
45.272727
77
0.598394
cc42ae892f0f2173d2ce64af65d6e0ec0cb90fc2
3,233
h
C
src/njli/builders/PlaneBuilder.h
njligames/Engine
899c7b79cea33a72fc34f159134f721b56715d3d
[ "MIT" ]
1
2019-02-13T05:41:54.000Z
2019-02-13T05:41:54.000Z
src/njli/builders/PlaneBuilder.h
njligames/Engine
899c7b79cea33a72fc34f159134f721b56715d3d
[ "MIT" ]
null
null
null
src/njli/builders/PlaneBuilder.h
njligames/Engine
899c7b79cea33a72fc34f159134f721b56715d3d
[ "MIT" ]
null
null
null
// // PlaneBuilder.h // JLIGameEngineTest // // Created by James Folk on 12/26/14. // Copyright (c) 2014 James Folk. All rights reserved. // #ifndef __JLIGameEngineTest__PlaneBuilder__ #define __JLIGameEngineTest__PlaneBuilder__ #include "btAlignedObjectArray.h" #include "Util.h" #include "AbstractBuilder.h" #include "btSerializer.h" #include "lua.hpp" namespace njli { /** * <#Description#> */ ATTRIBUTE_ALIGNED16(class) PlaneBuilder : public AbstractBuilder { friend class WorldFactory; protected: PlaneBuilder(); PlaneBuilder(const PlaneBuilder &); BT_DECLARE_ALIGNED_ALLOCATOR(); virtual ~PlaneBuilder(); PlaneBuilder &operator=(const PlaneBuilder &); public: /** * <#Description#> * * @return <#return value description#> */ virtual s32 calculateSerializeBufferSize() const; /** * <#Description#> * * @param btSerializer <#btSerializer description#> */ virtual void serialize(void*, btSerializer*) const; /** * <#Description#> * * @return <#return value description#> */ virtual u32 getObjectType()const; /** * <#Description#> * * @return <#return value description#> */ virtual const char *getClassName()const; /** * <#Description#> * * @return <#return value description#> */ virtual s32 getType()const; /** * <#Description#> * * @return <#return value description#> */ operator std::string() const; /** * <#Description#> * * @param size <#size description#> * * @return <#return value description#> */ static PlaneBuilder **createArray(const u32 size); /** * <#Description#> * * @param array <#array description#> */ static void destroyArray(PlaneBuilder **array, const u32 size = 0); /** * <#Description#> * * @return <#return value description#> */ static PlaneBuilder *create(); /** * <#Description#> * * @param object <#object description#> * * @return <#return value description#> */ static PlaneBuilder *clone(const PlaneBuilder &object); /** * <#Description#> * * @param object <#object description#> */ static void destroy(PlaneBuilder *object); /** * <#Description#> * * @param object <#object description#> * @param L <#L description#> * @param stack_index <#stack_index description#> */ static void load(PlaneBuilder &object, lua_State *L, int stack_index); /** * <#Description#> * * @return <#return value description#> */ static u32 type(); }; } #endif /* defined(__JLIGameEngineTest__PlaneBuilder__) */
25.65873
78
0.509125
a4455b175695a49fb7a2332f2bef14a4862959a3
535
h
C
src/kernel/graphics/graphics.h
Gabryx64/RecursiveOS
dd806e0c3f17137db6cdcfef142b69f9f9555792
[ "Zlib" ]
1
2021-08-02T03:48:33.000Z
2021-08-02T03:48:33.000Z
src/kernel/graphics/graphics.h
Gabryx64/RecursiveOS
dd806e0c3f17137db6cdcfef142b69f9f9555792
[ "Zlib" ]
null
null
null
src/kernel/graphics/graphics.h
Gabryx64/RecursiveOS
dd806e0c3f17137db6cdcfef142b69f9f9555792
[ "Zlib" ]
1
2021-07-02T01:19:20.000Z
2021-07-02T01:19:20.000Z
#ifndef GRAPHICS_H #define GRAPHICS_H 1 #include<stdint.h> #include<stivale2.h> #include"sys/sys.h" #include"wchar.h" #define RGB(r, g, b) (Color){ r, g, b } #define getcolor(col) (((col.r & 0xff) << fb_tag->red_mask_shift) + ((col.g & 0xff) << fb_tag->green_mask_shift) + ((col.b & 0xff) << fb_tag->blue_mask_shift)) typedef struct { uint8_t r, g, b; } Color; Color UINT_RGB(uint32_t color); void putpixel(int x, int y, Color color); void clearscreen(Color col); void putch(wchar_t ch, int x, int y, Color fg, Color bg); #endif
24.318182
159
0.684112
a896a58a153f3f9549d23f3598d9ca465d22106d
1,622
h
C
PHTpcSeedFinder.h
dmarkh/PHTpcTracker
89bc8b9fcc4eeb0b9f4b698845d56ebb9d26e3d7
[ "MIT" ]
null
null
null
PHTpcSeedFinder.h
dmarkh/PHTpcTracker
89bc8b9fcc4eeb0b9f4b698845d56ebb9d26e3d7
[ "MIT" ]
null
null
null
PHTpcSeedFinder.h
dmarkh/PHTpcTracker
89bc8b9fcc4eeb0b9f4b698845d56ebb9d26e3d7
[ "MIT" ]
1
2020-05-12T16:30:42.000Z
2020-05-12T16:30:42.000Z
/*! * \file PHTpcSeedFinder.h * \brief * \author Dmitry Arkhipkin <arkhipkin@gmail.com> */ #ifndef PHTPCSEEDFINDER_H_ #define PHTPCSEEDFINDER_H_ #include <trackbase/TrkrClusterContainer.h> #include "externals/kdfinder.hpp" /// \class PHTpcSeedFinder /// /// \brief /// class PHTpcSeedFinder { public: PHTpcSeedFinder(); virtual ~PHTpcSeedFinder() {} void set_options( double max_distance1 = 3.0, double triplet_angle1 = M_PI / 8, size_t minhits1 = 10, double max_distance2 = 6.0, double triplet_angle2 = M_PI / 8, size_t minhits2 = 5, size_t nthreads = 1 ) { mMaxDistance1 = max_distance1; mTripletAngle1 = triplet_angle1; mMinHits1 = minhits1; mMaxDistance2 = max_distance2; mTripletAngle2 = triplet_angle2; mMinHits2 = minhits2; mNThreads = nthreads; } void set_optimization_remove_loopers( bool opt = false, double minr = 10.0, double maxr = 70.0 ) { mRemoveLoopers = opt; mMinLooperRadius = minr; mMaxLooperRadius = maxr; } std::vector<kdfinder::TrackCandidate<double>*> findSeeds( TrkrClusterContainer* cluster_map, double B /* magfield */ ); protected: private: double mMaxDistance1; // 3.0 /* max distance in cm*/, double mTripletAngle1; // M_PI / 8 /* triplet angle */, size_t mMinHits1; // 10 /* min hits to keep track */, // first iteration double mMaxDistance2; // 6.0, double mTripletAngle2; // M_PI / 8, size_t mMinHits2; // 5, // second iteration params size_t mNThreads; // 1 /* nthreads */, bool mRemoveLoopers; double mMinLooperRadius; double mMaxLooperRadius; }; #endif /* PHTPCSEEDFINDER_H_ */
29.490909
121
0.694821
2f1072f7efe3c87ed3bdbaa5fdfe21befdff33c9
2,473
h
C
backport-include/linux/acpi.h
Timicapstone/minstrel-Usyd
508664dafb055add01ff8f55165f525cec1077c7
[ "MIT" ]
3
2019-06-04T14:29:04.000Z
2020-05-07T04:47:09.000Z
backport-include/linux/acpi.h
Timicapstone/minstrel-Usyd
508664dafb055add01ff8f55165f525cec1077c7
[ "MIT" ]
null
null
null
backport-include/linux/acpi.h
Timicapstone/minstrel-Usyd
508664dafb055add01ff8f55165f525cec1077c7
[ "MIT" ]
2
2019-06-04T11:02:20.000Z
2021-12-07T03:08:02.000Z
#ifndef __BACKPORT_LINUX_ACPI_H #define __BACKPORT_LINUX_ACPI_H #include_next <linux/acpi.h> #include <linux/version.h> #if LINUX_VERSION_IS_LESS(3,8,0) /* * Backports * * commit 95f8a082b9b1ead0c2859f2a7b1ac91ff63d8765 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> * Date: Wed Nov 21 00:21:50 2012 +0100 * * ACPI / driver core: Introduce struct acpi_dev_node and related macros * * To avoid adding an ACPI handle pointer to struct device on * architectures that don't use ACPI, or generally when CONFIG_ACPI is * not set, in which cases that pointer is useless, define struct * acpi_dev_node that will contain the handle pointer if CONFIG_ACPI is * set and will be empty otherwise and use it to represent the ACPI * device node field in struct device. * * In addition to that define macros for reading and setting the ACPI * handle of a device that don't generate code when CONFIG_ACPI is * unset. Modify the ACPI subsystem to use those macros instead of * referring to the given device's ACPI handle directly. * * Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> * Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> * Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> */ #ifdef CONFIG_ACPI #define ACPI_HANDLE(dev) DEVICE_ACPI_HANDLE(dev) #else #define ACPI_HANDLE(dev) (NULL) #endif /* CONFIG_ACPI */ #endif /* LINUX_VERSION_IS_LESS(3,8,0) */ #ifndef ACPI_COMPANION #ifdef CONFIG_ACPI static inline struct acpi_device *_acpi_get_companion(struct device *dev) { struct acpi_device *adev; int ret; ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev); if (ret < 0) adev = NULL; return adev; } #define ACPI_COMPANION(dev) _acpi_get_companion(dev) #else #define ACPI_COMPANION(dev) (NULL) #endif /* CONFIG_ACPI */ #endif /* ACPI_COMPANION */ #if LINUX_VERSION_IS_LESS(3,19,0) #define acpi_dev_remove_driver_gpios LINUX_BACKPORT(acpi_dev_remove_driver_gpios) static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {} #endif /* LINUX_VERSION_IS_LESS(3, 19, 0) */ #if LINUX_VERSION_IN_RANGE(3,19,0, 4,13,0) #define devm_acpi_dev_add_driver_gpios LINUX_BACKPORT(devm_acpi_dev_add_driver_gpios) static inline int devm_acpi_dev_add_driver_gpios(struct device *dev, const struct acpi_gpio_mapping *gpios) { return -ENXIO; } #endif /* LINUX_VERSION_IN_RANGE(3,19,0, 4,13,0) */ #endif /* __BACKPORT_LINUX_ACPI_H */
33.876712
85
0.75091
7803645c5ce0ad2d691b642248f301effe32113d
6,399
h
C
Device/Interface/Unit/Video/IVideoDisplayTypes.h
rerunner/STCM_driver
8fef3dd7327812fd317fdb0e6fab8d36e345a505
[ "BSD-3-Clause" ]
null
null
null
Device/Interface/Unit/Video/IVideoDisplayTypes.h
rerunner/STCM_driver
8fef3dd7327812fd317fdb0e6fab8d36e345a505
[ "BSD-3-Clause" ]
null
null
null
Device/Interface/Unit/Video/IVideoDisplayTypes.h
rerunner/STCM_driver
8fef3dd7327812fd317fdb0e6fab8d36e345a505
[ "BSD-3-Clause" ]
null
null
null
/// /// @brief Video Display private data types, definitions and simple helper classes /// #ifndef VIDEODISPLAYTYPES_H #define VIDEODISPLAYTYPES_H #include "VDR/Interface/Unit/Video/Display/IVDRVideoDisplayTypes.h" #include "VDR/Interface/Unit/Video/Display/IVDRVideoTypes.h" #include "Device/Interface/Unit/Video/IMPEGVideoTypes.h" /*! \brief Enumerator VDispVideoScanMode */ enum VDispVideoScanMode { VSMODE_INTERLACED = 0, //!< Two fields in bitmap are from two different points in time VSMODE_PROGRESSIVE //!< Both fields in bitmap belong to the same point in time }; ///{ //! Values for VDispBitmap.flags field #define VDISPBMP_BITMAP_VALID 0x00000001 // Bitmap structure valid #define VDISPBMP_DISABLE_DISPLAY 0x00000002 #define VDISPBMP_SHOW_AS_LETTERBOX 0x00000004 #define VDISPBMP_SHOW_ON_MAIN_OUT 0x00000008 #define VDISPBMP_SHOW_ON_AUX_OUT 0x00000010 #define VDISPBMP_TOP_FIELD_FIRST 0x00000020 // If set, the top field is ealier in time than the bottom field #define VDISPBMP_REPEAT_FIELD 0x00000040 // If set, the frame is shown for three field times, the first hown field is repeated #define VDISPBMP_COLOR_FILL 0x00000080 #define VDISPBMP_OBEY_FIELD_POLARITY 0x00000400 // independent from the frame being marked progressive we use this flag to obey VDISPBMP_TOP_FIELD_FIRST #define VDISPBMP_RENDER_DURATION_VALID 0x00000800 ///< Debug facility: If this bit is set the renderDuration field is valid #define VDISPBMP_VBI_BITMAP 0x00001000 // VBI bitmap can be treated special at mixer so it does not go through blitter ///} /*! \brief Constants related to VDispBitmapDesc::pixelAspectRatio Pixel aspect ratio is defined as pixelWidth/pixelHeight. Such obtained aspect ratio is farther multiplied by 675 - that means, value 675 is aspect ratio 1. This value is chosed because it avoids fractional errors and 32-bit overflows for all possible aspect ratio calculations. */ ///{ #define VD_PIX_ASPECT_RATIO_1_BY_1 675 ///< Pixel aspect ratio 1:1 = 1.000 - square pixel #define VD_PIX_ASPECT_RATIO_4_BY_3 900 ///< Pixel aspect ratio 4:3 = 1.333 #define VD_PIX_ASPECT_RATIO_NTSC_4_BY_3 600 ///< Pixel aspect ratio 24:27 = 0.889 (pixel in 4:3 NTSC frame) #define VD_PIX_ASPECT_RATIO_PAL_4_BY_3 720 ///< Pixel aspect ratio 144:135 = 1.067 (pixel in 4:3 PAL frame) #define VD_PIX_ASPECT_RATIO_NTSC_16_BY_9 800 ///< Pixel aspect ratio 32:27 = 1.185 (pixel in 16:9 NTSC frame) #define VD_PIX_ASPECT_RATIO_PAL_16_BY_9 960 ///< Pixel aspect ratio 192:135 = 1.422 (pixel in 16:9 PAL frame) ///} /*! \brief Structure VDispBitmapDesc Holds all the bitmap description information nedded for displaying the bitmap. */ struct VDispBitmapDesc { VDRGfxBitmapDesc gfxDesc; //!< Basic bitmap description //@{ //! Additional bitmap paramters used within the driver uint8 alpha; //!< Alpha (transparency) value associated with this bitmap. 0 - fully transparent, 255 - fully opaque. uint32 flags; //!< Different flags int16 letterboxStripeHeight; //!< Height of the letterbox stripe if bitmap should be shown in this mode, that is if VDISPBMP_SHOW_AS_LETTERBOX flag is set. uint32 pixelAspectRatio; //!< Pixel aspect ratio (pixel width / height * 675) - exact range of values still to be defined VDRGfxColorRGB fillColor; //!< Color value to fill bitmap destination area with when flag VDISPBMP_COLOR_FILL is set VDRGfxColorRGB srcClrKeyLower; //!< Lower limit for source color keying VDRGfxColorRGB srcClrKeyUpper; //!< Upper limit for source color keying VDRGfxColorRGB destClrKeyLower; //!< Lower limit for destination color keying VDRGfxColorRGB destClrKeyUpper; //!< Upper limit for destination color keying VDRGfxScanLayout bitmapScanLayout; //!< Bitmap layout: fields stored separately, or interleaved into a frame VDispVideoScanMode bitmapScanMode; //!< Bitmap scan mode: interlaced or progressive VideoBitmapContent bitmapContent; //!< Bitmap field content: both fields/frame, top or bottom VDRGfxRect srcRect; //!< Position and size of source rectangle VDRGfxRect destRect; //!< Position and size of rectangle on destination int16 zOrder; //!< Position of the bitmap in z-order STFHiPrec32BitDuration fieldDuration; //!< Used in case of interlaced frame to calculate the start time of the second field bool bitmapBusy; //!< If this flag is set, the bitmap is currently being rendered and not yet ready to be displayed or processed further STFHiPrec32BitDuration renderDuration; //!< Debug facility: If the corresponding bit is set in the flags, the time it took to render this bitmap is stored here uint32 uniqueID; //!< This ID is assidned and used internally by video mixer and blitter. Don't use this field otherwise, it may be overwritten PictureDisplayExtension panScanOffsets; //!< Contains optional pan scan offsets associated with this frame (depending on 'validNumber') ClosedCaptioning closedCaptioning; //!< Contains optional closed captioning data associated with this frame (depending on 'validBytes') //@} }; /*! \brief Structure VDispBitmap Holds all the information nedded for displaying bitmap, including bitmap pixels. */ struct VDispBitmap { VDRGfxBitmapPixels gfxPix; //!< Contains "pointers" to pixel data VDispBitmapDesc desc; //!< Bitmap description }; //Temporary class - will be removed and replaced by appropriate STF class class Uint32RegisterAccess { public: Uint32RegisterAccess(void* regBaseAddr) { this->regBaseAddr = (uint8*)regBaseAddr; } void WriteReg(uint32 regOffs, uint32 value) { #ifndef _WIN32 *((uint32*)(regBaseAddr+regOffs)) = value; #endif } uint32 ReadReg(uint32 regOffs) { #ifndef _WIN32 return *((uint32*)(regBaseAddr+regOffs)); #else return 0; #endif } protected: uint8* regBaseAddr; }; #endif
44.131034
177
0.698703
7a9cd93c83197809e9a71a7149922481d60b9d41
4,509
h
C
chromium/cc/animation/element_animations.h
wedataintelligence/vivaldi-source
22a46f2c969f6a0b7ca239a05575d1ea2738768c
[ "BSD-3-Clause" ]
27
2016-04-27T01:02:03.000Z
2021-12-13T08:53:19.000Z
chromium/cc/animation/element_animations.h
wedataintelligence/vivaldi-source
22a46f2c969f6a0b7ca239a05575d1ea2738768c
[ "BSD-3-Clause" ]
2
2017-03-09T09:00:50.000Z
2017-09-21T15:48:20.000Z
chromium/cc/animation/element_animations.h
wedataintelligence/vivaldi-source
22a46f2c969f6a0b7ca239a05575d1ea2738768c
[ "BSD-3-Clause" ]
17
2016-04-27T02:06:39.000Z
2019-12-18T08:07:00.000Z
// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CC_ANIMATION_ELEMENT_ANIMATIONS_H_ #define CC_ANIMATION_ELEMENT_ANIMATIONS_H_ #include "base/containers/linked_list.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "cc/animation/animation_delegate.h" #include "cc/animation/layer_animation_controller.h" #include "cc/animation/layer_animation_value_provider.h" #include "cc/base/cc_export.h" namespace gfx { class ScrollOffset; class Transform; } namespace cc { class AnimationHost; class AnimationPlayer; class FilterOperations; class LayerAnimationController; enum class LayerTreeType; // An ElementAnimations owns a list of all AnimationPlayers, attached to // the layer. Also, it owns LayerAnimationController instance (1:1 // relationship) // ElementAnimations object redirects all events from LAC to the list // of animation layers. // This is a CC counterpart for blink::ElementAnimations (in 1:1 relationship). // No pointer to/from respective blink::ElementAnimations object for now. class CC_EXPORT ElementAnimations : public AnimationDelegate, public LayerAnimationValueProvider { public: static scoped_ptr<ElementAnimations> Create(AnimationHost* host); ~ElementAnimations() override; int layer_id() const { return layer_animation_controller_ ? layer_animation_controller_->id() : 0; } // Parent AnimationHost. AnimationHost* animation_host() { return animation_host_; } const AnimationHost* animation_host() const { return animation_host_; } LayerAnimationController* layer_animation_controller() const { return layer_animation_controller_.get(); } void CreateLayerAnimationController(int layer_id); void DestroyLayerAnimationController(); void LayerRegistered(int layer_id, LayerTreeType tree_type); void LayerUnregistered(int layer_id, LayerTreeType tree_type); bool has_active_value_observer_for_testing() const { return active_value_observer_; } bool has_pending_value_observer_for_testing() const { return pending_value_observer_; } void AddPlayer(AnimationPlayer* player); void RemovePlayer(AnimationPlayer* player); bool IsEmpty() const; typedef base::LinkedList<AnimationPlayer> PlayersList; typedef base::LinkNode<AnimationPlayer> PlayersListNode; const PlayersList& players_list() const { return *players_list_.get(); } void PushPropertiesTo(ElementAnimations* element_animations_impl); private: explicit ElementAnimations(AnimationHost* host); void SetFilterMutated(LayerTreeType tree_type, const FilterOperations& filters); void SetOpacityMutated(LayerTreeType tree_type, float opacity); void SetTransformMutated(LayerTreeType tree_type, const gfx::Transform& transform); void SetScrollOffsetMutated(LayerTreeType tree_type, const gfx::ScrollOffset& scroll_offset); void SetTransformIsPotentiallyAnimatingChanged(LayerTreeType tree_type, bool is_animating); void CreateActiveValueObserver(); void DestroyActiveValueObserver(); void CreatePendingValueObserver(); void DestroyPendingValueObserver(); // AnimationDelegate implementation void NotifyAnimationStarted(base::TimeTicks monotonic_time, Animation::TargetProperty target_property, int group) override; void NotifyAnimationFinished(base::TimeTicks monotonic_time, Animation::TargetProperty target_property, int group) override; void NotifyAnimationAborted(base::TimeTicks monotonic_time, Animation::TargetProperty target_property, int group) override; // LayerAnimationValueProvider implementation. gfx::ScrollOffset ScrollOffsetForAnimation() const override; scoped_ptr<PlayersList> players_list_; class ValueObserver; scoped_ptr<ValueObserver> active_value_observer_; scoped_ptr<ValueObserver> pending_value_observer_; // LAC is owned by ElementAnimations (1:1 relationship). scoped_refptr<LayerAnimationController> layer_animation_controller_; AnimationHost* animation_host_; DISALLOW_COPY_AND_ASSIGN(ElementAnimations); }; } // namespace cc #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_
35.785714
79
0.746729
7adf67b1e7e1ba579d5b5e31e2a039ac2f72b268
732
h
C
System/Library/PrivateFrameworks/CoreDuet.framework/_DKDataProtectionMonitor.h
zhangkn/iOS14Header
4323e9459ed6f6f5504ecbea2710bfd6c3d7c946
[ "MIT" ]
1
2020-11-04T15:43:01.000Z
2020-11-04T15:43:01.000Z
System/Library/PrivateFrameworks/CoreDuet.framework/_DKDataProtectionMonitor.h
zhangkn/iOS14Header
4323e9459ed6f6f5504ecbea2710bfd6c3d7c946
[ "MIT" ]
null
null
null
System/Library/PrivateFrameworks/CoreDuet.framework/_DKDataProtectionMonitor.h
zhangkn/iOS14Header
4323e9459ed6f6f5504ecbea2710bfd6c3d7c946
[ "MIT" ]
null
null
null
/* * This header is generated by classdump-dyld 1.0 * on Sunday, September 27, 2020 at 11:39:21 AM Mountain Standard Time * Operating System: Version 14.0 (Build 18A373) * Image Source: /System/Library/PrivateFrameworks/CoreDuet.framework/CoreDuet * classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos. */ @protocol OS_dispatch_queue; @class NSMutableDictionary, NSObject; @interface _DKDataProtectionMonitor : NSObject { NSMutableDictionary* _handlers; BOOL _deviceFormatedForContentProtection; NSMutableDictionary* _availableState; NSObject*<OS_dispatch_queue> _stateQueue; NSObject*<OS_dispatch_queue> _notifyQueue; int _notifyToken; BOOL _notifyEnabled; } -(void)dealloc; -(id)init; @end
26.142857
81
0.795082
18fdbb66422df4cbecfacbb2440e189c74202429
2,517
h
C
include/video.h
javiermontenegro/C_VideoStore
3158b7c37def3787e0990741cdc82d53e34db6eb
[ "MIT" ]
null
null
null
include/video.h
javiermontenegro/C_VideoStore
3158b7c37def3787e0990741cdc82d53e34db6eb
[ "MIT" ]
null
null
null
include/video.h
javiermontenegro/C_VideoStore
3158b7c37def3787e0990741cdc82d53e34db6eb
[ "MIT" ]
null
null
null
#ifndef VIDEO_H #define VIDEO_H /*! \file video.h * \brief Definitions for memory allocated entries. * * The entry datatype supports the storage of attributes pertaining to * entries from an video store, such as film name, production co, * stars and story line. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <stdbool.h> #include <sqlite3.h> #define MAXLENGTH 512 sqlite3 *db; char *zErrMsg; int rc; char sql[MAXLENGTH]; /*! \typedef video_t * \brief Type definition for video store entries. */ struct video { char film_name [MAXLENGTH]; char production_co [MAXLENGTH]; char director [MAXLENGTH]; char stars [MAXLENGTH]; char language [MAXLENGTH]; char runtime [MAXLENGTH]; char country [MAXLENGTH]; char release_date [MAXLENGTH]; char story_line [MAXLENGTH]; }; typedef struct video video_t; /*! \fn bool add_entry(sqlite3* db, video_t* video) * \brief Creates an entry. * \return On success true. * Otherwise false is returned and errno is set appropriately. */ extern bool add_entry(sqlite3* db, video_t* video); /*! \fn int display_entries(sqlite3* db) * \brief Display entries. * \return On success count of entries. * Otherwise 0 is returned and errno is set appropriately. */ extern int display_entries(sqlite3* db); /*! \fn bool delete_entry(const unsigned int index) * \brief Delete an entry. * \return On success true. * Otherwise false is returned and errno is set appropriately. */ extern bool delete_entry(const unsigned int index); /*! \fn bool edit_entry(const unsigned int index, const unsigned int field_option, video_t* video) * \brief Edit an entry. * \return On success true. * Otherwise false is returned and errno is set appropriately. */ extern bool edit_entry(const unsigned int index, const unsigned int field_option, video_t* video); /*! \fn int find_entry(sqlite3* db, const char *film_name) * \brief Find a entry. * \return On success count of entries. * Otherwise 0 is returned and errno is set appropriately. */ extern int find_entry(sqlite3* db, const char *film_name); /*! \fn int assert_credentials(sqlite3* db, const char *username, const char *password) * \brief Find a entry. * \return On success 1. * Otherwise 0 is returned and errno is set appropriately. */ extern int assert_credentials(sqlite3* db, const char *username, const char *password); #endif /* VIDEO_H */
28.602273
98
0.700834
2b6bc888e8be3648cfb0569d6848943d1e3ecdeb
395
h
C
ios/versioned-react-native/ABI41_0_0/Expo/ExpoKit/Core/Api/Components/ViewPager/ABI41_0_0RCTOnPageScrollEvent.h
ahmadtech199/expo
b35f4713789b48c8ba72d7abe7089e5dfa031c41
[ "Apache-2.0", "MIT" ]
16,461
2017-03-24T19:59:01.000Z
2022-03-31T21:52:45.000Z
ios/versioned-react-native/ABI41_0_0/Expo/ExpoKit/Core/Api/Components/ViewPager/ABI41_0_0RCTOnPageScrollEvent.h
ahmadtech199/expo
b35f4713789b48c8ba72d7abe7089e5dfa031c41
[ "Apache-2.0", "MIT" ]
13,016
2017-03-25T22:49:31.000Z
2022-03-31T23:23:58.000Z
ios/versioned-react-native/ABI41_0_0/Expo/ExpoKit/Core/Api/Components/ViewPager/ABI41_0_0RCTOnPageScrollEvent.h
ahmadtech199/expo
b35f4713789b48c8ba72d7abe7089e5dfa031c41
[ "Apache-2.0", "MIT" ]
3,945
2017-03-25T07:12:57.000Z
2022-03-31T20:55:18.000Z
#import <Foundation/Foundation.h> #import <ABI41_0_0React/ABI41_0_0RCTViewManager.h> NS_ASSUME_NONNULL_BEGIN @interface ABI41_0_0RCTOnPageScrollEvent : NSObject <ABI41_0_0RCTEvent> - (instancetype) initWithABI41_0_0ReactTag:(NSNumber *)ABI41_0_0ReactTag position:(NSNumber *)position offset:(NSNumber *)offset; @end NS_ASSUME_NONNULL_END
26.333333
72
0.726582
9e62af46c54861a8daff546856ee5b69847233a3
7,340
h
C
src/statistics.h
vroland/sharpSAT
edfbde3424ce17d72d7f8d8f5b8681f2247f4932
[ "MIT" ]
null
null
null
src/statistics.h
vroland/sharpSAT
edfbde3424ce17d72d7f8d8f5b8681f2247f4932
[ "MIT" ]
null
null
null
src/statistics.h
vroland/sharpSAT
edfbde3424ce17d72d7f8d8f5b8681f2247f4932
[ "MIT" ]
null
null
null
/* * statistics.h * * Created on: Feb 13, 2013 * Author: mthurley */ #ifndef STATISTICS_H_ #define STATISTICS_H_ #include <string> #include <cstdint> #include <vector> #include <gmpxx.h> #include "structures.h" #include "component_types/cacheable_component.h" #include "primitive_types.h" using namespace std; class DataAndStatistics { public: string input_file_; double time_elapsed_ = 0.0; uint64_t maximum_cache_size_bytes_ = 0; SOLVER_StateT exit_state_ = NO_STATE; // different variable counts // number of variables and clauses before preprocessing unsigned long num_original_variables_ = 0; unsigned long num_original_clauses_ = 0; unsigned long num_original_binary_clauses_ = 0; unsigned long num_original_unit_clauses_ = 0; // number of variables remaining unsigned long num_variables_ = 0; // number of variables that actually occurs in clauses unsigned long num_used_variables_ = 0; unsigned long num_free_variables_ = 0; /// different clause counts // number of clauses after preprocessing unsigned long num_long_clauses_ = 0; unsigned long num_binary_clauses_ = 0; unsigned long num_long_conflict_clauses_ = 0; unsigned long num_binary_conflict_clauses_ = 0; unsigned long times_conflict_clauses_cleaned_ = 0; unsigned long num_unit_clauses_ = 0; /// number of all decisions made unsigned long num_decisions_ = 0; /// number of all implications derived unsigned long num_implications_ = 0; // number of all failed literal detections unsigned long num_failed_literals_detected_ = 0; unsigned long num_failed_literal_tests_ = 0; // number of all conflicts occurred unsigned long num_conflicts_ = 0; // number of clauses overall learned unsigned num_clauses_learned_ = 0; /* cache statistics */ uint64_t num_cache_hits_ = 0; uint64_t num_cache_look_ups_ = 0; uint64_t sum_cache_hit_sizes_ = 0; uint64_t num_cached_components_ = 0; uint64_t sum_size_cached_components_ = 0; // the number of bytes occupied by all // components uint64_t sum_bytes_cached_components_ = 0; // the same number, summing over all components ever stored uint64_t overall_bytes_components_stored_ = 0; // the above numbers, but without any overhead, // counting only the pure data size of the components - without model counts uint64_t sum_bytes_pure_cached_component_data_ = 0; // the same number, summing over all components ever stored uint64_t overall_bytes_pure_stored_component_data_ = 0; uint64_t sys_overhead_sum_bytes_cached_components_ = 0; // the same number, summing over all components ever stored uint64_t sys_overhead_overall_bytes_components_stored_ = 0; uint64_t cache_infrastructure_bytes_memory_usage_ = 0; uint64_t overall_num_cache_stores_ = 0; /*end statistics */ bool cache_full(){ return cache_bytes_memory_usage() >= maximum_cache_size_bytes_; } uint64_t cache_bytes_memory_usage(){ return cache_infrastructure_bytes_memory_usage_ + sum_bytes_cached_components_; } uint64_t overall_cache_bytes_memory_stored(){ return cache_infrastructure_bytes_memory_usage_ + overall_bytes_components_stored_; } void incorporate_cache_store(CacheableComponent &ccomp){ sum_bytes_cached_components_ += ccomp.SizeInBytes(); sum_size_cached_components_ += ccomp.num_variables(); num_cached_components_++; overall_bytes_components_stored_ += ccomp.SizeInBytes(); overall_num_cache_stores_ += ccomp.num_variables(); sys_overhead_sum_bytes_cached_components_ += ccomp.sys_overhead_SizeInBytes(); sys_overhead_overall_bytes_components_stored_ += ccomp.sys_overhead_SizeInBytes(); sum_bytes_pure_cached_component_data_ += ccomp.data_only_byte_size(); overall_bytes_pure_stored_component_data_ += ccomp.data_only_byte_size(); } void incorporate_cache_erase(CacheableComponent &ccomp){ sum_bytes_cached_components_ -= ccomp.SizeInBytes(); sum_size_cached_components_ -= ccomp.num_variables(); num_cached_components_--; sum_bytes_pure_cached_component_data_ -= ccomp.data_only_byte_size(); sys_overhead_sum_bytes_cached_components_ -= ccomp.sys_overhead_SizeInBytes(); } void incorporate_cache_hit(CacheableComponent &ccomp){ num_cache_hits_++; sum_cache_hit_sizes_ += ccomp.num_variables(); } unsigned long cache_MB_memory_usage() { return cache_bytes_memory_usage() / 1000000; } mpz_class final_solution_count_ = 0; double implicitBCP_miss_rate() { if(num_failed_literal_tests_ == 0) return 0.0; return (num_failed_literal_tests_ - num_failed_literals_detected_) / (double) num_failed_literal_tests_; } unsigned long num_clauses() { return num_long_clauses_ + num_binary_clauses_ + num_unit_clauses_; } unsigned long num_conflict_clauses() { return num_long_conflict_clauses_ + num_binary_conflict_clauses_; } unsigned long clause_deletion_interval() { return 10000 + 10 * times_conflict_clauses_cleaned_; } void set_final_solution_count(const mpz_class &count) { // set final_solution_count_ = count * 2^(num_variables_ - num_used_variables_) mpz_mul_2exp(final_solution_count_.get_mpz_t (),count.get_mpz_t (), num_variables_ - num_used_variables_); } const mpz_class &final_solution_count() const { return final_solution_count_; } void incorporateConflictClauseData(const vector<LiteralID> &clause) { if (clause.size() == 1) num_unit_clauses_++; else if (clause.size() == 2) num_binary_conflict_clauses_++; num_long_conflict_clauses_++; } void incorporateClauseData(const vector<LiteralID> &clause) { if (clause.size() == 1) num_unit_clauses_++; else if (clause.size() == 2) num_binary_clauses_++; else num_long_clauses_++; } void print_final_solution_count(); void writeToFile(const string & file_name); void printShort(); void printShortFormulaInfo() { cout << "variables (all/used/free): \t"; cout << num_variables_ << "/" << num_used_variables_ << "/"; cout << num_variables_ - num_used_variables_ << endl; cout << "clauses (all/long/binary/unit): "; cout << num_clauses() << "/" << num_long_clauses_; cout << "/" << num_binary_clauses_ << "/" << num_unit_clauses_ << endl; } unsigned getTime() { return num_decisions_; } double avgCachedSize() { if (num_cache_hits_ == 0) return 0.0; return (double) sum_size_cached_components_ / (double) num_cached_components_; } double avgCacheHitSize() { if (num_cache_hits_ == 0) return 0.0; return (double) sum_cache_hit_sizes_ / (double) num_cache_hits_; } long double getAvgComponentSize() { return sum_size_cached_components_ / (long double) num_cached_components_; } unsigned long cached_component_count() { return num_cached_components_; } unsigned long cache_hits() { return num_cache_hits_; } double cache_miss_rate() { if(num_cache_look_ups_ == 0) return 0.0; return (num_cache_look_ups_ - num_cache_hits_) / (double) num_cache_look_ups_; } long double getAvgCacheHitSize() { if(num_cache_hits_ == 0) return 0.0; return sum_cache_hit_sizes_ / (long double) num_cache_hits_; } }; #endif /* STATISTICS_H_ */
30.205761
110
0.741689