Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9adefb4ce6 |
24765
Include/json.hpp
24765
Include/json.hpp
File diff suppressed because it is too large
Load Diff
2930
Makefile.Debug
2930
Makefile.Debug
File diff suppressed because one or more lines are too long
2930
Makefile.Release
2930
Makefile.Release
File diff suppressed because one or more lines are too long
318
camera.cpp
318
camera.cpp
@ -1,5 +1,6 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
// Debug Options
|
||||
#define GlobalDebug 0 // 全局是否允许打印Debug信息(打印会拖慢处理时间)
|
||||
@ -40,9 +41,13 @@ int SaveImg_Flag;
|
||||
ONNXRunner runner;
|
||||
|
||||
|
||||
|
||||
|
||||
int dual_cam_offset_y = 0; // 双相机之间的上下偏移值
|
||||
int widthBlocks = 20; // 输出的喷阀通道数
|
||||
int heightBlocks = 512; // 输出的Mask高度
|
||||
int sizeThreshold = 4; // 转化为喷阀的每块要求像素个数
|
||||
int expansionRaidus = 1; // 获取mask后进行左右位置的扩展
|
||||
int padLeft = 1; // 左侧在结果Mask上补0
|
||||
int padRight = 1; // 右侧在结果Mask上补0
|
||||
int rowRange = 1; // 结果维持行数(至少为1)
|
||||
@ -59,18 +64,13 @@ static std::vector<std::vector<uint8_t>> tail_1(0);
|
||||
|
||||
uint8_t temp_buf[512 * 64] = {0};
|
||||
|
||||
// 总体参数
|
||||
extern int lowmac_sm; //吹气量
|
||||
extern int file_delay;
|
||||
extern int file_encoder;
|
||||
extern int file_valve;
|
||||
|
||||
// 颜色模块参数
|
||||
extern int sizeThreshold; // 转化为喷阀的每块要求像素个数
|
||||
extern int expansionRaidus; // 获取mask后进行左右位置的扩展
|
||||
extern int file_delay;
|
||||
|
||||
// 偏振模块参数
|
||||
//下位机参数
|
||||
extern int lowmac_dp; //偏振延迟时间
|
||||
extern int lowmac_sm; //吹气量
|
||||
extern int lowmac_ts; //模板匹配阈值
|
||||
extern int lowmac_sg; //偏振绿色通道大小阈值
|
||||
extern int lowmac_td; //偏振红色通道差值
|
||||
@ -78,7 +78,7 @@ extern int lowmac_td; //偏振红色通道差值
|
||||
Timer CallBackTimer0;
|
||||
Timer CallBackTimer1;
|
||||
|
||||
|
||||
// ONNXRunner runner;
|
||||
bool iniCamera()
|
||||
{
|
||||
//分配application
|
||||
@ -134,6 +134,12 @@ bool iniCamera()
|
||||
return 1;
|
||||
}
|
||||
|
||||
// #if(GlobalDebug && DebugDetection)
|
||||
// // #define SAVE_PATH_resize MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//resize.png")
|
||||
// #define SAVE_PATH_flip MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//flip.png")
|
||||
// #define SAVE_PATH_raw MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//raw.png")
|
||||
// #define SAVE_PATH_result MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//result.png")
|
||||
// #endif
|
||||
|
||||
MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
{
|
||||
@ -230,9 +236,7 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
#endif
|
||||
// 任务在指定时间内完成,可以继续使用 detection_result1 \
|
||||
// 将 Matrox 的检测结果转换为 二维vector
|
||||
matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold,
|
||||
params["screen_left_" + std::to_string(camera_id)],
|
||||
params["screen_right_" + std::to_string(camera_id)]);
|
||||
matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -274,9 +278,7 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
timer_detection_time.restart();
|
||||
#endif
|
||||
// 将深度学习的检测结果转换为 OpenCV Mat
|
||||
dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold,
|
||||
params["screen_left_" + std::to_string(camera_id)],
|
||||
params["screen_right_" + std::to_string(camera_id)]);
|
||||
dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold);
|
||||
merged_mask = ImageUtils::mergeMasks(dl_mask, matrox_mask);
|
||||
}
|
||||
else
|
||||
@ -404,9 +406,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
#endif
|
||||
// 任务在20ms内完成,可以继续使用 detection_result1 \
|
||||
// 将 Matrox 的检测结果转换为 二维vector
|
||||
matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold,
|
||||
params["screen_left_" + std::to_string(camera_id)],
|
||||
params["screen_right_" + std::to_string(camera_id)]);
|
||||
matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold);
|
||||
#if(GlobalDebug && DebugDetectionTime)
|
||||
timer_detection_time.printElapsedTime("CallBack2: High sat detection to mask");
|
||||
timer_detection_time.restart();
|
||||
@ -452,9 +452,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
timer_detection_time.restart();
|
||||
#endif
|
||||
// 将深度学习的检测结果转换为 OpenCV Mat
|
||||
dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold,
|
||||
params["screen_left_" + std::to_string(camera_id)],
|
||||
params["screen_right_" + std::to_string(camera_id)]);
|
||||
dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold);
|
||||
merged_mask = ImageUtils::mergeMasks(dl_mask, matrox_mask);
|
||||
}
|
||||
else
|
||||
@ -551,25 +549,36 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
// 将结果的左右补充上0,让物体大小符合要求
|
||||
PadColumns(mask_expaned, padLeft, padRight, 0);
|
||||
|
||||
max_valves_together_limit(mask_expaned, params["max_valves_together"]);
|
||||
|
||||
// ======= 新增:统计 mask_expaned 里的 1 的总个数,并累加到全局变量 =======
|
||||
{
|
||||
long long count_ones_this_time = 0;
|
||||
for(const auto & row : mask_expaned)
|
||||
{
|
||||
for(uint8_t val : row)
|
||||
{
|
||||
count_ones_this_time += (val == 1);
|
||||
}
|
||||
}
|
||||
g_valveActionCount += count_ones_this_time;
|
||||
// 如果你想调试打印,可以
|
||||
// qDebug() << "This callback1 new triggered bits =" << count_ones_this_time
|
||||
// << ", total=" << g_valveActionCount;
|
||||
}
|
||||
// ======= 新增结束 =======
|
||||
//将mask扩展到合适发送的大小
|
||||
std::vector<std::vector<uint8_t>> mask_Total = expandArray(mask_expaned,64);
|
||||
|
||||
if(!g_lower_machine_connected.load())
|
||||
{
|
||||
qWarning() << "下位机未连接";
|
||||
#if(GlobalDebug && DebugDetectionTime)
|
||||
call_back_timer1.printElapsedTime("CallBack2: Total time spent: ");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
// save masks
|
||||
// #if(GlobalDebug && DebugDetection)
|
||||
// VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask" + std::to_string(FuncCount1) + ".bmp");
|
||||
// VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask_ignored" + std::to_string(FuncCount1) + ".bmp");
|
||||
// VectorToImg(mask_Total,"C:/Users/Pc/Desktop/img/mask_expended" + std::to_string(FuncCount1) + ".bmp");
|
||||
// #endif
|
||||
// 发送到下位机
|
||||
bool result_Low = get_valve_data(mask_Total);
|
||||
if(!result_Low)
|
||||
{
|
||||
g_lower_machine_connected.store(result_Low);
|
||||
qWarning() << "下位机发送失败";
|
||||
qWarning()<<"下位机发送失败";
|
||||
}
|
||||
|
||||
|
||||
@ -594,13 +603,10 @@ bool DestoryCamera()
|
||||
|
||||
MbufFree(MilImage0);
|
||||
MbufFree(MilImage1);
|
||||
|
||||
MbufFree(MilImage_Color0);
|
||||
MbufFree(MilImage_Color1);
|
||||
|
||||
MdigFree(MilDigitizer0);
|
||||
MdigFree(MilDigitizer1);
|
||||
|
||||
MsysFree(MilSystem);
|
||||
MappFree(MilApplication);
|
||||
|
||||
@ -679,6 +685,14 @@ void read_color(const std::string& filename, std::vector<std::string>& colors) {
|
||||
|
||||
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds= 10) {
|
||||
// 读取图像
|
||||
// cv::Mat image = cv::imread(imagePath, cv::IMREAD_GRAYSCALE);
|
||||
|
||||
// // 检查图像是否成功读取
|
||||
// if (image.empty()) {
|
||||
// std::cerr << "无法加载图像,请检查路径是否正确: " << imagePath << std::endl;
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
cv::Mat image=ImageUtils::mil2Mat(inputImage);
|
||||
// 确保图像是二值化的
|
||||
cv::threshold(image, image, 128, 255, cv::THRESH_BINARY);
|
||||
@ -720,85 +734,51 @@ std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromMatImage(
|
||||
const cv::Mat& image,
|
||||
int outputWidth,
|
||||
int outputHeight,
|
||||
int thresholds,
|
||||
int skipLeftCols,
|
||||
int skipRightCols) {
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds= 10) {
|
||||
|
||||
// Ensure the image is binary
|
||||
// 确保图像是二值化的-*
|
||||
cv::threshold(image, image, 128, 255, cv::THRESH_BINARY);
|
||||
|
||||
// 获取图像的宽度和高度
|
||||
int imageWidth = image.cols;
|
||||
int imageHeight = image.rows;
|
||||
|
||||
// Adjust image width by excluding skipLeftCols and skipRightCols
|
||||
int effectiveWidth = imageWidth - skipLeftCols - skipRightCols;
|
||||
if (effectiveWidth <= 0) {
|
||||
throw std::invalid_argument("Invalid column skip values. Effective width is less than or equal to zero.");
|
||||
}
|
||||
// 计算每个块的宽度和高度
|
||||
int blockWidth = imageWidth / widthBlocks;
|
||||
int blockHeight = imageHeight / heightBlocks;
|
||||
|
||||
int blockWidth = effectiveWidth / outputWidth;
|
||||
int blockHeight = imageHeight / outputHeight;
|
||||
// 创建掩膜矩阵
|
||||
std::vector<std::vector<uint8_t>> mask(heightBlocks, std::vector<uint8_t>(widthBlocks, false));
|
||||
|
||||
vector<vector<uint8_t>> mask(outputHeight, vector<uint8_t>(outputWidth, 0));
|
||||
|
||||
for (int i = 0; i < outputHeight; ++i) {
|
||||
for (int j = 0; j < outputWidth; ++j) {
|
||||
int x_start = skipLeftCols + j * blockWidth;
|
||||
// 遍历每个块并统计白色像素点的数量
|
||||
for (int i = 0; i < heightBlocks; ++i)
|
||||
{
|
||||
for (int j = 0; j < widthBlocks; ++j)
|
||||
{
|
||||
// 计算块的起始和结束位置
|
||||
int x_start = j * blockWidth;
|
||||
int y_start = i * blockHeight;
|
||||
int x_end = (j == outputWidth - 1) ? (imageWidth - skipRightCols) : (skipLeftCols + (j + 1) * blockWidth);
|
||||
int y_end = (i == outputHeight - 1) ? imageHeight : (i + 1) * blockHeight;
|
||||
int x_end = (j == widthBlocks - 1) ? imageWidth : (j + 1) * blockWidth;
|
||||
int y_end = (i == heightBlocks - 1) ? imageHeight : (i + 1) * blockHeight;
|
||||
|
||||
// 提取当前块
|
||||
cv::Mat block = image(cv::Rect(x_start, y_start, x_end - x_start, y_end - y_start));
|
||||
|
||||
// 统计块中白色像素的数量
|
||||
int whitePixelCount = cv::countNonZero(block);
|
||||
if (whitePixelCount > sizeThreshold) {
|
||||
mask[i][j] = 1;
|
||||
}
|
||||
|
||||
// 如果白色像素数大于阈值,将该块标记为 true
|
||||
if (whitePixelCount > thresholds)
|
||||
{
|
||||
mask[i][j] = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
void max_valves_together_limit(std::vector<std::vector<uint8_t>> &mask_expaned, const int row_threshold)
|
||||
{
|
||||
// 初始化当前回调的1的计数
|
||||
long long count_ones_this_time = 0;
|
||||
|
||||
// 遍历每一行
|
||||
for(auto & row : mask_expaned)
|
||||
{
|
||||
// 计算当前行中1的数量
|
||||
long long row_count = 0;
|
||||
for(uint8_t val : row)
|
||||
{
|
||||
row_count += (val == 1);
|
||||
}
|
||||
|
||||
// 检查是否超过阈值
|
||||
if(row_count > row_threshold)
|
||||
{
|
||||
// 如果超过阈值,将整行置为0
|
||||
std::fill(row.begin(), row.end(), 0);
|
||||
g_camera_error.store(true); // 原子赋值为 true
|
||||
}
|
||||
else
|
||||
{
|
||||
count_ones_this_time += row_count;
|
||||
g_camera_error.store(false); // 原子赋值为 true
|
||||
}
|
||||
}
|
||||
|
||||
// 更新全局的1的计数
|
||||
g_valveActionCount += count_ones_this_time;
|
||||
|
||||
// 如果需要调试打印,可以取消注释以下代码
|
||||
// qDebug() << "This callback1 new triggered bits =" << count_ones_this_time
|
||||
// << ", total=" << g_valveActionCount;
|
||||
}
|
||||
|
||||
bool iniColor()
|
||||
{
|
||||
@ -811,82 +791,62 @@ bool iniColor()
|
||||
|
||||
bool iniOnnx()
|
||||
{
|
||||
|
||||
std::string modelPath = (getConfigDirectory() + "/dimo_369_640.onnx").toStdString();
|
||||
|
||||
runner.load(modelPath);
|
||||
|
||||
// cv::Mat mask;
|
||||
// std::vector<Detection> result = runner.predict(image);
|
||||
// mask = runner.postProcess(result, image);
|
||||
// std::string savepath = "C:/Users/admin/Desktop/config/suspect_mask.png";
|
||||
// cv::imwrite(savepath, mask);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool iniLowMac()
|
||||
{
|
||||
/*--- server socket to faban ---*/
|
||||
if (server_to_lowermachine) {
|
||||
server_to_lowermachine->close(); // 释放之前的 server
|
||||
delete server_to_lowermachine;
|
||||
server_to_lowermachine = nullptr;
|
||||
}
|
||||
|
||||
server_to_lowermachine = new QTcpServer();
|
||||
|
||||
#if(GlobalDebug && DebugLowerMacCOM)
|
||||
qDebug() << "1/4. Build Tcp Server";
|
||||
qDebug()<<"1/4. Build Tcp Server";
|
||||
#endif
|
||||
server_to_lowermachine->listen(QHostAddress::Any, 13452);
|
||||
#if(GlobalDebug && DebugLowerMacCOM)
|
||||
qDebug()<<"2/4. Bind to Port 13452";
|
||||
#endif
|
||||
bool is_timeout;
|
||||
server_to_lowermachine->waitForNewConnection(5000,&is_timeout);
|
||||
#if(GlobalDebug && DebugLowerMacCOM)
|
||||
qDebug()<<"3/4. Try to Establish connect";
|
||||
#endif
|
||||
|
||||
if (!server_to_lowermachine->listen(QHostAddress::Any, 13452)) {
|
||||
qDebug() << "Error: Failed to bind to port 13452. Port may be in use.";
|
||||
delete server_to_lowermachine;
|
||||
server_to_lowermachine = nullptr;
|
||||
return false;
|
||||
if(is_timeout)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if(GlobalDebug && DebugLowerMacCOM)
|
||||
qDebug() << "2/4. Bind to Port 13452";
|
||||
#endif
|
||||
|
||||
bool is_timeout = false;
|
||||
if (!server_to_lowermachine->waitForNewConnection(9000, &is_timeout)) {
|
||||
qDebug() << "3/4. Connection timeout.";
|
||||
server_to_lowermachine->close();
|
||||
delete server_to_lowermachine;
|
||||
server_to_lowermachine = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if(GlobalDebug && DebugLowerMacCOM)
|
||||
qDebug() << "4/4. Connection Established, no timeout";
|
||||
qDebug()<<"4/4. Connection Established no timeout";
|
||||
#endif
|
||||
|
||||
lower_machine = server_to_lowermachine->nextPendingConnection();
|
||||
|
||||
if (!lower_machine) {
|
||||
qDebug() << "Error: No pending connection.";
|
||||
server_to_lowermachine->close();
|
||||
delete server_to_lowermachine;
|
||||
server_to_lowermachine = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if(GlobalDebug && DebugLowerMacCOM)
|
||||
qDebug() << "Lower Machine Connection Succeeded";
|
||||
qDebug()<<"Lower Machine Connection Suecced";
|
||||
#endif
|
||||
|
||||
if (!lower_machine->isWritable()) {
|
||||
qDebug() << "Error: Lower machine is not writable.";
|
||||
lower_machine->close();
|
||||
delete lower_machine;
|
||||
lower_machine = nullptr;
|
||||
return false;
|
||||
if (lower_machine == nullptr || !lower_machine->isWritable()) {
|
||||
cout << "Error: Lower machine is not available or writable." << endl;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
return setLowMacParam();
|
||||
}
|
||||
|
||||
bool setLowMacParam(){
|
||||
try {
|
||||
|
||||
// 计算 Y = 100000000 / X
|
||||
int divide_camera = (file_encoder != 0) ? 100000000 / file_encoder : 0; // 防止除以零的情况
|
||||
int divide_valve = (file_valve != 0) ? 100000000 / file_valve : 0; // 防止除以零的情况
|
||||
|
||||
|
||||
// 将参数转换为长度为8的字符串,前面补0
|
||||
QString delay_time = QString("%1").arg(file_delay, 8, 10, QChar('0'));
|
||||
QString divide_parameter = QString("%1").arg(divide_camera, 8, 10, QChar('0'));
|
||||
@ -914,7 +874,6 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)delay_buf, len_delay + 8);
|
||||
qDebug() << "彩色相机延迟时间:" << delay_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for delay parameter." << endl;
|
||||
}
|
||||
@ -934,7 +893,6 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)divide_buf, len_divide + 8);
|
||||
qDebug() << "彩色相机分频系数:" << divide_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for encoder parameter." << endl;
|
||||
}
|
||||
@ -952,14 +910,24 @@ bool setLowMacParam(){
|
||||
valve_divide_buf[len_sv + 6] = 0xFF;
|
||||
valve_divide_buf[len_sv + 7] = 0xBB;
|
||||
|
||||
qDebug()<<"相机参数"<<divide_byte.data();
|
||||
qDebug()<<"阀门参数"<<sv_byte.data();
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)valve_divide_buf, len_sv + 8);
|
||||
qDebug() << "阀门分频系数:" << sv_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for valve parameter." << endl;
|
||||
}
|
||||
delete[] valve_divide_buf;
|
||||
|
||||
|
||||
// //下位机参数
|
||||
// int lowmac_dp = 400; //偏振延迟时间
|
||||
// int lowmac_sm = 5; //吹气量
|
||||
// int lowmac_ts = 15; //模板匹配阈值
|
||||
// int lowmac_sg = 80; //偏振绿色通道大小阈值
|
||||
// int lowmac_td = 10; //偏振红色通道差值
|
||||
//新增下位机协议
|
||||
// 将参数转换为长度为8的字符串,前面补0
|
||||
QString dp = QString("%1").arg(lowmac_dp, 8, 10, QChar('0'));
|
||||
QString sm = QString("%1").arg(lowmac_sm, 8, 10, QChar('0'));
|
||||
@ -979,7 +947,6 @@ bool setLowMacParam(){
|
||||
QByteArray sg_byte = sg.toLatin1();
|
||||
QByteArray td_byte = td.toLatin1();
|
||||
|
||||
//偏振延迟时间
|
||||
uint8_t* dp_buf = new uint8_t[len_dp + 8];
|
||||
dp_buf[0] = 0xAA;
|
||||
dp_buf[1] = 0x00;
|
||||
@ -993,13 +960,11 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)dp_buf, len_dp + 8);
|
||||
qDebug() << "偏振延迟时间: " << dp_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for dp parameter." << endl;
|
||||
}
|
||||
delete[] dp_buf;
|
||||
|
||||
// 吹气量
|
||||
uint8_t* sm_buf = new uint8_t[len_sm + 8];
|
||||
sm_buf[0] = 0xAA;
|
||||
sm_buf[1] = 0x00;
|
||||
@ -1013,13 +978,11 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)sm_buf, len_sm + 8);
|
||||
qDebug() << "吹气量: " << sm_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for sm parameter." << endl;
|
||||
}
|
||||
delete[] sm_buf;
|
||||
|
||||
// 模板匹配阈值
|
||||
uint8_t* ts_buf = new uint8_t[len_ts + 8];
|
||||
ts_buf[0] = 0xAA;
|
||||
ts_buf[1] = 0x00;
|
||||
@ -1033,13 +996,11 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)ts_buf, len_ts + 8);
|
||||
qDebug() << "模板匹配阈值: " << ts_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for ts parameter." << endl;
|
||||
}
|
||||
delete[] ts_buf;
|
||||
|
||||
// 偏振绿色通道大小阈值
|
||||
uint8_t* sg_buf = new uint8_t[len_sg + 8];
|
||||
sg_buf[0] = 0xAA;
|
||||
sg_buf[1] = 0x00;
|
||||
@ -1053,13 +1014,11 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)sg_buf, len_sg + 8);
|
||||
qDebug() << "偏振绿色通道大小阈值: " << sg_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for sg parameter." << endl;
|
||||
}
|
||||
delete[] sg_buf;
|
||||
|
||||
// 偏振红色通道差值
|
||||
uint8_t* td_buf = new uint8_t[len_td + 8];
|
||||
td_buf[0] = 0xAA;
|
||||
td_buf[1] = 0x00;
|
||||
@ -1073,20 +1032,19 @@ bool setLowMacParam(){
|
||||
|
||||
if (lower_machine->isWritable()) {
|
||||
lower_machine->write((const char*)td_buf, len_td + 8);
|
||||
qDebug() << "偏振红色通道差值: " << td_byte.data();
|
||||
} else {
|
||||
cout << "Error: Unable to write to lower machine for td parameter." << endl;
|
||||
}
|
||||
delete[] td_buf;
|
||||
} catch (...) {
|
||||
qWarning() << "Set lower machine parameters failed!!!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool DestoryLowMac()
|
||||
{
|
||||
MdigProcess(MilDigitizer0, MilGrabBufferList0, 20, M_STOP, M_DEFAULT,ProcessingFunction0, M_NULL);
|
||||
MdigProcess(MilDigitizer1, MilGrabBufferList1, 20, M_STOP, M_DEFAULT,ProcessingFunction1, M_NULL);
|
||||
|
||||
// 构建停止命令
|
||||
uint8_t stop_command[9] = {0};
|
||||
stop_command[0] = 0xAA; // 起始标志
|
||||
@ -1109,13 +1067,13 @@ bool DestoryLowMac()
|
||||
is_running = false;
|
||||
}
|
||||
|
||||
|
||||
bool get_valve_data(std::vector<std::vector<uint8_t>> mask)
|
||||
{
|
||||
if (mask[0].size() % 8 != 0) {
|
||||
std::cerr << "Error: mask 的第 0 行的列数应该为 8 的倍数。" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* mask_buf = new uint8_t[4096 + 8]; // 创建缓冲区,大小为3072 + 8
|
||||
mask_buf[0] = 0xAA; // 起始标志
|
||||
mask_buf[1] = 0x10; // 高位数据长度 (352 字节 -> 0x0160)
|
||||
@ -1168,40 +1126,21 @@ bool get_valve_data(std::vector<std::vector<uint8_t>> mask)
|
||||
else
|
||||
{
|
||||
std::cout << "*** lower machine connect failed! *** " << std::endl;
|
||||
delete[] mask_buf; // 释放内存
|
||||
return false;
|
||||
// ui->lab_lowermachine_isconnect->setStyleSheet("QLabel{background-color: rgb(237, 212, 0);}"); // 显示连接失败
|
||||
// ui->lab_lowermachine_isconnect->repaint(); // 强制刷新UI
|
||||
}
|
||||
|
||||
delete[] mask_buf; // 释放内存
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_grab()
|
||||
|
||||
void Start_camera()
|
||||
{
|
||||
try
|
||||
{
|
||||
MdigProcess(MilDigitizer0, MilGrabBufferList0, 20, M_START, M_DEFAULT,ProcessingFunction0, M_NULL);
|
||||
MdigProcess(MilDigitizer1, MilGrabBufferList1, 20, M_START, M_DEFAULT,ProcessingFunction1, M_NULL);
|
||||
} catch (...) {
|
||||
qWarning() << "Start Grabber Failed!!!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stop_grab()
|
||||
{ try {
|
||||
MdigProcess(MilDigitizer0, MilGrabBufferList0, 20, M_STOP, M_DEFAULT,ProcessingFunction0, M_NULL);
|
||||
MdigProcess(MilDigitizer1, MilGrabBufferList1, 20, M_STOP, M_DEFAULT,ProcessingFunction1, M_NULL);
|
||||
} catch (...) {
|
||||
qWarning() << "Stop Grabber Failed!!!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void start_camera()
|
||||
{
|
||||
start_grab();
|
||||
// 发送开始命令
|
||||
uint8_t start_command[9] = {0};
|
||||
start_command[0] = 0xAA;
|
||||
@ -1217,7 +1156,7 @@ void start_camera()
|
||||
if (lower_machine != nullptr && lower_machine->isWritable())
|
||||
{
|
||||
lower_machine->write((const char*)start_command, 9);
|
||||
qDebug()<<"发送相机启动成功";
|
||||
qDebug()<<"发送相机参数成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1226,6 +1165,7 @@ void start_camera()
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<std::vector<uint8_t> > expandArray(const std::vector<std::vector<uint8_t> > &array, int newCols)
|
||||
{
|
||||
int rows = array.size();
|
||||
|
||||
20
camera.h
20
camera.h
@ -11,7 +11,6 @@
|
||||
#include <string>
|
||||
#include <future>
|
||||
|
||||
#include <QTimer>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
@ -24,18 +23,13 @@
|
||||
#include <QTcpServer>
|
||||
#include "globals.h"
|
||||
#include "img_utils.h"
|
||||
#include "color_algorithms.h"
|
||||
#include "color_range.h"
|
||||
|
||||
extern MIL_ID MilApplication;
|
||||
extern MIL_ID MilSystem;
|
||||
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds);
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image,
|
||||
int widthBlocks,
|
||||
int heightBlocks,
|
||||
int thresholds = 10,
|
||||
int skipLeftCols = 0,
|
||||
int skipRightCols = 0);
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds);
|
||||
|
||||
|
||||
void PadColumns(std::vector<std::vector<uint8_t>>& data, int pad_left, int pad_right, uint8_t fill_value );
|
||||
@ -73,18 +67,12 @@ bool iniColor();
|
||||
|
||||
bool iniOnnx();
|
||||
|
||||
void start_camera();
|
||||
|
||||
bool setLowMacParam();
|
||||
void Start_camera();
|
||||
|
||||
bool DestoryCamera();
|
||||
|
||||
bool DestoryLowMac();
|
||||
|
||||
bool start_grab();
|
||||
|
||||
bool stop_grab();
|
||||
|
||||
extern int SaveImg_Flag;
|
||||
|
||||
MIL_INT MFTYPE ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void* HookDataPtr);
|
||||
@ -132,6 +120,4 @@ extern bool volatile is_running;
|
||||
|
||||
bool get_valve_data(std::vector<std::vector<uint8_t>> mask );
|
||||
|
||||
void max_valves_together_limit(std::vector<std::vector<uint8_t>> &mask_expaned, const int row_threshold);
|
||||
|
||||
#endif // CAMERA_H
|
||||
|
||||
@ -5,55 +5,29 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
CONFIG += c++17
|
||||
CONFIG += console
|
||||
|
||||
DEFINES += WIN32_LEAN_AND_MEAN
|
||||
DEFINES += _WINSOCKAPI_
|
||||
|
||||
# You can make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
countdown_dialog.cpp \
|
||||
libmodbus/modbus-data.c \
|
||||
libmodbus/modbus-rtu.c \
|
||||
libmodbus/modbus-tcp.c \
|
||||
libmodbus/modbus.c \
|
||||
camera.cpp \
|
||||
color_algorithms.cpp \
|
||||
detection_worker.cpp \
|
||||
color_range.cpp \
|
||||
detectionworker.cpp \
|
||||
globals.cpp \
|
||||
img_utils.cpp \
|
||||
license_dialog.cpp \
|
||||
license_dialog.cpp \
|
||||
licesing.cpp \
|
||||
lower_machine.cpp \
|
||||
main.cpp \
|
||||
onnxrunner.cpp \
|
||||
plc_connector.cpp \
|
||||
storage_worker.cpp \
|
||||
storageworker.cpp \
|
||||
widget.cpp
|
||||
|
||||
HEADERS += \
|
||||
countdown_dialog.h \
|
||||
libmodbus/modbus-version.h \
|
||||
libmodbus/modbus.h \
|
||||
libmodbus/modbus-private.h \
|
||||
libmodbus/modbus-tcp.h \
|
||||
libmodbus/modbus-tcp-private.h \
|
||||
libmodbus/modbus-rtu.h \
|
||||
libmodbus/modbus-rtu-private.h \
|
||||
camera.h \
|
||||
color_algorithms.h \
|
||||
detection_worker.h \
|
||||
color_range.h \
|
||||
detectionworker.h \
|
||||
globals.h \
|
||||
img_utils.h \
|
||||
license_dialog.h \
|
||||
license_dialog.h \
|
||||
licesing.h \
|
||||
lower_machine.h \
|
||||
onnxrunner.h \
|
||||
plc_connector.h \
|
||||
storage_worker.h \
|
||||
storageworker.h \
|
||||
widget.h
|
||||
|
||||
FORMS += \
|
||||
@ -69,7 +43,8 @@ DEPENDPATH += $${PWD}/Include
|
||||
LIBS += -L$${PWD}/LIB -lmil
|
||||
LIBS += -L$${PWD}/LIB -lMilim
|
||||
LIBS += -L$${PWD}/LIB -lmilblob
|
||||
# LIBS += -Ldll -lws2_32
|
||||
|
||||
|
||||
|
||||
LIBS += \
|
||||
# $${PWD}/opencv410-vs22/x64/vc17/lib/*.lib
|
||||
@ -78,10 +53,3 @@ LIBS += \
|
||||
INCLUDEPATH += \
|
||||
# $${PWD}/opencv410-vs22/include
|
||||
$${PWD}/opencv/build/include
|
||||
|
||||
# 指定库目录
|
||||
LIBS += "$$PWD/libsodium/x64/Release/v143/static/libsodium.lib"
|
||||
DEFINES += SODIUM_STATIC
|
||||
INCLUDEPATH += $${PWD}/libsodium/include
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 15.0.0, 2025-01-16T12:30:28. -->
|
||||
<!-- Written by QtCreator 15.0.0, 2025-01-02T20:20:23. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// detection_worker.cpp
|
||||
#include "detection_worker.h"
|
||||
#include "detectionworker.h"
|
||||
#include "globals.h"
|
||||
#include <QDebug>
|
||||
#include "onnxrunner.h"
|
||||
42
dist/config/color_range_config.txt
vendored
42
dist/config/color_range_config.txt
vendored
@ -1,3 +1,4 @@
|
||||
# Green color parameters
|
||||
green_L_min = 16
|
||||
green_L_max = 56
|
||||
green_a_min = -33
|
||||
@ -5,6 +6,7 @@ green_a_max = -11
|
||||
green_b_min = -7
|
||||
green_b_max = 24
|
||||
|
||||
# Blue color parameters
|
||||
blue_L_min = 20
|
||||
blue_L_max = 43
|
||||
blue_a_min = -13
|
||||
@ -12,13 +14,15 @@ blue_a_max = 22
|
||||
blue_b_min = -48
|
||||
blue_b_max = -8
|
||||
|
||||
orange_L_min = 63
|
||||
orange_L_max = 78
|
||||
orange_a_min = 7
|
||||
orange_a_max = 14
|
||||
orange_b_min = 23
|
||||
orange_b_max = 47
|
||||
# Orange color parameters
|
||||
orange_L_min = 60
|
||||
orange_L_max = 60
|
||||
orange_a_min = 6
|
||||
orange_a_max = 6
|
||||
orange_b_min = 20
|
||||
orange_b_max = 46
|
||||
|
||||
# Black color parameters
|
||||
black_L_min = 0
|
||||
black_L_max = 8
|
||||
black_a_min = -4
|
||||
@ -26,6 +30,7 @@ black_a_max = 2
|
||||
black_b_min = -3
|
||||
black_b_max = 4
|
||||
|
||||
# Red color parameters
|
||||
red_L_min = 23
|
||||
red_L_max = 48
|
||||
red_a_min = 12
|
||||
@ -33,6 +38,7 @@ red_a_max = 55
|
||||
red_b_min = -80
|
||||
red_b_max = 37
|
||||
|
||||
# Purple color parameters
|
||||
purple_L_min = 38
|
||||
purple_L_max = 54
|
||||
purple_a_min = 10
|
||||
@ -40,27 +46,7 @@ purple_a_max = 20
|
||||
purple_b_min = -45
|
||||
purple_b_max = 1
|
||||
|
||||
yellow_L_min = 45
|
||||
yellow_L_max = 56
|
||||
yellow_a_min = -4
|
||||
yellow_a_max = 7
|
||||
yellow_b_min = 20
|
||||
yellow_b_max = 21
|
||||
|
||||
expansionRaidus = 1
|
||||
file_delay = 1180
|
||||
# Other parameters
|
||||
lab_denoising = 1
|
||||
lowmac_dp = 350
|
||||
lowmac_sg = 70
|
||||
lowmac_sm = 1200
|
||||
lowmac_td = 7
|
||||
lowmac_ts = 10
|
||||
machine_num = 0
|
||||
max_valves_together = 18
|
||||
saturation_denoising = 1
|
||||
saturation_threshold = 165
|
||||
screen_left_0 = 0
|
||||
screen_left_1 = 0
|
||||
screen_right_0 = 10
|
||||
screen_right_1 = 0
|
||||
sizeThreshold = 4
|
||||
saturation_denoising = 1
|
||||
|
||||
2
dist/license.txt
vendored
2
dist/license.txt
vendored
@ -61,7 +61,7 @@
|
||||
1. **Software Provided “As Is”**
|
||||
The Software and any related services are provided on an “as is” basis. The Licensor makes no express or implied warranties regarding the performance, quality, compatibility, or suitability of the Software.
|
||||
2. **Assumption of Risk**
|
||||
The User understands and agrees that any risks or losses arising from the use of or inability to use the Software are borne by the User. The Licensor shall not be liable for any direct or indirect losses arising therefrom. And the Licensor shall agree that NC is NC.
|
||||
The User understands and agrees that any risks or losses arising from the use of or inability to use the Software are borne by the User. The Licensor shall not be liable for any direct or indirect losses arising therefrom.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -3,9 +3,6 @@
|
||||
|
||||
// camera.cpp 顶部或 globals.cpp 中
|
||||
long long g_valveActionCount = 0;
|
||||
std::atomic<bool> g_camera_error(false);
|
||||
|
||||
std::atomic<bool> g_lower_machine_connected(false);
|
||||
|
||||
// 初始化图片显示互斥锁和MIL_ID
|
||||
QMutex gDispPicMutex0;
|
||||
@ -46,8 +43,6 @@ std::atomic<bool>* g_recognitionRunning[2] = { nullptr, nullptr };
|
||||
bool g_dl_enable[2] = { true, true };
|
||||
bool g_traditional_enable[2] = { true, true };
|
||||
|
||||
int sizeThreshold = 4; // 转化为喷阀的每块要求像素个数
|
||||
int expansionRaidus = 1; // 获取mask后进行左右位置的扩展
|
||||
|
||||
// 初始化全局ONNXRunner实例数组
|
||||
ONNXRunner* g_runner_array[2] = { nullptr, nullptr };
|
||||
|
||||
@ -16,10 +16,7 @@
|
||||
#include <atomic>
|
||||
#include "onnxrunner.h"
|
||||
|
||||
// 计数喷阀次数
|
||||
extern long long g_valveActionCount;
|
||||
extern std::atomic<bool> g_camera_error;
|
||||
extern std::atomic<bool> g_lower_machine_connected;
|
||||
|
||||
// 图片显示0
|
||||
extern QMutex gDispPicMutex0;
|
||||
@ -42,9 +39,6 @@ extern QSemaphore detection_ready;
|
||||
extern bool g_dl_enable[2];
|
||||
extern bool g_traditional_enable[2];
|
||||
|
||||
extern int sizeThreshold; // 转化为喷阀的每块要求像素个数
|
||||
extern int expansionRaidus;
|
||||
|
||||
// 获取保存目录和配置目录函数
|
||||
QString getSaveDirectory();
|
||||
QString getConfigDirectory();
|
||||
|
||||
@ -1,233 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2010-2014 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
# include <stdint.h>
|
||||
#else
|
||||
# include "stdint.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <winsock2.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
//#include <config.h>
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
# include <byteswap.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <libkern/OSByteOrder.h>
|
||||
# define bswap_16 OSSwapInt16
|
||||
# define bswap_32 OSSwapInt32
|
||||
# define bswap_64 OSSwapInt64
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10)
|
||||
# if GCC_VERSION >= 430
|
||||
// Since GCC >= 4.30, GCC provides __builtin_bswapXX() alternatives so we switch to them
|
||||
# undef bswap_32
|
||||
# define bswap_32 __builtin_bswap32
|
||||
# endif
|
||||
# if GCC_VERSION >= 480
|
||||
# undef bswap_16
|
||||
# define bswap_16 __builtin_bswap16
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
# define bswap_32 _byteswap_ulong
|
||||
# define bswap_16 _byteswap_ushort
|
||||
#endif
|
||||
|
||||
#if !defined(bswap_16)
|
||||
# warning "Fallback on C functions for bswap_16"
|
||||
static inline uint16_t bswap_16(uint16_t x)
|
||||
{
|
||||
return (x >> 8) | (x << 8);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(bswap_32)
|
||||
# warning "Fallback on C functions for bswap_32"
|
||||
static inline uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
return (bswap_16(x & 0xffff) << 16) | (bswap_16(x >> 16));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Sets many bits from a single byte value (all 8 bits of the byte value are
|
||||
set) */
|
||||
void modbus_set_bits_from_byte(uint8_t *dest, int idx, const uint8_t value)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < 8; i++) {
|
||||
dest[idx+i] = (value & (1 << i)) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sets many bits from a table of bytes (only the bits between idx and
|
||||
idx + nb_bits are set) */
|
||||
void modbus_set_bits_from_bytes(uint8_t *dest, int idx, unsigned int nb_bits,
|
||||
const uint8_t *tab_byte)
|
||||
{
|
||||
unsigned int i;
|
||||
int shift = 0;
|
||||
|
||||
for (i = idx; i < idx + nb_bits; i++) {
|
||||
dest[i] = tab_byte[(i - idx) / 8] & (1 << shift) ? 1 : 0;
|
||||
/* gcc doesn't like: shift = (++shift) % 8; */
|
||||
shift++;
|
||||
shift %= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/* Gets the byte value from many bits.
|
||||
To obtain a full byte, set nb_bits to 8. */
|
||||
uint8_t modbus_get_byte_from_bits(const uint8_t *src, int idx,
|
||||
unsigned int nb_bits)
|
||||
{
|
||||
unsigned int i;
|
||||
uint8_t value = 0;
|
||||
|
||||
if (nb_bits > 8) {
|
||||
/* Assert is ignored if NDEBUG is set */
|
||||
assert(nb_bits < 8);
|
||||
nb_bits = 8;
|
||||
}
|
||||
|
||||
for (i=0; i < nb_bits; i++) {
|
||||
value |= (src[idx+i] << i);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Get a float from 4 bytes (Modbus) without any conversion (ABCD) */
|
||||
float modbus_get_float_abcd(const uint16_t *src)
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
|
||||
i = ntohl(((uint32_t)src[0] << 16) + src[1]);
|
||||
memcpy(&f, &i, sizeof(float));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* Get a float from 4 bytes (Modbus) in inversed format (DCBA) */
|
||||
float modbus_get_float_dcba(const uint16_t *src)
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
|
||||
i = ntohl(bswap_32((((uint32_t)src[0]) << 16) + src[1]));
|
||||
memcpy(&f, &i, sizeof(float));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* Get a float from 4 bytes (Modbus) with swapped bytes (BADC) */
|
||||
float modbus_get_float_badc(const uint16_t *src)
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
|
||||
i = ntohl((uint32_t)(bswap_16(src[0]) << 16) + bswap_16(src[1]));
|
||||
memcpy(&f, &i, sizeof(float));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* Get a float from 4 bytes (Modbus) with swapped words (CDAB) */
|
||||
float modbus_get_float_cdab(const uint16_t *src)
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
|
||||
i = ntohl((((uint32_t)src[1]) << 16) + src[0]);
|
||||
memcpy(&f, &i, sizeof(float));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* DEPRECATED - Get a float from 4 bytes in sort of Modbus format */
|
||||
float modbus_get_float(const uint16_t *src)
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
|
||||
i = (((uint32_t)src[1]) << 16) + src[0];
|
||||
memcpy(&f, &i, sizeof(float));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* Set a float to 4 bytes for Modbus w/o any conversion (ABCD) */
|
||||
void modbus_set_float_abcd(float f, uint16_t *dest)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
memcpy(&i, &f, sizeof(uint32_t));
|
||||
i = htonl(i);
|
||||
dest[0] = (uint16_t)(i >> 16);
|
||||
dest[1] = (uint16_t)i;
|
||||
}
|
||||
|
||||
/* Set a float to 4 bytes for Modbus with byte and word swap conversion (DCBA) */
|
||||
void modbus_set_float_dcba(float f, uint16_t *dest)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
memcpy(&i, &f, sizeof(uint32_t));
|
||||
i = bswap_32(htonl(i));
|
||||
dest[0] = (uint16_t)(i >> 16);
|
||||
dest[1] = (uint16_t)i;
|
||||
}
|
||||
|
||||
/* Set a float to 4 bytes for Modbus with byte swap conversion (BADC) */
|
||||
void modbus_set_float_badc(float f, uint16_t *dest)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
memcpy(&i, &f, sizeof(uint32_t));
|
||||
i = htonl(i);
|
||||
dest[0] = (uint16_t)bswap_16(i >> 16);
|
||||
dest[1] = (uint16_t)bswap_16(i & 0xFFFF);
|
||||
}
|
||||
|
||||
/* Set a float to 4 bytes for Modbus with word swap conversion (CDAB) */
|
||||
void modbus_set_float_cdab(float f, uint16_t *dest)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
memcpy(&i, &f, sizeof(uint32_t));
|
||||
i = htonl(i);
|
||||
dest[0] = (uint16_t)i;
|
||||
dest[1] = (uint16_t)(i >> 16);
|
||||
}
|
||||
|
||||
/* DEPRECATED - Set a float to 4 bytes in a sort of Modbus format! */
|
||||
void modbus_set_float(float f, uint16_t *dest)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
memcpy(&i, &f, sizeof(uint32_t));
|
||||
dest[0] = (uint16_t)i;
|
||||
dest[1] = (uint16_t)(i >> 16);
|
||||
}
|
||||
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2010-2012 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_PRIVATE_H
|
||||
#define MODBUS_PRIVATE_H
|
||||
|
||||
#ifndef _MSC_VER
|
||||
# include <stdint.h>
|
||||
# include <sys/time.h>
|
||||
#else
|
||||
# include "stdint.h"
|
||||
# include <time.h>
|
||||
typedef int ssize_t;
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
//#include <config.h>
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
MODBUS_BEGIN_DECLS
|
||||
|
||||
/* It's not really the minimal length (the real one is report slave ID
|
||||
* in RTU (4 bytes)) but it's a convenient size to use in RTU or TCP
|
||||
* communications to read many values or write a single one.
|
||||
* Maximum between :
|
||||
* - HEADER_LENGTH_TCP (7) + function (1) + address (2) + number (2)
|
||||
* - HEADER_LENGTH_RTU (1) + function (1) + address (2) + number (2) + CRC (2)
|
||||
*/
|
||||
#define _MIN_REQ_LENGTH 12
|
||||
|
||||
#define _REPORT_SLAVE_ID 180
|
||||
|
||||
#define _MODBUS_EXCEPTION_RSP_LENGTH 5
|
||||
|
||||
/* Timeouts in microsecond (0.5 s) */
|
||||
#define _RESPONSE_TIMEOUT 500000
|
||||
#define _BYTE_TIMEOUT 500000
|
||||
|
||||
typedef enum {
|
||||
_MODBUS_BACKEND_TYPE_RTU=0,
|
||||
_MODBUS_BACKEND_TYPE_TCP
|
||||
} modbus_backend_type_t;
|
||||
|
||||
/*
|
||||
* ---------- Request Indication ----------
|
||||
* | Client | ---------------------->| Server |
|
||||
* ---------- Confirmation Response ----------
|
||||
*/
|
||||
typedef enum {
|
||||
/* Request message on the server side */
|
||||
MSG_INDICATION,
|
||||
/* Request message on the client side */
|
||||
MSG_CONFIRMATION
|
||||
} msg_type_t;
|
||||
|
||||
/* This structure reduces the number of params in functions and so
|
||||
* optimizes the speed of execution (~ 37%). */
|
||||
typedef struct _sft {
|
||||
int slave;
|
||||
int function;
|
||||
int t_id;
|
||||
} sft_t;
|
||||
|
||||
typedef struct _modbus_backend {
|
||||
unsigned int backend_type;
|
||||
unsigned int header_length;
|
||||
unsigned int checksum_length;
|
||||
unsigned int max_adu_length;
|
||||
int (*set_slave) (modbus_t *ctx, int slave);
|
||||
int (*build_request_basis) (modbus_t *ctx, int function, int addr,
|
||||
int nb, uint8_t *req);
|
||||
int (*build_response_basis) (sft_t *sft, uint8_t *rsp);
|
||||
int (*prepare_response_tid) (const uint8_t *req, int *req_length);
|
||||
int (*send_msg_pre) (uint8_t *req, int req_length);
|
||||
ssize_t (*send) (modbus_t *ctx, const uint8_t *req, int req_length);
|
||||
int (*receive) (modbus_t *ctx, uint8_t *req);
|
||||
ssize_t (*recv) (modbus_t *ctx, uint8_t *rsp, int rsp_length);
|
||||
int (*check_integrity) (modbus_t *ctx, uint8_t *msg,
|
||||
const int msg_length);
|
||||
int (*pre_check_confirmation) (modbus_t *ctx, const uint8_t *req,
|
||||
const uint8_t *rsp, int rsp_length);
|
||||
int (*connect) (modbus_t *ctx);
|
||||
void (*close) (modbus_t *ctx);
|
||||
int (*flush) (modbus_t *ctx);
|
||||
int (*select) (modbus_t *ctx, fd_set *rset, struct timeval *tv, int msg_length);
|
||||
void (*free) (modbus_t *ctx);
|
||||
} modbus_backend_t;
|
||||
|
||||
struct _modbus {
|
||||
/* Slave address */
|
||||
int slave;
|
||||
/* Socket or file descriptor */
|
||||
int s;
|
||||
int debug;
|
||||
int error_recovery;
|
||||
struct timeval response_timeout;
|
||||
struct timeval byte_timeout;
|
||||
struct timeval indication_timeout;
|
||||
const modbus_backend_t *backend;
|
||||
void *backend_data;
|
||||
};
|
||||
|
||||
void _modbus_init_common(modbus_t *ctx);
|
||||
void _error_print(modbus_t *ctx, const char *context);
|
||||
int _modbus_receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
size_t strlcpy(char *dest, const char *src, size_t dest_size);
|
||||
#endif
|
||||
|
||||
MODBUS_END_DECLS
|
||||
|
||||
#endif /* MODBUS_PRIVATE_H */
|
||||
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2001-2011 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_RTU_PRIVATE_H
|
||||
#define MODBUS_RTU_PRIVATE_H
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
#define _MODBUS_RTU_HEADER_LENGTH 1
|
||||
#define _MODBUS_RTU_PRESET_REQ_LENGTH 6
|
||||
#define _MODBUS_RTU_PRESET_RSP_LENGTH 2
|
||||
|
||||
#define _MODBUS_RTU_CHECKSUM_LENGTH 2
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if !defined(ENOTSUP)
|
||||
#define ENOTSUP WSAEOPNOTSUPP
|
||||
#endif
|
||||
|
||||
/* WIN32: struct containing serial handle and a receive buffer */
|
||||
#define PY_BUF_SIZE 512
|
||||
struct win32_ser {
|
||||
/* File handle */
|
||||
HANDLE fd;
|
||||
/* Receive buffer */
|
||||
uint8_t buf[PY_BUF_SIZE];
|
||||
/* Received chars */
|
||||
DWORD n_bytes;
|
||||
};
|
||||
#endif /* _WIN32 */
|
||||
|
||||
typedef struct _modbus_rtu {
|
||||
/* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X. */
|
||||
char *device;
|
||||
/* Bauds: 9600, 19200, 57600, 115200, etc */
|
||||
int baud;
|
||||
/* Data bit */
|
||||
uint8_t data_bit;
|
||||
/* Stop bit */
|
||||
uint8_t stop_bit;
|
||||
/* Parity: 'N', 'O', 'E' */
|
||||
char parity;
|
||||
#if defined(_WIN32)
|
||||
struct win32_ser w_ser;
|
||||
DCB old_dcb;
|
||||
#else
|
||||
/* Save old termios settings */
|
||||
struct termios old_tios;
|
||||
#endif
|
||||
#if HAVE_DECL_TIOCSRS485
|
||||
int serial_mode;
|
||||
#endif
|
||||
#if HAVE_DECL_TIOCM_RTS
|
||||
int rts;
|
||||
int rts_delay;
|
||||
int onebyte_time;
|
||||
void (*set_rts) (modbus_t *ctx, int on);
|
||||
#endif
|
||||
/* To handle many slaves on the same link */
|
||||
int confirmation_to_ignore;
|
||||
} modbus_rtu_t;
|
||||
|
||||
#endif /* MODBUS_RTU_PRIVATE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2001-2011 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_RTU_H
|
||||
#define MODBUS_RTU_H
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
MODBUS_BEGIN_DECLS
|
||||
|
||||
/* Modbus_Application_Protocol_V1_1b.pdf Chapter 4 Section 1 Page 5
|
||||
* RS232 / RS485 ADU = 253 bytes + slave (1 byte) + CRC (2 bytes) = 256 bytes
|
||||
*/
|
||||
#define MODBUS_RTU_MAX_ADU_LENGTH 256
|
||||
|
||||
MODBUS_API modbus_t* modbus_new_rtu(const char *device, int baud, char parity,
|
||||
int data_bit, int stop_bit);
|
||||
|
||||
#define MODBUS_RTU_RS232 0
|
||||
#define MODBUS_RTU_RS485 1
|
||||
|
||||
MODBUS_API int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode);
|
||||
MODBUS_API int modbus_rtu_get_serial_mode(modbus_t *ctx);
|
||||
|
||||
#define MODBUS_RTU_RTS_NONE 0
|
||||
#define MODBUS_RTU_RTS_UP 1
|
||||
#define MODBUS_RTU_RTS_DOWN 2
|
||||
|
||||
MODBUS_API int modbus_rtu_set_rts(modbus_t *ctx, int mode);
|
||||
MODBUS_API int modbus_rtu_get_rts(modbus_t *ctx);
|
||||
|
||||
MODBUS_API int modbus_rtu_set_custom_rts(modbus_t *ctx, void (*set_rts) (modbus_t *ctx, int on));
|
||||
|
||||
MODBUS_API int modbus_rtu_set_rts_delay(modbus_t *ctx, int us);
|
||||
MODBUS_API int modbus_rtu_get_rts_delay(modbus_t *ctx);
|
||||
|
||||
MODBUS_END_DECLS
|
||||
|
||||
#endif /* MODBUS_RTU_H */
|
||||
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2001-2011 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_TCP_PRIVATE_H
|
||||
#define MODBUS_TCP_PRIVATE_H
|
||||
|
||||
#define _MODBUS_TCP_HEADER_LENGTH 7
|
||||
#define _MODBUS_TCP_PRESET_REQ_LENGTH 12
|
||||
#define _MODBUS_TCP_PRESET_RSP_LENGTH 8
|
||||
|
||||
#define _MODBUS_TCP_CHECKSUM_LENGTH 0
|
||||
|
||||
/* In both structures, the transaction ID must be placed on first position
|
||||
to have a quick access not dependant of the TCP backend */
|
||||
typedef struct _modbus_tcp {
|
||||
/* Extract from MODBUS Messaging on TCP/IP Implementation Guide V1.0b
|
||||
(page 23/46):
|
||||
The transaction identifier is used to associate the future response
|
||||
with the request. This identifier is unique on each TCP connection. */
|
||||
uint16_t t_id;
|
||||
/* TCP port */
|
||||
int port;
|
||||
/* IP address */
|
||||
char ip[16];
|
||||
} modbus_tcp_t;
|
||||
|
||||
#define _MODBUS_TCP_PI_NODE_LENGTH 1025
|
||||
#define _MODBUS_TCP_PI_SERVICE_LENGTH 32
|
||||
|
||||
typedef struct _modbus_tcp_pi {
|
||||
/* Transaction ID */
|
||||
uint16_t t_id;
|
||||
/* TCP port */
|
||||
int port;
|
||||
/* Node */
|
||||
char node[_MODBUS_TCP_PI_NODE_LENGTH];
|
||||
/* Service */
|
||||
char service[_MODBUS_TCP_PI_SERVICE_LENGTH];
|
||||
} modbus_tcp_pi_t;
|
||||
|
||||
#endif /* MODBUS_TCP_PRIVATE_H */
|
||||
@ -1,929 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2001-2013 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define OS_WIN32
|
||||
/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
|
||||
* minwg32 headers check WINVER before allowing the use of these */
|
||||
# ifndef WINVER
|
||||
# define WINVER 0x0501
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* Already set in modbus-tcp.h but it seems order matters in VS2005 */
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
# define SHUT_RDWR 2
|
||||
# define close closesocket
|
||||
#else
|
||||
# include <sys/socket.h>
|
||||
# include <sys/ioctl.h>
|
||||
|
||||
#if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ < 5)
|
||||
# define OS_BSD
|
||||
# include <netinet/in_systm.h>
|
||||
#endif
|
||||
|
||||
# include <netinet/in.h>
|
||||
# include <netinet/ip.h>
|
||||
# include <netinet/tcp.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
#if !defined(MSG_NOSIGNAL)
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
#if defined(_AIX) && !defined(MSG_DONTWAIT)
|
||||
#define MSG_DONTWAIT MSG_NONBLOCK
|
||||
#endif
|
||||
|
||||
#include "modbus-private.h"
|
||||
|
||||
#include "modbus-tcp.h"
|
||||
#include "modbus-tcp-private.h"
|
||||
|
||||
#ifdef OS_WIN32
|
||||
static int _modbus_tcp_init_win32(void)
|
||||
{
|
||||
/* Initialise Windows Socket API */
|
||||
WSADATA wsaData;
|
||||
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
fprintf(stderr, "WSAStartup() returned error code %d\n",
|
||||
(unsigned int)GetLastError());
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int _modbus_set_slave(modbus_t *ctx, int slave)
|
||||
{
|
||||
/* Broadcast address is 0 (MODBUS_BROADCAST_ADDRESS) */
|
||||
if (slave >= 0 && slave <= 247) {
|
||||
ctx->slave = slave;
|
||||
} else if (slave == MODBUS_TCP_SLAVE) {
|
||||
/* The special value MODBUS_TCP_SLAVE (0xFF) can be used in TCP mode to
|
||||
* restore the default value. */
|
||||
ctx->slave = slave;
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Builds a TCP request header */
|
||||
static int _modbus_tcp_build_request_basis(modbus_t *ctx, int function,
|
||||
int addr, int nb,
|
||||
uint8_t *req)
|
||||
{
|
||||
modbus_tcp_t *ctx_tcp = ctx->backend_data;
|
||||
|
||||
/* Increase transaction ID */
|
||||
if (ctx_tcp->t_id < UINT16_MAX)
|
||||
ctx_tcp->t_id++;
|
||||
else
|
||||
ctx_tcp->t_id = 0;
|
||||
req[0] = ctx_tcp->t_id >> 8;
|
||||
req[1] = ctx_tcp->t_id & 0x00ff;
|
||||
|
||||
/* Protocol Modbus */
|
||||
req[2] = 0;
|
||||
req[3] = 0;
|
||||
|
||||
/* Length will be defined later by set_req_length_tcp at offsets 4
|
||||
and 5 */
|
||||
|
||||
req[6] = ctx->slave;
|
||||
req[7] = function;
|
||||
req[8] = addr >> 8;
|
||||
req[9] = addr & 0x00ff;
|
||||
req[10] = nb >> 8;
|
||||
req[11] = nb & 0x00ff;
|
||||
|
||||
return _MODBUS_TCP_PRESET_REQ_LENGTH;
|
||||
}
|
||||
|
||||
/* Builds a TCP response header */
|
||||
static int _modbus_tcp_build_response_basis(sft_t *sft, uint8_t *rsp)
|
||||
{
|
||||
/* Extract from MODBUS Messaging on TCP/IP Implementation
|
||||
Guide V1.0b (page 23/46):
|
||||
The transaction identifier is used to associate the future
|
||||
response with the request. */
|
||||
rsp[0] = sft->t_id >> 8;
|
||||
rsp[1] = sft->t_id & 0x00ff;
|
||||
|
||||
/* Protocol Modbus */
|
||||
rsp[2] = 0;
|
||||
rsp[3] = 0;
|
||||
|
||||
/* Length will be set later by send_msg (4 and 5) */
|
||||
|
||||
/* The slave ID is copied from the indication */
|
||||
rsp[6] = sft->slave;
|
||||
rsp[7] = sft->function;
|
||||
|
||||
return _MODBUS_TCP_PRESET_RSP_LENGTH;
|
||||
}
|
||||
|
||||
|
||||
static int _modbus_tcp_prepare_response_tid(const uint8_t *req, int *req_length)
|
||||
{
|
||||
return (req[0] << 8) + req[1];
|
||||
}
|
||||
|
||||
static int _modbus_tcp_send_msg_pre(uint8_t *req, int req_length)
|
||||
{
|
||||
/* Substract the header length to the message length */
|
||||
int mbap_length = req_length - 6;
|
||||
|
||||
req[4] = mbap_length >> 8;
|
||||
req[5] = mbap_length & 0x00FF;
|
||||
|
||||
return req_length;
|
||||
}
|
||||
|
||||
static ssize_t _modbus_tcp_send(modbus_t *ctx, const uint8_t *req, int req_length)
|
||||
{
|
||||
/* MSG_NOSIGNAL
|
||||
Requests not to send SIGPIPE on errors on stream oriented
|
||||
sockets when the other end breaks the connection. The EPIPE
|
||||
error is still returned. */
|
||||
return send(ctx->s, (const char *)req, req_length, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
static int _modbus_tcp_receive(modbus_t *ctx, uint8_t *req) {
|
||||
return _modbus_receive_msg(ctx, req, MSG_INDICATION);
|
||||
}
|
||||
|
||||
static ssize_t _modbus_tcp_recv(modbus_t *ctx, uint8_t *rsp, int rsp_length) {
|
||||
return recv(ctx->s, (char *)rsp, rsp_length, 0);
|
||||
}
|
||||
|
||||
static int _modbus_tcp_check_integrity(modbus_t *ctx, uint8_t *msg, const int msg_length)
|
||||
{
|
||||
return msg_length;
|
||||
}
|
||||
|
||||
static int _modbus_tcp_pre_check_confirmation(modbus_t *ctx, const uint8_t *req,
|
||||
const uint8_t *rsp, int rsp_length)
|
||||
{
|
||||
/* Check transaction ID */
|
||||
if (req[0] != rsp[0] || req[1] != rsp[1]) {
|
||||
if (ctx->debug) {
|
||||
fprintf(stderr, "Invalid transaction ID received 0x%X (not 0x%X)\n",
|
||||
(rsp[0] << 8) + rsp[1], (req[0] << 8) + req[1]);
|
||||
}
|
||||
errno = EMBBADDATA;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check protocol ID */
|
||||
if (rsp[2] != 0x0 && rsp[3] != 0x0) {
|
||||
if (ctx->debug) {
|
||||
fprintf(stderr, "Invalid protocol ID received 0x%X (not 0x0)\n",
|
||||
(rsp[2] << 8) + rsp[3]);
|
||||
}
|
||||
errno = EMBBADDATA;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _modbus_tcp_set_ipv4_options(int s)
|
||||
{
|
||||
int rc;
|
||||
int option;
|
||||
|
||||
/* Set the TCP no delay flag */
|
||||
/* SOL_TCP = IPPROTO_TCP */
|
||||
option = 1;
|
||||
rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
|
||||
(const void *)&option, sizeof(int));
|
||||
if (rc == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the OS does not offer SOCK_NONBLOCK, fall back to setting FIONBIO to
|
||||
* make sockets non-blocking */
|
||||
/* Do not care about the return value, this is optional */
|
||||
#if !defined(SOCK_NONBLOCK) && defined(FIONBIO)
|
||||
#ifdef OS_WIN32
|
||||
{
|
||||
/* Setting FIONBIO expects an unsigned long according to MSDN */
|
||||
u_long loption = 1;
|
||||
ioctlsocket(s, FIONBIO, &loption);
|
||||
}
|
||||
#else
|
||||
option = 1;
|
||||
ioctl(s, FIONBIO, &option);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef OS_WIN32
|
||||
/**
|
||||
* Cygwin defines IPTOS_LOWDELAY but can't handle that flag so it's
|
||||
* necessary to workaround that problem.
|
||||
**/
|
||||
/* Set the IP low delay option */
|
||||
option = IPTOS_LOWDELAY;
|
||||
rc = setsockopt(s, IPPROTO_IP, IP_TOS,
|
||||
(const void *)&option, sizeof(int));
|
||||
if (rc == -1) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen,
|
||||
const struct timeval *ro_tv)
|
||||
{
|
||||
int rc = connect(sockfd, addr, addrlen);
|
||||
|
||||
#ifdef OS_WIN32
|
||||
int wsaError = 0;
|
||||
if (rc == -1) {
|
||||
wsaError = WSAGetLastError();
|
||||
}
|
||||
|
||||
if (wsaError == WSAEWOULDBLOCK || wsaError == WSAEINPROGRESS) {
|
||||
#else
|
||||
if (rc == -1 && errno == EINPROGRESS) {
|
||||
#endif
|
||||
fd_set wset;
|
||||
int optval;
|
||||
socklen_t optlen = sizeof(optval);
|
||||
struct timeval tv = *ro_tv;
|
||||
|
||||
/* Wait to be available in writing */
|
||||
FD_ZERO(&wset);
|
||||
FD_SET(sockfd, &wset);
|
||||
rc = select(sockfd + 1, NULL, &wset, NULL, &tv);
|
||||
if (rc <= 0) {
|
||||
/* Timeout or fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The connection is established if SO_ERROR and optval are set to 0 */
|
||||
rc = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen);
|
||||
if (rc == 0 && optval == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
errno = ECONNREFUSED;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Establishes a modbus TCP connection with a Modbus server. */
|
||||
static int _modbus_tcp_connect(modbus_t *ctx)
|
||||
{
|
||||
int rc;
|
||||
/* Specialized version of sockaddr for Internet socket address (same size) */
|
||||
struct sockaddr_in addr;
|
||||
modbus_tcp_t *ctx_tcp = ctx->backend_data;
|
||||
int flags = SOCK_STREAM;
|
||||
|
||||
#ifdef OS_WIN32
|
||||
if (_modbus_tcp_init_win32() == -1) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SOCK_CLOEXEC
|
||||
flags |= SOCK_CLOEXEC;
|
||||
#endif
|
||||
|
||||
#ifdef SOCK_NONBLOCK
|
||||
flags |= SOCK_NONBLOCK;
|
||||
#endif
|
||||
|
||||
ctx->s = socket(PF_INET, flags, 0);
|
||||
if (ctx->s == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = _modbus_tcp_set_ipv4_options(ctx->s);
|
||||
if (rc == -1) {
|
||||
close(ctx->s);
|
||||
ctx->s = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctx->debug) {
|
||||
printf("Connecting to %s:%d\n", ctx_tcp->ip, ctx_tcp->port);
|
||||
}
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(ctx_tcp->port);
|
||||
addr.sin_addr.s_addr = inet_addr(ctx_tcp->ip);
|
||||
rc = _connect(ctx->s, (struct sockaddr *)&addr, sizeof(addr), &ctx->response_timeout);
|
||||
if (rc == -1) {
|
||||
close(ctx->s);
|
||||
ctx->s = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Establishes a modbus TCP PI connection with a Modbus server. */
|
||||
static int _modbus_tcp_pi_connect(modbus_t *ctx)
|
||||
{
|
||||
int rc;
|
||||
struct addrinfo *ai_list;
|
||||
struct addrinfo *ai_ptr;
|
||||
struct addrinfo ai_hints;
|
||||
modbus_tcp_pi_t *ctx_tcp_pi = ctx->backend_data;
|
||||
|
||||
#ifdef OS_WIN32
|
||||
if (_modbus_tcp_init_win32() == -1) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(&ai_hints, 0, sizeof(ai_hints));
|
||||
#ifdef AI_ADDRCONFIG
|
||||
ai_hints.ai_flags |= AI_ADDRCONFIG;
|
||||
#endif
|
||||
ai_hints.ai_family = AF_UNSPEC;
|
||||
ai_hints.ai_socktype = SOCK_STREAM;
|
||||
ai_hints.ai_addr = NULL;
|
||||
ai_hints.ai_canonname = NULL;
|
||||
ai_hints.ai_next = NULL;
|
||||
|
||||
ai_list = NULL;
|
||||
rc = getaddrinfo(ctx_tcp_pi->node, ctx_tcp_pi->service,
|
||||
&ai_hints, &ai_list);
|
||||
if (rc != 0) {
|
||||
if (ctx->debug) {
|
||||
fprintf(stderr, "Error returned by getaddrinfo: %s\n", gai_strerror(rc));
|
||||
}
|
||||
errno = ECONNREFUSED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
|
||||
int flags = ai_ptr->ai_socktype;
|
||||
int s;
|
||||
|
||||
#ifdef SOCK_CLOEXEC
|
||||
flags |= SOCK_CLOEXEC;
|
||||
#endif
|
||||
|
||||
#ifdef SOCK_NONBLOCK
|
||||
flags |= SOCK_NONBLOCK;
|
||||
#endif
|
||||
|
||||
s = socket(ai_ptr->ai_family, flags, ai_ptr->ai_protocol);
|
||||
if (s < 0)
|
||||
continue;
|
||||
|
||||
if (ai_ptr->ai_family == AF_INET)
|
||||
_modbus_tcp_set_ipv4_options(s);
|
||||
|
||||
if (ctx->debug) {
|
||||
printf("Connecting to [%s]:%s\n", ctx_tcp_pi->node, ctx_tcp_pi->service);
|
||||
}
|
||||
|
||||
rc = _connect(s, ai_ptr->ai_addr, ai_ptr->ai_addrlen, &ctx->response_timeout);
|
||||
if (rc == -1) {
|
||||
close(s);
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx->s = s;
|
||||
break;
|
||||
}
|
||||
|
||||
freeaddrinfo(ai_list);
|
||||
|
||||
if (ctx->s < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Closes the network connection and socket in TCP mode */
|
||||
static void _modbus_tcp_close(modbus_t *ctx)
|
||||
{
|
||||
if (ctx->s != -1) {
|
||||
shutdown(ctx->s, SHUT_RDWR);
|
||||
close(ctx->s);
|
||||
ctx->s = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int _modbus_tcp_flush(modbus_t *ctx)
|
||||
{
|
||||
int rc;
|
||||
int rc_sum = 0;
|
||||
|
||||
do {
|
||||
/* Extract the garbage from the socket */
|
||||
char devnull[MODBUS_TCP_MAX_ADU_LENGTH];
|
||||
#ifndef OS_WIN32
|
||||
rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, MSG_DONTWAIT);
|
||||
#else
|
||||
/* On Win32, it's a bit more complicated to not wait */
|
||||
fd_set rset;
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(ctx->s, &rset);
|
||||
rc = select(ctx->s+1, &rset, NULL, NULL, &tv);
|
||||
if (rc == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc == 1) {
|
||||
/* There is data to flush */
|
||||
rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0);
|
||||
}
|
||||
#endif
|
||||
if (rc > 0) {
|
||||
rc_sum += rc;
|
||||
}
|
||||
} while (rc == MODBUS_TCP_MAX_ADU_LENGTH);
|
||||
|
||||
return rc_sum;
|
||||
}
|
||||
|
||||
/* Listens for any request from one or many modbus masters in TCP */
|
||||
int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
|
||||
{
|
||||
int new_s;
|
||||
int enable;
|
||||
int flags;
|
||||
struct sockaddr_in addr;
|
||||
modbus_tcp_t *ctx_tcp;
|
||||
|
||||
if (ctx == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx_tcp = ctx->backend_data;
|
||||
|
||||
#ifdef OS_WIN32
|
||||
if (_modbus_tcp_init_win32() == -1) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
flags = SOCK_STREAM;
|
||||
|
||||
#ifdef SOCK_CLOEXEC
|
||||
flags |= SOCK_CLOEXEC;
|
||||
#endif
|
||||
|
||||
new_s = socket(PF_INET, flags, IPPROTO_TCP);
|
||||
if (new_s == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
enable = 1;
|
||||
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *)&enable, sizeof(enable)) == -1) {
|
||||
close(new_s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
/* If the modbus port is < to 1024, we need the setuid root. */
|
||||
addr.sin_port = htons(ctx_tcp->port);
|
||||
if (ctx_tcp->ip[0] == '0') {
|
||||
/* Listen any addresses */
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
} else {
|
||||
/* Listen only specified IP address */
|
||||
addr.sin_addr.s_addr = inet_addr(ctx_tcp->ip);
|
||||
}
|
||||
if (bind(new_s, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||
close(new_s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen(new_s, nb_connection) == -1) {
|
||||
close(new_s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return new_s;
|
||||
}
|
||||
|
||||
int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
|
||||
{
|
||||
int rc;
|
||||
struct addrinfo *ai_list;
|
||||
struct addrinfo *ai_ptr;
|
||||
struct addrinfo ai_hints;
|
||||
const char *node;
|
||||
const char *service;
|
||||
int new_s;
|
||||
modbus_tcp_pi_t *ctx_tcp_pi;
|
||||
|
||||
if (ctx == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx_tcp_pi = ctx->backend_data;
|
||||
|
||||
#ifdef OS_WIN32
|
||||
if (_modbus_tcp_init_win32() == -1) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ctx_tcp_pi->node[0] == 0) {
|
||||
node = NULL; /* == any */
|
||||
} else {
|
||||
node = ctx_tcp_pi->node;
|
||||
}
|
||||
|
||||
if (ctx_tcp_pi->service[0] == 0) {
|
||||
service = "502";
|
||||
} else {
|
||||
service = ctx_tcp_pi->service;
|
||||
}
|
||||
|
||||
memset(&ai_hints, 0, sizeof (ai_hints));
|
||||
/* If node is not NULL, than the AI_PASSIVE flag is ignored. */
|
||||
ai_hints.ai_flags |= AI_PASSIVE;
|
||||
#ifdef AI_ADDRCONFIG
|
||||
ai_hints.ai_flags |= AI_ADDRCONFIG;
|
||||
#endif
|
||||
ai_hints.ai_family = AF_UNSPEC;
|
||||
ai_hints.ai_socktype = SOCK_STREAM;
|
||||
ai_hints.ai_addr = NULL;
|
||||
ai_hints.ai_canonname = NULL;
|
||||
ai_hints.ai_next = NULL;
|
||||
|
||||
ai_list = NULL;
|
||||
rc = getaddrinfo(node, service, &ai_hints, &ai_list);
|
||||
if (rc != 0) {
|
||||
if (ctx->debug) {
|
||||
fprintf(stderr, "Error returned by getaddrinfo: %s\n", gai_strerror(rc));
|
||||
}
|
||||
errno = ECONNREFUSED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
new_s = -1;
|
||||
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
|
||||
int flags = ai_ptr->ai_socktype;
|
||||
int s;
|
||||
|
||||
#ifdef SOCK_CLOEXEC
|
||||
flags |= SOCK_CLOEXEC;
|
||||
#endif
|
||||
|
||||
s = socket(ai_ptr->ai_family, flags, ai_ptr->ai_protocol);
|
||||
if (s < 0) {
|
||||
if (ctx->debug) {
|
||||
perror("socket");
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
int enable = 1;
|
||||
rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
|
||||
(void *)&enable, sizeof (enable));
|
||||
if (rc != 0) {
|
||||
close(s);
|
||||
if (ctx->debug) {
|
||||
perror("setsockopt");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
rc = bind(s, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
|
||||
if (rc != 0) {
|
||||
close(s);
|
||||
if (ctx->debug) {
|
||||
perror("bind");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = listen(s, nb_connection);
|
||||
if (rc != 0) {
|
||||
close(s);
|
||||
if (ctx->debug) {
|
||||
perror("listen");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
new_s = s;
|
||||
break;
|
||||
}
|
||||
freeaddrinfo(ai_list);
|
||||
|
||||
if (new_s < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return new_s;
|
||||
}
|
||||
|
||||
int modbus_tcp_accept(modbus_t *ctx, int *s)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen;
|
||||
|
||||
if (ctx == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
addrlen = sizeof(addr);
|
||||
#ifdef HAVE_ACCEPT4
|
||||
/* Inherit socket flags and use accept4 call */
|
||||
ctx->s = accept4(*s, (struct sockaddr *)&addr, &addrlen, SOCK_CLOEXEC);
|
||||
#else
|
||||
ctx->s = accept(*s, (struct sockaddr *)&addr, &addrlen);
|
||||
#endif
|
||||
|
||||
if (ctx->s == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctx->debug) {
|
||||
printf("The client connection from %s is accepted\n",
|
||||
inet_ntoa(addr.sin_addr));
|
||||
}
|
||||
|
||||
return ctx->s;
|
||||
}
|
||||
|
||||
int modbus_tcp_pi_accept(modbus_t *ctx, int *s)
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
|
||||
if (ctx == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
addrlen = sizeof(addr);
|
||||
#ifdef HAVE_ACCEPT4
|
||||
/* Inherit socket flags and use accept4 call */
|
||||
ctx->s = accept4(*s, (struct sockaddr *)&addr, &addrlen, SOCK_CLOEXEC);
|
||||
#else
|
||||
ctx->s = accept(*s, (struct sockaddr *)&addr, &addrlen);
|
||||
#endif
|
||||
|
||||
if (ctx->s == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctx->debug) {
|
||||
printf("The client connection is accepted.\n");
|
||||
}
|
||||
|
||||
return ctx->s;
|
||||
}
|
||||
|
||||
static int _modbus_tcp_select(modbus_t *ctx, fd_set *rset, struct timeval *tv, int length_to_read)
|
||||
{
|
||||
int s_rc;
|
||||
while ((s_rc = select(ctx->s+1, rset, NULL, NULL, tv)) == -1) {
|
||||
if (errno == EINTR) {
|
||||
if (ctx->debug) {
|
||||
fprintf(stderr, "A non blocked signal was caught\n");
|
||||
}
|
||||
/* Necessary after an error */
|
||||
FD_ZERO(rset);
|
||||
FD_SET(ctx->s, rset);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_rc == 0) {
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return s_rc;
|
||||
}
|
||||
|
||||
static void _modbus_tcp_free(modbus_t *ctx) {
|
||||
free(ctx->backend_data);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
const modbus_backend_t _modbus_tcp_backend = {
|
||||
_MODBUS_BACKEND_TYPE_TCP,
|
||||
_MODBUS_TCP_HEADER_LENGTH,
|
||||
_MODBUS_TCP_CHECKSUM_LENGTH,
|
||||
MODBUS_TCP_MAX_ADU_LENGTH,
|
||||
_modbus_set_slave,
|
||||
_modbus_tcp_build_request_basis,
|
||||
_modbus_tcp_build_response_basis,
|
||||
_modbus_tcp_prepare_response_tid,
|
||||
_modbus_tcp_send_msg_pre,
|
||||
_modbus_tcp_send,
|
||||
_modbus_tcp_receive,
|
||||
_modbus_tcp_recv,
|
||||
_modbus_tcp_check_integrity,
|
||||
_modbus_tcp_pre_check_confirmation,
|
||||
_modbus_tcp_connect,
|
||||
_modbus_tcp_close,
|
||||
_modbus_tcp_flush,
|
||||
_modbus_tcp_select,
|
||||
_modbus_tcp_free
|
||||
};
|
||||
|
||||
|
||||
const modbus_backend_t _modbus_tcp_pi_backend = {
|
||||
_MODBUS_BACKEND_TYPE_TCP,
|
||||
_MODBUS_TCP_HEADER_LENGTH,
|
||||
_MODBUS_TCP_CHECKSUM_LENGTH,
|
||||
MODBUS_TCP_MAX_ADU_LENGTH,
|
||||
_modbus_set_slave,
|
||||
_modbus_tcp_build_request_basis,
|
||||
_modbus_tcp_build_response_basis,
|
||||
_modbus_tcp_prepare_response_tid,
|
||||
_modbus_tcp_send_msg_pre,
|
||||
_modbus_tcp_send,
|
||||
_modbus_tcp_receive,
|
||||
_modbus_tcp_recv,
|
||||
_modbus_tcp_check_integrity,
|
||||
_modbus_tcp_pre_check_confirmation,
|
||||
_modbus_tcp_pi_connect,
|
||||
_modbus_tcp_close,
|
||||
_modbus_tcp_flush,
|
||||
_modbus_tcp_select,
|
||||
_modbus_tcp_free
|
||||
};
|
||||
|
||||
modbus_t* modbus_new_tcp(const char *ip, int port)
|
||||
{
|
||||
modbus_t *ctx;
|
||||
modbus_tcp_t *ctx_tcp;
|
||||
size_t dest_size;
|
||||
size_t ret_size;
|
||||
|
||||
#if defined(OS_BSD)
|
||||
/* MSG_NOSIGNAL is unsupported on *BSD so we install an ignore
|
||||
handler for SIGPIPE. */
|
||||
struct sigaction sa;
|
||||
|
||||
sa.sa_handler = SIG_IGN;
|
||||
if (sigaction(SIGPIPE, &sa, NULL) < 0) {
|
||||
/* The debug flag can't be set here... */
|
||||
fprintf(stderr, "Could not install SIGPIPE handler.\n");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
ctx = (modbus_t *)malloc(sizeof(modbus_t));
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
_modbus_init_common(ctx);
|
||||
|
||||
/* Could be changed after to reach a remote serial Modbus device */
|
||||
ctx->slave = MODBUS_TCP_SLAVE;
|
||||
|
||||
ctx->backend = &_modbus_tcp_backend;
|
||||
|
||||
ctx->backend_data = (modbus_tcp_t *)malloc(sizeof(modbus_tcp_t));
|
||||
if (ctx->backend_data == NULL) {
|
||||
modbus_free(ctx);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
ctx_tcp = (modbus_tcp_t *)ctx->backend_data;
|
||||
|
||||
if (ip != NULL) {
|
||||
dest_size = sizeof(char) * 16;
|
||||
ret_size = strlcpy(ctx_tcp->ip, ip, dest_size);
|
||||
if (ret_size == 0) {
|
||||
fprintf(stderr, "The IP string is empty\n");
|
||||
modbus_free(ctx);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ret_size >= dest_size) {
|
||||
fprintf(stderr, "The IP string has been truncated\n");
|
||||
modbus_free(ctx);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ctx_tcp->ip[0] = '0';
|
||||
}
|
||||
ctx_tcp->port = port;
|
||||
ctx_tcp->t_id = 0;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
modbus_t* modbus_new_tcp_pi(const char *node, const char *service)
|
||||
{
|
||||
modbus_t *ctx;
|
||||
modbus_tcp_pi_t *ctx_tcp_pi;
|
||||
size_t dest_size;
|
||||
size_t ret_size;
|
||||
|
||||
ctx = (modbus_t *)malloc(sizeof(modbus_t));
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
_modbus_init_common(ctx);
|
||||
|
||||
/* Could be changed after to reach a remote serial Modbus device */
|
||||
ctx->slave = MODBUS_TCP_SLAVE;
|
||||
|
||||
ctx->backend = &_modbus_tcp_pi_backend;
|
||||
|
||||
ctx->backend_data = (modbus_tcp_pi_t *)malloc(sizeof(modbus_tcp_pi_t));
|
||||
if (ctx->backend_data == NULL) {
|
||||
modbus_free(ctx);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
ctx_tcp_pi = (modbus_tcp_pi_t *)ctx->backend_data;
|
||||
|
||||
if (node == NULL) {
|
||||
/* The node argument can be empty to indicate any hosts */
|
||||
ctx_tcp_pi->node[0] = 0;
|
||||
} else {
|
||||
dest_size = sizeof(char) * _MODBUS_TCP_PI_NODE_LENGTH;
|
||||
ret_size = strlcpy(ctx_tcp_pi->node, node, dest_size);
|
||||
if (ret_size == 0) {
|
||||
fprintf(stderr, "The node string is empty\n");
|
||||
modbus_free(ctx);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ret_size >= dest_size) {
|
||||
fprintf(stderr, "The node string has been truncated\n");
|
||||
modbus_free(ctx);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (service != NULL) {
|
||||
dest_size = sizeof(char) * _MODBUS_TCP_PI_SERVICE_LENGTH;
|
||||
ret_size = strlcpy(ctx_tcp_pi->service, service, dest_size);
|
||||
} else {
|
||||
/* Empty service is not allowed, error catched below. */
|
||||
ret_size = 0;
|
||||
}
|
||||
|
||||
if (ret_size == 0) {
|
||||
fprintf(stderr, "The service string is empty\n");
|
||||
modbus_free(ctx);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ret_size >= dest_size) {
|
||||
fprintf(stderr, "The service string has been truncated\n");
|
||||
modbus_free(ctx);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx_tcp_pi->t_id = 0;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2001-2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_TCP_H
|
||||
#define MODBUS_TCP_H
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
MODBUS_BEGIN_DECLS
|
||||
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
/* Win32 with MinGW, supplement to <errno.h> */
|
||||
#include <winsock2.h>
|
||||
#if !defined(ECONNRESET)
|
||||
#define ECONNRESET WSAECONNRESET
|
||||
#endif
|
||||
#if !defined(ECONNREFUSED)
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
#endif
|
||||
#if !defined(ETIMEDOUT)
|
||||
#define ETIMEDOUT WSAETIMEDOUT
|
||||
#endif
|
||||
#if !defined(ENOPROTOOPT)
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
#endif
|
||||
#if !defined(EINPROGRESS)
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MODBUS_TCP_DEFAULT_PORT 502
|
||||
#define MODBUS_TCP_SLAVE 0xFF
|
||||
|
||||
/* Modbus_Application_Protocol_V1_1b.pdf Chapter 4 Section 1 Page 5
|
||||
* TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes
|
||||
*/
|
||||
#define MODBUS_TCP_MAX_ADU_LENGTH 260
|
||||
|
||||
MODBUS_API modbus_t* modbus_new_tcp(const char *ip_address, int port);
|
||||
MODBUS_API int modbus_tcp_listen(modbus_t *ctx, int nb_connection);
|
||||
MODBUS_API int modbus_tcp_accept(modbus_t *ctx, int *s);
|
||||
|
||||
MODBUS_API modbus_t* modbus_new_tcp_pi(const char *node, const char *service);
|
||||
MODBUS_API int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection);
|
||||
MODBUS_API int modbus_tcp_pi_accept(modbus_t *ctx, int *s);
|
||||
|
||||
MODBUS_END_DECLS
|
||||
|
||||
#endif /* MODBUS_TCP_H */
|
||||
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2010-2014 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_VERSION_H
|
||||
#define MODBUS_VERSION_H
|
||||
|
||||
/* The major version, (1, if %LIBMODBUS_VERSION is 1.2.3) */
|
||||
#define LIBMODBUS_VERSION_MAJOR (3)
|
||||
|
||||
/* The minor version (2, if %LIBMODBUS_VERSION is 1.2.3) */
|
||||
#define LIBMODBUS_VERSION_MINOR (1)
|
||||
|
||||
/* The micro version (3, if %LIBMODBUS_VERSION is 1.2.3) */
|
||||
#define LIBMODBUS_VERSION_MICRO (6)
|
||||
|
||||
/* The full version, like 1.2.3 */
|
||||
#define LIBMODBUS_VERSION 3.1.6
|
||||
|
||||
/* The full version, in string form (suited for string concatenation)
|
||||
*/
|
||||
#define LIBMODBUS_VERSION_STRING "3.1.6"
|
||||
|
||||
/* Numerically encoded version, eg. v1.2.3 is 0x010203 */
|
||||
#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_VERSION_MAJOR << 16) | \
|
||||
(LIBMODBUS_VERSION_MINOR << 8) | \
|
||||
(LIBMODBUS_VERSION_MICRO << 0))
|
||||
|
||||
/* Evaluates to True if the version is greater than @major, @minor and @micro
|
||||
*/
|
||||
#define LIBMODBUS_VERSION_CHECK(major,minor,micro) \
|
||||
(LIBMODBUS_VERSION_MAJOR > (major) || \
|
||||
(LIBMODBUS_VERSION_MAJOR == (major) && \
|
||||
LIBMODBUS_VERSION_MINOR > (minor)) || \
|
||||
(LIBMODBUS_VERSION_MAJOR == (major) && \
|
||||
LIBMODBUS_VERSION_MINOR == (minor) && \
|
||||
LIBMODBUS_VERSION_MICRO >= (micro)))
|
||||
|
||||
#endif /* MODBUS_VERSION_H */
|
||||
1983
libmodbus/modbus.c
1983
libmodbus/modbus.c
File diff suppressed because it is too large
Load Diff
@ -1,293 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2001-2013 Stéphane Raimbault <stephane.raimbault@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef MODBUS_H
|
||||
#define MODBUS_H
|
||||
|
||||
/* Add this for macros that defined unix flavor */
|
||||
#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
|
||||
#include "modbus-version.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# if defined(DLLBUILD)
|
||||
/* define DLLBUILD when building the DLL */
|
||||
# define MODBUS_API __declspec(dllexport)
|
||||
# else
|
||||
# define MODBUS_API __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define MODBUS_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define MODBUS_BEGIN_DECLS extern "C" {
|
||||
# define MODBUS_END_DECLS }
|
||||
#else
|
||||
# define MODBUS_BEGIN_DECLS
|
||||
# define MODBUS_END_DECLS
|
||||
#endif
|
||||
|
||||
MODBUS_BEGIN_DECLS
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef OFF
|
||||
#define OFF 0
|
||||
#endif
|
||||
|
||||
#ifndef ON
|
||||
#define ON 1
|
||||
#endif
|
||||
|
||||
/* Modbus function codes */
|
||||
#define MODBUS_FC_READ_COILS 0x01
|
||||
#define MODBUS_FC_READ_DISCRETE_INPUTS 0x02
|
||||
#define MODBUS_FC_READ_HOLDING_REGISTERS 0x03
|
||||
#define MODBUS_FC_READ_INPUT_REGISTERS 0x04
|
||||
#define MODBUS_FC_WRITE_SINGLE_COIL 0x05
|
||||
#define MODBUS_FC_WRITE_SINGLE_REGISTER 0x06
|
||||
#define MODBUS_FC_READ_EXCEPTION_STATUS 0x07
|
||||
#define MODBUS_FC_WRITE_MULTIPLE_COILS 0x0F
|
||||
#define MODBUS_FC_WRITE_MULTIPLE_REGISTERS 0x10
|
||||
#define MODBUS_FC_REPORT_SLAVE_ID 0x11
|
||||
#define MODBUS_FC_MASK_WRITE_REGISTER 0x16
|
||||
#define MODBUS_FC_WRITE_AND_READ_REGISTERS 0x17
|
||||
|
||||
#define MODBUS_BROADCAST_ADDRESS 0
|
||||
|
||||
/* Modbus_Application_Protocol_V1_1b.pdf (chapter 6 section 1 page 12)
|
||||
* Quantity of Coils to read (2 bytes): 1 to 2000 (0x7D0)
|
||||
* (chapter 6 section 11 page 29)
|
||||
* Quantity of Coils to write (2 bytes): 1 to 1968 (0x7B0)
|
||||
*/
|
||||
#define MODBUS_MAX_READ_BITS 2000
|
||||
#define MODBUS_MAX_WRITE_BITS 1968
|
||||
|
||||
/* Modbus_Application_Protocol_V1_1b.pdf (chapter 6 section 3 page 15)
|
||||
* Quantity of Registers to read (2 bytes): 1 to 125 (0x7D)
|
||||
* (chapter 6 section 12 page 31)
|
||||
* Quantity of Registers to write (2 bytes) 1 to 123 (0x7B)
|
||||
* (chapter 6 section 17 page 38)
|
||||
* Quantity of Registers to write in R/W registers (2 bytes) 1 to 121 (0x79)
|
||||
*/
|
||||
#define MODBUS_MAX_READ_REGISTERS 125
|
||||
#define MODBUS_MAX_WRITE_REGISTERS 123
|
||||
#define MODBUS_MAX_WR_WRITE_REGISTERS 121
|
||||
#define MODBUS_MAX_WR_READ_REGISTERS 125
|
||||
|
||||
/* The size of the MODBUS PDU is limited by the size constraint inherited from
|
||||
* the first MODBUS implementation on Serial Line network (max. RS485 ADU = 256
|
||||
* bytes). Therefore, MODBUS PDU for serial line communication = 256 - Server
|
||||
* address (1 byte) - CRC (2 bytes) = 253 bytes.
|
||||
*/
|
||||
#define MODBUS_MAX_PDU_LENGTH 253
|
||||
|
||||
/* Consequently:
|
||||
* - RTU MODBUS ADU = 253 bytes + Server address (1 byte) + CRC (2 bytes) = 256
|
||||
* bytes.
|
||||
* - TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes.
|
||||
* so the maximum of both backend in 260 bytes. This size can used to allocate
|
||||
* an array of bytes to store responses and it will be compatible with the two
|
||||
* backends.
|
||||
*/
|
||||
#define MODBUS_MAX_ADU_LENGTH 260
|
||||
|
||||
/* Random number to avoid errno conflicts */
|
||||
#define MODBUS_ENOBASE 112345678
|
||||
|
||||
/* Protocol exceptions */
|
||||
enum {
|
||||
MODBUS_EXCEPTION_ILLEGAL_FUNCTION = 0x01,
|
||||
MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS,
|
||||
MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE,
|
||||
MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE,
|
||||
MODBUS_EXCEPTION_ACKNOWLEDGE,
|
||||
MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY,
|
||||
MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE,
|
||||
MODBUS_EXCEPTION_MEMORY_PARITY,
|
||||
MODBUS_EXCEPTION_NOT_DEFINED,
|
||||
MODBUS_EXCEPTION_GATEWAY_PATH,
|
||||
MODBUS_EXCEPTION_GATEWAY_TARGET,
|
||||
MODBUS_EXCEPTION_MAX
|
||||
};
|
||||
|
||||
#define EMBXILFUN (MODBUS_ENOBASE + MODBUS_EXCEPTION_ILLEGAL_FUNCTION)
|
||||
#define EMBXILADD (MODBUS_ENOBASE + MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS)
|
||||
#define EMBXILVAL (MODBUS_ENOBASE + MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE)
|
||||
#define EMBXSFAIL (MODBUS_ENOBASE + MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE)
|
||||
#define EMBXACK (MODBUS_ENOBASE + MODBUS_EXCEPTION_ACKNOWLEDGE)
|
||||
#define EMBXSBUSY (MODBUS_ENOBASE + MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY)
|
||||
#define EMBXNACK (MODBUS_ENOBASE + MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE)
|
||||
#define EMBXMEMPAR (MODBUS_ENOBASE + MODBUS_EXCEPTION_MEMORY_PARITY)
|
||||
#define EMBXGPATH (MODBUS_ENOBASE + MODBUS_EXCEPTION_GATEWAY_PATH)
|
||||
#define EMBXGTAR (MODBUS_ENOBASE + MODBUS_EXCEPTION_GATEWAY_TARGET)
|
||||
|
||||
/* Native libmodbus error codes */
|
||||
#define EMBBADCRC (EMBXGTAR + 1)
|
||||
#define EMBBADDATA (EMBXGTAR + 2)
|
||||
#define EMBBADEXC (EMBXGTAR + 3)
|
||||
#define EMBUNKEXC (EMBXGTAR + 4)
|
||||
#define EMBMDATA (EMBXGTAR + 5)
|
||||
#define EMBBADSLAVE (EMBXGTAR + 6)
|
||||
|
||||
extern const unsigned int libmodbus_version_major;
|
||||
extern const unsigned int libmodbus_version_minor;
|
||||
extern const unsigned int libmodbus_version_micro;
|
||||
|
||||
typedef struct _modbus modbus_t;
|
||||
|
||||
typedef struct _modbus_mapping_t {
|
||||
int nb_bits;
|
||||
int start_bits;
|
||||
int nb_input_bits;
|
||||
int start_input_bits;
|
||||
int nb_input_registers;
|
||||
int start_input_registers;
|
||||
int nb_registers;
|
||||
int start_registers;
|
||||
uint8_t *tab_bits;
|
||||
uint8_t *tab_input_bits;
|
||||
uint16_t *tab_input_registers;
|
||||
uint16_t *tab_registers;
|
||||
} modbus_mapping_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MODBUS_ERROR_RECOVERY_NONE = 0,
|
||||
MODBUS_ERROR_RECOVERY_LINK = (1<<1),
|
||||
MODBUS_ERROR_RECOVERY_PROTOCOL = (1<<2)
|
||||
} modbus_error_recovery_mode;
|
||||
|
||||
MODBUS_API int modbus_set_slave(modbus_t* ctx, int slave);
|
||||
MODBUS_API int modbus_get_slave(modbus_t* ctx);
|
||||
MODBUS_API int modbus_set_error_recovery(modbus_t *ctx, modbus_error_recovery_mode error_recovery);
|
||||
MODBUS_API int modbus_set_socket(modbus_t *ctx, int s);
|
||||
MODBUS_API int modbus_get_socket(modbus_t *ctx);
|
||||
|
||||
MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, uint32_t *to_sec, uint32_t *to_usec);
|
||||
MODBUS_API int modbus_set_response_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec);
|
||||
|
||||
MODBUS_API int modbus_get_byte_timeout(modbus_t *ctx, uint32_t *to_sec, uint32_t *to_usec);
|
||||
MODBUS_API int modbus_set_byte_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec);
|
||||
|
||||
MODBUS_API int modbus_get_indication_timeout(modbus_t *ctx, uint32_t *to_sec, uint32_t *to_usec);
|
||||
MODBUS_API int modbus_set_indication_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec);
|
||||
|
||||
MODBUS_API int modbus_get_header_length(modbus_t *ctx);
|
||||
|
||||
MODBUS_API int modbus_connect(modbus_t *ctx);
|
||||
MODBUS_API void modbus_close(modbus_t *ctx);
|
||||
|
||||
MODBUS_API void modbus_free(modbus_t *ctx);
|
||||
|
||||
MODBUS_API int modbus_flush(modbus_t *ctx);
|
||||
MODBUS_API int modbus_set_debug(modbus_t *ctx, int flag);
|
||||
|
||||
MODBUS_API const char *modbus_strerror(int errnum);
|
||||
|
||||
MODBUS_API int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest);
|
||||
MODBUS_API int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest);
|
||||
MODBUS_API int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest);
|
||||
MODBUS_API int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest);
|
||||
MODBUS_API int modbus_write_bit(modbus_t *ctx, int coil_addr, int status);
|
||||
MODBUS_API int modbus_write_register(modbus_t *ctx, int reg_addr, const uint16_t value);
|
||||
MODBUS_API int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data);
|
||||
MODBUS_API int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data);
|
||||
MODBUS_API int modbus_mask_write_register(modbus_t *ctx, int addr, uint16_t and_mask, uint16_t or_mask);
|
||||
MODBUS_API int modbus_write_and_read_registers(modbus_t *ctx, int write_addr, int write_nb,
|
||||
const uint16_t *src, int read_addr, int read_nb,
|
||||
uint16_t *dest);
|
||||
MODBUS_API int modbus_report_slave_id(modbus_t *ctx, int max_dest, uint8_t *dest);
|
||||
|
||||
MODBUS_API modbus_mapping_t* modbus_mapping_new_start_address(
|
||||
unsigned int start_bits, unsigned int nb_bits,
|
||||
unsigned int start_input_bits, unsigned int nb_input_bits,
|
||||
unsigned int start_registers, unsigned int nb_registers,
|
||||
unsigned int start_input_registers, unsigned int nb_input_registers);
|
||||
|
||||
MODBUS_API modbus_mapping_t* modbus_mapping_new(int nb_bits, int nb_input_bits,
|
||||
int nb_registers, int nb_input_registers);
|
||||
MODBUS_API void modbus_mapping_free(modbus_mapping_t *mb_mapping);
|
||||
|
||||
MODBUS_API int modbus_send_raw_request(modbus_t *ctx, const uint8_t *raw_req, int raw_req_length);
|
||||
|
||||
MODBUS_API int modbus_receive(modbus_t *ctx, uint8_t *req);
|
||||
|
||||
MODBUS_API int modbus_receive_confirmation(modbus_t *ctx, uint8_t *rsp);
|
||||
|
||||
MODBUS_API int modbus_reply(modbus_t *ctx, const uint8_t *req,
|
||||
int req_length, modbus_mapping_t *mb_mapping);
|
||||
MODBUS_API int modbus_reply_exception(modbus_t *ctx, const uint8_t *req,
|
||||
unsigned int exception_code);
|
||||
|
||||
/**
|
||||
* UTILS FUNCTIONS
|
||||
**/
|
||||
|
||||
#define MODBUS_GET_HIGH_BYTE(data) (((data) >> 8) & 0xFF)
|
||||
#define MODBUS_GET_LOW_BYTE(data) ((data) & 0xFF)
|
||||
#define MODBUS_GET_INT64_FROM_INT16(tab_int16, index) \
|
||||
(((int64_t)tab_int16[(index) ] << 48) + \
|
||||
((int64_t)tab_int16[(index) + 1] << 32) + \
|
||||
((int64_t)tab_int16[(index) + 2] << 16) + \
|
||||
(int64_t)tab_int16[(index) + 3])
|
||||
#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) + tab_int16[(index) + 1])
|
||||
#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) + tab_int8[(index) + 1])
|
||||
#define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \
|
||||
do { \
|
||||
tab_int8[(index)] = (value) >> 8; \
|
||||
tab_int8[(index) + 1] = (value) & 0xFF; \
|
||||
} while (0)
|
||||
#define MODBUS_SET_INT32_TO_INT16(tab_int16, index, value) \
|
||||
do { \
|
||||
tab_int16[(index) ] = (value) >> 16; \
|
||||
tab_int16[(index) + 1] = (value); \
|
||||
} while (0)
|
||||
#define MODBUS_SET_INT64_TO_INT16(tab_int16, index, value) \
|
||||
do { \
|
||||
tab_int16[(index) ] = (value) >> 48; \
|
||||
tab_int16[(index) + 1] = (value) >> 32; \
|
||||
tab_int16[(index) + 2] = (value) >> 16; \
|
||||
tab_int16[(index) + 3] = (value); \
|
||||
} while (0)
|
||||
|
||||
MODBUS_API void modbus_set_bits_from_byte(uint8_t *dest, int idx, const uint8_t value);
|
||||
MODBUS_API void modbus_set_bits_from_bytes(uint8_t *dest, int idx, unsigned int nb_bits,
|
||||
const uint8_t *tab_byte);
|
||||
MODBUS_API uint8_t modbus_get_byte_from_bits(const uint8_t *src, int idx, unsigned int nb_bits);
|
||||
MODBUS_API float modbus_get_float(const uint16_t *src);
|
||||
MODBUS_API float modbus_get_float_abcd(const uint16_t *src);
|
||||
MODBUS_API float modbus_get_float_dcba(const uint16_t *src);
|
||||
MODBUS_API float modbus_get_float_badc(const uint16_t *src);
|
||||
MODBUS_API float modbus_get_float_cdab(const uint16_t *src);
|
||||
|
||||
MODBUS_API void modbus_set_float(float f, uint16_t *dest);
|
||||
MODBUS_API void modbus_set_float_abcd(float f, uint16_t *dest);
|
||||
MODBUS_API void modbus_set_float_dcba(float f, uint16_t *dest);
|
||||
MODBUS_API void modbus_set_float_badc(float f, uint16_t *dest);
|
||||
MODBUS_API void modbus_set_float_cdab(float f, uint16_t *dest);
|
||||
|
||||
#include "modbus-tcp.h"
|
||||
#include "modbus-rtu.h"
|
||||
|
||||
MODBUS_END_DECLS
|
||||
|
||||
#endif /* MODBUS_H */
|
||||
@ -1,75 +0,0 @@
|
||||
|
||||
#ifndef sodium_H
|
||||
#define sodium_H
|
||||
|
||||
#include "sodium/version.h"
|
||||
|
||||
#include "sodium/core.h"
|
||||
#include "sodium/crypto_aead_aegis128l.h"
|
||||
#include "sodium/crypto_aead_aegis256.h"
|
||||
#include "sodium/crypto_aead_aes256gcm.h"
|
||||
#include "sodium/crypto_aead_chacha20poly1305.h"
|
||||
#include "sodium/crypto_aead_xchacha20poly1305.h"
|
||||
#include "sodium/crypto_auth.h"
|
||||
#include "sodium/crypto_auth_hmacsha256.h"
|
||||
#include "sodium/crypto_auth_hmacsha512.h"
|
||||
#include "sodium/crypto_auth_hmacsha512256.h"
|
||||
#include "sodium/crypto_box.h"
|
||||
#include "sodium/crypto_box_curve25519xsalsa20poly1305.h"
|
||||
#include "sodium/crypto_core_hchacha20.h"
|
||||
#include "sodium/crypto_core_hsalsa20.h"
|
||||
#include "sodium/crypto_core_salsa20.h"
|
||||
#include "sodium/crypto_core_salsa2012.h"
|
||||
#include "sodium/crypto_core_salsa208.h"
|
||||
#include "sodium/crypto_generichash.h"
|
||||
#include "sodium/crypto_generichash_blake2b.h"
|
||||
#include "sodium/crypto_hash.h"
|
||||
#include "sodium/crypto_hash_sha256.h"
|
||||
#include "sodium/crypto_hash_sha512.h"
|
||||
#include "sodium/crypto_kdf.h"
|
||||
#include "sodium/crypto_kdf_hkdf_sha256.h"
|
||||
#include "sodium/crypto_kdf_hkdf_sha512.h"
|
||||
#include "sodium/crypto_kdf_blake2b.h"
|
||||
#include "sodium/crypto_kdf_hkdf_sha256.h"
|
||||
#include "sodium/crypto_kdf_hkdf_sha512.h"
|
||||
#include "sodium/crypto_kx.h"
|
||||
#include "sodium/crypto_onetimeauth.h"
|
||||
#include "sodium/crypto_onetimeauth_poly1305.h"
|
||||
#include "sodium/crypto_pwhash.h"
|
||||
#include "sodium/crypto_pwhash_argon2i.h"
|
||||
#include "sodium/crypto_scalarmult.h"
|
||||
#include "sodium/crypto_scalarmult_curve25519.h"
|
||||
#include "sodium/crypto_secretbox.h"
|
||||
#include "sodium/crypto_secretbox_xsalsa20poly1305.h"
|
||||
#include "sodium/crypto_secretstream_xchacha20poly1305.h"
|
||||
#include "sodium/crypto_shorthash.h"
|
||||
#include "sodium/crypto_shorthash_siphash24.h"
|
||||
#include "sodium/crypto_sign.h"
|
||||
#include "sodium/crypto_sign_ed25519.h"
|
||||
#include "sodium/crypto_stream.h"
|
||||
#include "sodium/crypto_stream_chacha20.h"
|
||||
#include "sodium/crypto_stream_salsa20.h"
|
||||
#include "sodium/crypto_stream_xsalsa20.h"
|
||||
#include "sodium/crypto_verify_16.h"
|
||||
#include "sodium/crypto_verify_32.h"
|
||||
#include "sodium/crypto_verify_64.h"
|
||||
#include "sodium/randombytes.h"
|
||||
#include "sodium/randombytes_internal_random.h"
|
||||
#include "sodium/randombytes_sysrandom.h"
|
||||
#include "sodium/runtime.h"
|
||||
#include "sodium/utils.h"
|
||||
|
||||
#ifndef SODIUM_LIBRARY_MINIMAL
|
||||
#include "sodium/crypto_box_curve25519xchacha20poly1305.h"
|
||||
#include "sodium/crypto_core_ed25519.h"
|
||||
#include "sodium/crypto_core_ristretto255.h"
|
||||
#include "sodium/crypto_pwhash_scryptsalsa208sha256.h"
|
||||
#include "sodium/crypto_scalarmult_ed25519.h"
|
||||
#include "sodium/crypto_scalarmult_ristretto255.h"
|
||||
#include "sodium/crypto_secretbox_xchacha20poly1305.h"
|
||||
#include "sodium/crypto_stream_salsa2012.h"
|
||||
#include "sodium/crypto_stream_salsa208.h"
|
||||
#include "sodium/crypto_stream_xchacha20.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,28 +0,0 @@
|
||||
|
||||
#ifndef sodium_core_H
|
||||
#define sodium_core_H
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_init(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* ---- */
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_set_misuse_handler(void (*handler)(void));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_misuse(void)
|
||||
__attribute__ ((noreturn));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,92 +0,0 @@
|
||||
#ifndef crypto_aead_aegis128l_H
|
||||
#define crypto_aead_aegis128l_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic ignored "-Wlong-long"
|
||||
#endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_aead_aegis128l_KEYBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis128l_keybytes(void);
|
||||
|
||||
#define crypto_aead_aegis128l_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis128l_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_aegis128l_NPUBBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis128l_npubbytes(void);
|
||||
|
||||
#define crypto_aead_aegis128l_ABYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis128l_abytes(void);
|
||||
|
||||
#define crypto_aead_aegis128l_MESSAGEBYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aegis128l_ABYTES, (1ULL << 61) - 1)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis128l_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis128l_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k) __attribute__((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis128l_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k) __attribute__((warn_unused_result))
|
||||
__attribute__((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis128l_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis128l_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__((warn_unused_result)) __attribute__((nonnull(3, 5, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_aead_aegis128l_keygen(unsigned char k[crypto_aead_aegis128l_KEYBYTES])
|
||||
__attribute__((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,92 +0,0 @@
|
||||
#ifndef crypto_aead_aegis256_H
|
||||
#define crypto_aead_aegis256_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic ignored "-Wlong-long"
|
||||
#endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_aead_aegis256_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis256_keybytes(void);
|
||||
|
||||
#define crypto_aead_aegis256_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis256_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_aegis256_NPUBBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis256_npubbytes(void);
|
||||
|
||||
#define crypto_aead_aegis256_ABYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis256_abytes(void);
|
||||
|
||||
#define crypto_aead_aegis256_MESSAGEBYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aegis256_ABYTES, (1ULL << 61) - 1)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aegis256_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis256_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k) __attribute__((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis256_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k) __attribute__((warn_unused_result))
|
||||
__attribute__((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis256_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aegis256_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__((warn_unused_result)) __attribute__((nonnull(3, 5, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_aead_aegis256_keygen(unsigned char k[crypto_aead_aegis256_KEYBYTES])
|
||||
__attribute__((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,179 +0,0 @@
|
||||
#ifndef crypto_aead_aes256gcm_H
|
||||
#define crypto_aead_aes256gcm_H
|
||||
|
||||
/*
|
||||
* WARNING: Despite being the most popular AEAD construction due to its
|
||||
* use in TLS, safely using AES-GCM in a different context is tricky.
|
||||
*
|
||||
* No more than ~ 350 GB of input data should be encrypted with a given key.
|
||||
* This is for ~ 16 KB messages -- Actual figures vary according to
|
||||
* message sizes.
|
||||
*
|
||||
* In addition, nonces are short and repeated nonces would totally destroy
|
||||
* the security of this scheme.
|
||||
*
|
||||
* Nonces should thus come from atomic counters, which can be difficult to
|
||||
* set up in a distributed environment.
|
||||
*
|
||||
* Unless you absolutely need AES-GCM, use crypto_aead_xchacha20poly1305_ietf_*()
|
||||
* instead. It doesn't have any of these limitations.
|
||||
* Or, if you don't need to authenticate additional data, just stick to
|
||||
* crypto_secretbox().
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_is_available(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_keybytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_NPUBBYTES 12U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_npubbytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_abytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_MESSAGEBYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aes256gcm_ABYTES, \
|
||||
(16ULL * ((1ULL << 32) - 2ULL)))
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_messagebytes_max(void);
|
||||
|
||||
typedef struct CRYPTO_ALIGN(16) crypto_aead_aes256gcm_state_ {
|
||||
unsigned char opaque[512];
|
||||
} crypto_aead_aes256gcm_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
|
||||
|
||||
/* -- Precomputation interface -- */
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_encrypt_afternm(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
__attribute__ ((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_decrypt_afternm(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_encrypt_detached_afternm(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
__attribute__ ((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_aead_aes256gcm_keygen(unsigned char k[crypto_aead_aes256gcm_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,180 +0,0 @@
|
||||
#ifndef crypto_aead_chacha20poly1305_H
|
||||
#define crypto_aead_chacha20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -- IETF ChaCha20-Poly1305 construction with a 96-bit nonce and a 32-bit internal counter -- */
|
||||
|
||||
#define crypto_aead_chacha20poly1305_ietf_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_ietf_keybytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_ietf_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_ietf_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_ietf_NPUBBYTES 12U
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_ietf_npubbytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_ietf_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_ietf_abytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ietf_ABYTES, \
|
||||
(64ULL * ((1ULL << 32) - 1ULL)))
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_ietf_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_ietf_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_chacha20poly1305_ietf_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* -- Original ChaCha20-Poly1305 construction with a 64-bit nonce and a 64-bit internal counter -- */
|
||||
|
||||
#define crypto_aead_chacha20poly1305_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_keybytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_NPUBBYTES 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_npubbytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_abytes(void);
|
||||
|
||||
#define crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX \
|
||||
(SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ABYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_chacha20poly1305_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_chacha20poly1305_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* Aliases */
|
||||
|
||||
#define crypto_aead_chacha20poly1305_IETF_KEYBYTES crypto_aead_chacha20poly1305_ietf_KEYBYTES
|
||||
#define crypto_aead_chacha20poly1305_IETF_NSECBYTES crypto_aead_chacha20poly1305_ietf_NSECBYTES
|
||||
#define crypto_aead_chacha20poly1305_IETF_NPUBBYTES crypto_aead_chacha20poly1305_ietf_NPUBBYTES
|
||||
#define crypto_aead_chacha20poly1305_IETF_ABYTES crypto_aead_chacha20poly1305_ietf_ABYTES
|
||||
#define crypto_aead_chacha20poly1305_IETF_MESSAGEBYTES_MAX crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,100 +0,0 @@
|
||||
#ifndef crypto_aead_xchacha20poly1305_H
|
||||
#define crypto_aead_xchacha20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_ietf_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_keybytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_ietf_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_ietf_NPUBBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_npubbytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_ietf_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_abytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX \
|
||||
(SODIUM_SIZE_MAX - crypto_aead_xchacha20poly1305_ietf_ABYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_ietf_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_ietf_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_ietf_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 9, 10)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *mac,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* Aliases */
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_IETF_KEYBYTES crypto_aead_xchacha20poly1305_ietf_KEYBYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_NSECBYTES crypto_aead_xchacha20poly1305_ietf_NSECBYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_NPUBBYTES crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_ABYTES crypto_aead_xchacha20poly1305_ietf_ABYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_MESSAGEBYTES_MAX crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,46 +0,0 @@
|
||||
#ifndef crypto_auth_H
|
||||
#define crypto_auth_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_auth_hmacsha512256.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_bytes(void);
|
||||
|
||||
#define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_keybytes(void);
|
||||
|
||||
#define crypto_auth_PRIMITIVE "hmacsha512256"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_auth_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_verify(const unsigned char *h, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,70 +0,0 @@
|
||||
#ifndef crypto_auth_hmacsha256_H
|
||||
#define crypto_auth_hmacsha256_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_hash_sha256.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_auth_hmacsha256_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha256_bytes(void);
|
||||
|
||||
#define crypto_auth_hmacsha256_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha256_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256(unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct crypto_auth_hmacsha256_state {
|
||||
crypto_hash_sha256_state ictx;
|
||||
crypto_hash_sha256_state octx;
|
||||
} crypto_auth_hmacsha256_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha256_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state,
|
||||
const unsigned char *key,
|
||||
size_t keylen) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_final(crypto_auth_hmacsha256_state *state,
|
||||
unsigned char *out) __attribute__ ((nonnull));
|
||||
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_auth_hmacsha256_keygen(unsigned char k[crypto_auth_hmacsha256_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,68 +0,0 @@
|
||||
#ifndef crypto_auth_hmacsha512_H
|
||||
#define crypto_auth_hmacsha512_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_auth_hmacsha512_BYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha512_bytes(void);
|
||||
|
||||
#define crypto_auth_hmacsha512_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha512_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512(unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct crypto_auth_hmacsha512_state {
|
||||
crypto_hash_sha512_state ictx;
|
||||
crypto_hash_sha512_state octx;
|
||||
} crypto_auth_hmacsha512_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha512_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state,
|
||||
const unsigned char *key,
|
||||
size_t keylen) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_final(crypto_auth_hmacsha512_state *state,
|
||||
unsigned char *out) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_auth_hmacsha512_keygen(unsigned char k[crypto_auth_hmacsha512_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,65 +0,0 @@
|
||||
#ifndef crypto_auth_hmacsha512256_H
|
||||
#define crypto_auth_hmacsha512256_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_auth_hmacsha512.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_auth_hmacsha512256_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha512256_bytes(void);
|
||||
|
||||
#define crypto_auth_hmacsha512256_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha512256_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512256(unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512256_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
typedef crypto_auth_hmacsha512_state crypto_auth_hmacsha512256_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_auth_hmacsha512256_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state,
|
||||
const unsigned char *key,
|
||||
size_t keylen) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state,
|
||||
unsigned char *out) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_auth_hmacsha512256_keygen(unsigned char k[crypto_auth_hmacsha512256_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,177 +0,0 @@
|
||||
#ifndef crypto_box_H
|
||||
#define crypto_box_H
|
||||
|
||||
/*
|
||||
* THREAD SAFETY: crypto_box_keypair() is thread-safe,
|
||||
* provided that sodium_init() was called before.
|
||||
*
|
||||
* Other functions are always thread-safe.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_box_curve25519xsalsa20poly1305.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_seedbytes(void);
|
||||
|
||||
#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_publickeybytes(void);
|
||||
|
||||
#define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_secretkeybytes(void);
|
||||
|
||||
#define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_noncebytes(void);
|
||||
|
||||
#define crypto_box_MACBYTES crypto_box_curve25519xsalsa20poly1305_MACBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_macbytes(void);
|
||||
|
||||
#define crypto_box_MESSAGEBYTES_MAX crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_messagebytes_max(void);
|
||||
|
||||
#define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_box_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||
const unsigned char *seed)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_keypair(unsigned char *pk, unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_easy(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_detached(unsigned char *c, unsigned char *mac,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *n, const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open_detached(unsigned char *m, const unsigned char *c,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7)));
|
||||
|
||||
/* -- Precomputation interface -- */
|
||||
|
||||
#define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_beforenmbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
|
||||
|
||||
/* -- Ephemeral SK interface -- */
|
||||
|
||||
#define crypto_box_SEALBYTES (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_sealbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_seal(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *pk)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_seal_open(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
/* -- NaCl compatibility interface ; Requires padding -- */
|
||||
|
||||
#define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_zerobytes(void);
|
||||
|
||||
#define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_boxzerobytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_afternm(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,164 +0,0 @@
|
||||
|
||||
#ifndef crypto_box_curve25519xchacha20poly1305_H
|
||||
#define crypto_box_curve25519xchacha20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_stream_xchacha20.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_SEEDBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_seedbytes(void);
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_publickeybytes(void);
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_secretkeybytes(void);
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_beforenmbytes(void);
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_noncebytes(void);
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_MACBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_macbytes(void);
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX \
|
||||
(crypto_stream_xchacha20_MESSAGEBYTES_MAX - crypto_box_curve25519xchacha20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_seed_keypair(unsigned char *pk,
|
||||
unsigned char *sk,
|
||||
const unsigned char *seed)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_keypair(unsigned char *pk,
|
||||
unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_easy(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_open_easy(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_open_detached(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7)));
|
||||
|
||||
/* -- Precomputation interface -- */
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_beforenm(unsigned char *k,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_easy_afternm(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_open_easy_afternm(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_detached_afternm(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_open_detached_afternm(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
|
||||
|
||||
/* -- Ephemeral SK interface -- */
|
||||
|
||||
#define crypto_box_curve25519xchacha20poly1305_SEALBYTES \
|
||||
(crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES + \
|
||||
crypto_box_curve25519xchacha20poly1305_MACBYTES)
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xchacha20poly1305_sealbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xchacha20poly1305_seal_open(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,112 +0,0 @@
|
||||
#ifndef crypto_box_curve25519xsalsa20poly1305_H
|
||||
#define crypto_box_curve25519xsalsa20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_stream_xsalsa20.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_SEEDBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_seedbytes(void);
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_publickeybytes(void);
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_secretkeybytes(void);
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_beforenmbytes(void);
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_noncebytes(void);
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_MACBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_macbytes(void);
|
||||
|
||||
/* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */
|
||||
#define crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX \
|
||||
(crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_box_curve25519xsalsa20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,
|
||||
unsigned char *sk,
|
||||
const unsigned char *seed)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk,
|
||||
unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
/* -- NaCl compatibility interface ; Requires padding -- */
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void);
|
||||
|
||||
#define crypto_box_curve25519xsalsa20poly1305_ZEROBYTES \
|
||||
(crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + \
|
||||
crypto_box_curve25519xsalsa20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_box_curve25519xsalsa20poly1305_zerobytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,100 +0,0 @@
|
||||
#ifndef crypto_core_ed25519_H
|
||||
#define crypto_core_ed25519_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_ed25519_BYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ed25519_bytes(void);
|
||||
|
||||
#define crypto_core_ed25519_UNIFORMBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ed25519_uniformbytes(void);
|
||||
|
||||
#define crypto_core_ed25519_HASHBYTES 64
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ed25519_hashbytes(void);
|
||||
|
||||
#define crypto_core_ed25519_SCALARBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ed25519_scalarbytes(void);
|
||||
|
||||
#define crypto_core_ed25519_NONREDUCEDSCALARBYTES 64
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ed25519_nonreducedscalarbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ed25519_is_valid_point(const unsigned char *p)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ed25519_add(unsigned char *r,
|
||||
const unsigned char *p, const unsigned char *q)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ed25519_sub(unsigned char *r,
|
||||
const unsigned char *p, const unsigned char *q)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ed25519_from_uniform(unsigned char *p, const unsigned char *r)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ed25519_from_hash(unsigned char *p, const unsigned char *h)
|
||||
__attribute__ ((nonnull)) __attribute__ ((deprecated));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_random(unsigned char *p)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_random(unsigned char *r)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ed25519_scalar_invert(unsigned char *recip, const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_negate(unsigned char *neg, const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_complement(unsigned char *comp, const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_add(unsigned char *z, const unsigned char *x,
|
||||
const unsigned char *y)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_sub(unsigned char *z, const unsigned char *x,
|
||||
const unsigned char *y)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_mul(unsigned char *z, const unsigned char *x,
|
||||
const unsigned char *y)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/*
|
||||
* The interval `s` is sampled from should be at least 317 bits to ensure almost
|
||||
* uniformity of `r` over `L`.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ed25519_scalar_reduce(unsigned char *r, const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,36 +0,0 @@
|
||||
#ifndef crypto_core_hchacha20_H
|
||||
#define crypto_core_hchacha20_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_hchacha20_OUTPUTBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hchacha20_outputbytes(void);
|
||||
|
||||
#define crypto_core_hchacha20_INPUTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hchacha20_inputbytes(void);
|
||||
|
||||
#define crypto_core_hchacha20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hchacha20_keybytes(void);
|
||||
|
||||
#define crypto_core_hchacha20_CONSTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hchacha20_constbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_hchacha20(unsigned char *out, const unsigned char *in,
|
||||
const unsigned char *k, const unsigned char *c)
|
||||
__attribute__ ((nonnull(1, 2, 3)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,36 +0,0 @@
|
||||
#ifndef crypto_core_hsalsa20_H
|
||||
#define crypto_core_hsalsa20_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_hsalsa20_OUTPUTBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hsalsa20_outputbytes(void);
|
||||
|
||||
#define crypto_core_hsalsa20_INPUTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hsalsa20_inputbytes(void);
|
||||
|
||||
#define crypto_core_hsalsa20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hsalsa20_keybytes(void);
|
||||
|
||||
#define crypto_core_hsalsa20_CONSTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_hsalsa20_constbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_hsalsa20(unsigned char *out, const unsigned char *in,
|
||||
const unsigned char *k, const unsigned char *c)
|
||||
__attribute__ ((nonnull(1, 2, 3)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,100 +0,0 @@
|
||||
#ifndef crypto_core_ristretto255_H
|
||||
#define crypto_core_ristretto255_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_ristretto255_BYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ristretto255_bytes(void);
|
||||
|
||||
#define crypto_core_ristretto255_HASHBYTES 64
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ristretto255_hashbytes(void);
|
||||
|
||||
#define crypto_core_ristretto255_SCALARBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ristretto255_scalarbytes(void);
|
||||
|
||||
#define crypto_core_ristretto255_NONREDUCEDSCALARBYTES 64
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_ristretto255_nonreducedscalarbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ristretto255_is_valid_point(const unsigned char *p)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ristretto255_add(unsigned char *r,
|
||||
const unsigned char *p, const unsigned char *q)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ristretto255_sub(unsigned char *r,
|
||||
const unsigned char *p, const unsigned char *q)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ristretto255_from_hash(unsigned char *p,
|
||||
const unsigned char *r)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_random(unsigned char *p)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_random(unsigned char *r)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_ristretto255_scalar_invert(unsigned char *recip,
|
||||
const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_negate(unsigned char *neg,
|
||||
const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_complement(unsigned char *comp,
|
||||
const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_add(unsigned char *z,
|
||||
const unsigned char *x,
|
||||
const unsigned char *y)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_sub(unsigned char *z,
|
||||
const unsigned char *x,
|
||||
const unsigned char *y)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_mul(unsigned char *z,
|
||||
const unsigned char *x,
|
||||
const unsigned char *y)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/*
|
||||
* The interval `s` is sampled from should be at least 317 bits to ensure almost
|
||||
* uniformity of `r` over `L`.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
void crypto_core_ristretto255_scalar_reduce(unsigned char *r,
|
||||
const unsigned char *s)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,36 +0,0 @@
|
||||
#ifndef crypto_core_salsa20_H
|
||||
#define crypto_core_salsa20_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_salsa20_OUTPUTBYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa20_outputbytes(void);
|
||||
|
||||
#define crypto_core_salsa20_INPUTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa20_inputbytes(void);
|
||||
|
||||
#define crypto_core_salsa20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa20_keybytes(void);
|
||||
|
||||
#define crypto_core_salsa20_CONSTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa20_constbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_salsa20(unsigned char *out, const unsigned char *in,
|
||||
const unsigned char *k, const unsigned char *c)
|
||||
__attribute__ ((nonnull(1, 2, 3)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,36 +0,0 @@
|
||||
#ifndef crypto_core_salsa2012_H
|
||||
#define crypto_core_salsa2012_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_salsa2012_OUTPUTBYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa2012_outputbytes(void);
|
||||
|
||||
#define crypto_core_salsa2012_INPUTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa2012_inputbytes(void);
|
||||
|
||||
#define crypto_core_salsa2012_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa2012_keybytes(void);
|
||||
|
||||
#define crypto_core_salsa2012_CONSTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa2012_constbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_salsa2012(unsigned char *out, const unsigned char *in,
|
||||
const unsigned char *k, const unsigned char *c)
|
||||
__attribute__ ((nonnull(1, 2, 3)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,40 +0,0 @@
|
||||
#ifndef crypto_core_salsa208_H
|
||||
#define crypto_core_salsa208_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_core_salsa208_OUTPUTBYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa208_outputbytes(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
#define crypto_core_salsa208_INPUTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa208_inputbytes(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
#define crypto_core_salsa208_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa208_keybytes(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
#define crypto_core_salsa208_CONSTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_core_salsa208_constbytes(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_core_salsa208(unsigned char *out, const unsigned char *in,
|
||||
const unsigned char *k, const unsigned char *c)
|
||||
__attribute__ ((nonnull(1, 2, 3)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,84 +0,0 @@
|
||||
#ifndef crypto_generichash_H
|
||||
#define crypto_generichash_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_generichash_blake2b.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_generichash_BYTES_MIN crypto_generichash_blake2b_BYTES_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_bytes_min(void);
|
||||
|
||||
#define crypto_generichash_BYTES_MAX crypto_generichash_blake2b_BYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_bytes_max(void);
|
||||
|
||||
#define crypto_generichash_BYTES crypto_generichash_blake2b_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_bytes(void);
|
||||
|
||||
#define crypto_generichash_KEYBYTES_MIN crypto_generichash_blake2b_KEYBYTES_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_keybytes_min(void);
|
||||
|
||||
#define crypto_generichash_KEYBYTES_MAX crypto_generichash_blake2b_KEYBYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_keybytes_max(void);
|
||||
|
||||
#define crypto_generichash_KEYBYTES crypto_generichash_blake2b_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_keybytes(void);
|
||||
|
||||
#define crypto_generichash_PRIMITIVE "blake2b"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_generichash_primitive(void);
|
||||
|
||||
/*
|
||||
* Important when writing bindings for other programming languages:
|
||||
* the state address should be 64-bytes aligned.
|
||||
*/
|
||||
typedef crypto_generichash_blake2b_state crypto_generichash_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash(unsigned char *out, size_t outlen,
|
||||
const unsigned char *in, unsigned long long inlen,
|
||||
const unsigned char *key, size_t keylen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_init(crypto_generichash_state *state,
|
||||
const unsigned char *key,
|
||||
const size_t keylen, const size_t outlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_update(crypto_generichash_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_final(crypto_generichash_state *state,
|
||||
unsigned char *out, const size_t outlen)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,122 +0,0 @@
|
||||
#ifndef crypto_generichash_blake2b_H
|
||||
#define crypto_generichash_blake2b_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __IBMC__
|
||||
# pragma pack(1)
|
||||
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# pragma pack(1)
|
||||
#else
|
||||
# pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_ALIGN(64) crypto_generichash_blake2b_state {
|
||||
unsigned char opaque[384];
|
||||
} crypto_generichash_blake2b_state;
|
||||
|
||||
#ifdef __IBMC__
|
||||
# pragma pack(pop)
|
||||
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# pragma pack()
|
||||
#else
|
||||
# pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#define crypto_generichash_blake2b_BYTES_MIN 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_bytes_min(void);
|
||||
|
||||
#define crypto_generichash_blake2b_BYTES_MAX 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_bytes_max(void);
|
||||
|
||||
#define crypto_generichash_blake2b_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_bytes(void);
|
||||
|
||||
#define crypto_generichash_blake2b_KEYBYTES_MIN 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_keybytes_min(void);
|
||||
|
||||
#define crypto_generichash_blake2b_KEYBYTES_MAX 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_keybytes_max(void);
|
||||
|
||||
#define crypto_generichash_blake2b_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_keybytes(void);
|
||||
|
||||
#define crypto_generichash_blake2b_SALTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_saltbytes(void);
|
||||
|
||||
#define crypto_generichash_blake2b_PERSONALBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_personalbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_generichash_blake2b_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_blake2b(unsigned char *out, size_t outlen,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *key, size_t keylen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_blake2b_salt_personal(unsigned char *out, size_t outlen,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *key,
|
||||
size_t keylen,
|
||||
const unsigned char *salt,
|
||||
const unsigned char *personal)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state,
|
||||
const unsigned char *key,
|
||||
const size_t keylen, const size_t outlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_blake2b_init_salt_personal(crypto_generichash_blake2b_state *state,
|
||||
const unsigned char *key,
|
||||
const size_t keylen, const size_t outlen,
|
||||
const unsigned char *salt,
|
||||
const unsigned char *personal)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state,
|
||||
unsigned char *out,
|
||||
const size_t outlen) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_generichash_blake2b_keygen(unsigned char k[crypto_generichash_blake2b_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,40 +0,0 @@
|
||||
#ifndef crypto_hash_H
|
||||
#define crypto_hash_H
|
||||
|
||||
/*
|
||||
* WARNING: Unless you absolutely need to use SHA512 for interoperability,
|
||||
* purposes, you might want to consider crypto_generichash() instead.
|
||||
* Unlike SHA512, crypto_generichash() is not vulnerable to length
|
||||
* extension attacks.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_hash_BYTES crypto_hash_sha512_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_hash_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen) __attribute__ ((nonnull(1)));
|
||||
|
||||
#define crypto_hash_PRIMITIVE "sha512"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_hash_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,60 +0,0 @@
|
||||
#ifndef crypto_hash_sha256_H
|
||||
#define crypto_hash_sha256_H
|
||||
|
||||
/*
|
||||
* WARNING: Unless you absolutely need to use SHA256 for interoperability,
|
||||
* purposes, you might want to consider crypto_generichash() instead.
|
||||
* Unlike SHA256, crypto_generichash() is not vulnerable to length
|
||||
* extension attacks.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct crypto_hash_sha256_state {
|
||||
uint32_t state[8];
|
||||
uint64_t count;
|
||||
uint8_t buf[64];
|
||||
} crypto_hash_sha256_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_hash_sha256_statebytes(void);
|
||||
|
||||
#define crypto_hash_sha256_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_hash_sha256_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha256_init(crypto_hash_sha256_state *state)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha256_update(crypto_hash_sha256_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha256_final(crypto_hash_sha256_state *state,
|
||||
unsigned char *out)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,60 +0,0 @@
|
||||
#ifndef crypto_hash_sha512_H
|
||||
#define crypto_hash_sha512_H
|
||||
|
||||
/*
|
||||
* WARNING: Unless you absolutely need to use SHA512 for interoperability,
|
||||
* purposes, you might want to consider crypto_generichash() instead.
|
||||
* Unlike SHA512, crypto_generichash() is not vulnerable to length
|
||||
* extension attacks.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct crypto_hash_sha512_state {
|
||||
uint64_t state[8];
|
||||
uint64_t count[2];
|
||||
uint8_t buf[128];
|
||||
} crypto_hash_sha512_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_hash_sha512_statebytes(void);
|
||||
|
||||
#define crypto_hash_sha512_BYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_hash_sha512_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha512(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha512_init(crypto_hash_sha512_state *state)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha512_update(crypto_hash_sha512_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_hash_sha512_final(crypto_hash_sha512_state *state,
|
||||
unsigned char *out)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,53 +0,0 @@
|
||||
#ifndef crypto_kdf_H
|
||||
#define crypto_kdf_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "crypto_kdf_blake2b.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_kdf_BYTES_MIN crypto_kdf_blake2b_BYTES_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_bytes_min(void);
|
||||
|
||||
#define crypto_kdf_BYTES_MAX crypto_kdf_blake2b_BYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_bytes_max(void);
|
||||
|
||||
#define crypto_kdf_CONTEXTBYTES crypto_kdf_blake2b_CONTEXTBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_contextbytes(void);
|
||||
|
||||
#define crypto_kdf_KEYBYTES crypto_kdf_blake2b_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_keybytes(void);
|
||||
|
||||
#define crypto_kdf_PRIMITIVE "blake2b"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_kdf_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len,
|
||||
uint64_t subkey_id,
|
||||
const char ctx[crypto_kdf_CONTEXTBYTES],
|
||||
const unsigned char key[crypto_kdf_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,44 +0,0 @@
|
||||
#ifndef crypto_kdf_blake2b_H
|
||||
#define crypto_kdf_blake2b_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_kdf_blake2b_BYTES_MIN 16
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_blake2b_bytes_min(void);
|
||||
|
||||
#define crypto_kdf_blake2b_BYTES_MAX 64
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_blake2b_bytes_max(void);
|
||||
|
||||
#define crypto_kdf_blake2b_CONTEXTBYTES 8
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_blake2b_contextbytes(void);
|
||||
|
||||
#define crypto_kdf_blake2b_KEYBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_blake2b_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_blake2b_derive_from_key(unsigned char *subkey, size_t subkey_len,
|
||||
uint64_t subkey_id,
|
||||
const char ctx[crypto_kdf_blake2b_CONTEXTBYTES],
|
||||
const unsigned char key[crypto_kdf_blake2b_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,74 +0,0 @@
|
||||
#ifndef crypto_kdf_hkdf_sha256_H
|
||||
#define crypto_kdf_hkdf_sha256_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "crypto_kdf.h"
|
||||
#include "crypto_auth_hmacsha256.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_kdf_hkdf_sha256_KEYBYTES crypto_auth_hmacsha256_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha256_keybytes(void);
|
||||
|
||||
#define crypto_kdf_hkdf_sha256_BYTES_MIN 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha256_bytes_min(void);
|
||||
|
||||
#define crypto_kdf_hkdf_sha256_BYTES_MAX (0xff * crypto_auth_hmacsha256_BYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha256_bytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha256_extract(unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES],
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *ikm, size_t ikm_len)
|
||||
__attribute__ ((nonnull(4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_kdf_hkdf_sha256_keygen(unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES]);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha256_expand(unsigned char *out, size_t out_len,
|
||||
const char *ctx, size_t ctx_len,
|
||||
const unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES])
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct crypto_kdf_hkdf_sha256_state {
|
||||
crypto_auth_hmacsha256_state st;
|
||||
} crypto_kdf_hkdf_sha256_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha256_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha256_extract_init(crypto_kdf_hkdf_sha256_state *state,
|
||||
const unsigned char *salt, size_t salt_len)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha256_extract_update(crypto_kdf_hkdf_sha256_state *state,
|
||||
const unsigned char *ikm, size_t ikm_len)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha256_extract_final(crypto_kdf_hkdf_sha256_state *state,
|
||||
unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,75 +0,0 @@
|
||||
#ifndef crypto_kdf_hkdf_sha512_H
|
||||
#define crypto_kdf_hkdf_sha512_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "crypto_kdf.h"
|
||||
#include "crypto_auth_hmacsha512.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_kdf_hkdf_sha512_KEYBYTES crypto_auth_hmacsha512_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha512_keybytes(void);
|
||||
|
||||
#define crypto_kdf_hkdf_sha512_BYTES_MIN 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha512_bytes_min(void);
|
||||
|
||||
#define crypto_kdf_hkdf_sha512_BYTES_MAX (0xff * crypto_auth_hmacsha512_BYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha512_bytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha512_extract(unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES],
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *ikm, size_t ikm_len)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_kdf_hkdf_sha512_keygen(unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha512_expand(unsigned char *out, size_t out_len,
|
||||
const char *ctx, size_t ctx_len,
|
||||
const unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES])
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct crypto_kdf_hkdf_sha512_state {
|
||||
crypto_auth_hmacsha512_state st;
|
||||
} crypto_kdf_hkdf_sha512_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kdf_hkdf_sha512_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha512_extract_init(crypto_kdf_hkdf_sha512_state *state,
|
||||
const unsigned char *salt, size_t salt_len)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha512_extract_update(crypto_kdf_hkdf_sha512_state *state,
|
||||
const unsigned char *ikm, size_t ikm_len)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kdf_hkdf_sha512_extract_final(crypto_kdf_hkdf_sha512_state *state,
|
||||
unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,66 +0,0 @@
|
||||
#ifndef crypto_kx_H
|
||||
#define crypto_kx_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_kx_PUBLICKEYBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kx_publickeybytes(void);
|
||||
|
||||
#define crypto_kx_SECRETKEYBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kx_secretkeybytes(void);
|
||||
|
||||
#define crypto_kx_SEEDBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kx_seedbytes(void);
|
||||
|
||||
#define crypto_kx_SESSIONKEYBYTES 32
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_kx_sessionkeybytes(void);
|
||||
|
||||
#define crypto_kx_PRIMITIVE "x25519blake2b"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_kx_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kx_seed_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES],
|
||||
unsigned char sk[crypto_kx_SECRETKEYBYTES],
|
||||
const unsigned char seed[crypto_kx_SEEDBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kx_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES],
|
||||
unsigned char sk[crypto_kx_SECRETKEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
|
||||
unsigned char tx[crypto_kx_SESSIONKEYBYTES],
|
||||
const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES],
|
||||
const unsigned char client_sk[crypto_kx_SECRETKEYBYTES],
|
||||
const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES])
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
|
||||
unsigned char tx[crypto_kx_SESSIONKEYBYTES],
|
||||
const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES],
|
||||
const unsigned char server_sk[crypto_kx_SECRETKEYBYTES],
|
||||
const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES])
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 4, 5)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,65 +0,0 @@
|
||||
#ifndef crypto_onetimeauth_H
|
||||
#define crypto_onetimeauth_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_onetimeauth_poly1305.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef crypto_onetimeauth_poly1305_state crypto_onetimeauth_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_onetimeauth_statebytes(void);
|
||||
|
||||
#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_onetimeauth_bytes(void);
|
||||
|
||||
#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_onetimeauth_keybytes(void);
|
||||
|
||||
#define crypto_onetimeauth_PRIMITIVE "poly1305"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_onetimeauth_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_verify(const unsigned char *h, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_init(crypto_onetimeauth_state *state,
|
||||
const unsigned char *key) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_update(crypto_onetimeauth_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_final(crypto_onetimeauth_state *state,
|
||||
unsigned char *out) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_onetimeauth_keygen(unsigned char k[crypto_onetimeauth_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,72 +0,0 @@
|
||||
#ifndef crypto_onetimeauth_poly1305_H
|
||||
#define crypto_onetimeauth_poly1305_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_ALIGN(16) crypto_onetimeauth_poly1305_state {
|
||||
unsigned char opaque[256];
|
||||
} crypto_onetimeauth_poly1305_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_onetimeauth_poly1305_statebytes(void);
|
||||
|
||||
#define crypto_onetimeauth_poly1305_BYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_onetimeauth_poly1305_bytes(void);
|
||||
|
||||
#define crypto_onetimeauth_poly1305_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_onetimeauth_poly1305_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305(unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state,
|
||||
const unsigned char *key)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305_update(crypto_onetimeauth_poly1305_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state,
|
||||
unsigned char *out)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_onetimeauth_poly1305_keygen(unsigned char k[crypto_onetimeauth_poly1305_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,147 +0,0 @@
|
||||
#ifndef crypto_pwhash_H
|
||||
#define crypto_pwhash_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_pwhash_argon2i.h"
|
||||
#include "crypto_pwhash_argon2id.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_pwhash_ALG_ARGON2I13 crypto_pwhash_argon2i_ALG_ARGON2I13
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_alg_argon2i13(void);
|
||||
|
||||
#define crypto_pwhash_ALG_ARGON2ID13 crypto_pwhash_argon2id_ALG_ARGON2ID13
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_alg_argon2id13(void);
|
||||
|
||||
#define crypto_pwhash_ALG_DEFAULT crypto_pwhash_ALG_ARGON2ID13
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_alg_default(void);
|
||||
|
||||
#define crypto_pwhash_BYTES_MIN crypto_pwhash_argon2id_BYTES_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_BYTES_MAX crypto_pwhash_argon2id_BYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_PASSWD_MIN crypto_pwhash_argon2id_PASSWD_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_PASSWD_MAX crypto_pwhash_argon2id_PASSWD_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_SALTBYTES crypto_pwhash_argon2id_SALTBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_saltbytes(void);
|
||||
|
||||
#define crypto_pwhash_STRBYTES crypto_pwhash_argon2id_STRBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_strbytes(void);
|
||||
|
||||
#define crypto_pwhash_STRPREFIX crypto_pwhash_argon2id_STRPREFIX
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_MIN crypto_pwhash_argon2id_OPSLIMIT_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_MAX crypto_pwhash_argon2id_OPSLIMIT_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_MIN crypto_pwhash_argon2id_MEMLIMIT_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_MAX crypto_pwhash_argon2id_MEMLIMIT_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_INTERACTIVE crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_INTERACTIVE crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_MODERATE crypto_pwhash_argon2id_OPSLIMIT_MODERATE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_moderate(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_MODERATE crypto_pwhash_argon2id_MEMLIMIT_MODERATE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_moderate(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_SENSITIVE crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_sensitive(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_SENSITIVE crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_sensitive(void);
|
||||
|
||||
/*
|
||||
* With this function, do not forget to store all parameters, including the
|
||||
* algorithm identifier in order to produce deterministic output.
|
||||
* The crypto_pwhash_* definitions, including crypto_pwhash_ALG_DEFAULT,
|
||||
* may change.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash(unsigned char * const out, unsigned long long outlen,
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit, size_t memlimit, int alg)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
/*
|
||||
* The output string already includes all the required parameters, including
|
||||
* the algorithm identifier. The string is all that has to be stored in
|
||||
* order to verify a password.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES],
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
unsigned long long opslimit, size_t memlimit, int alg)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_str_verify(const char *str,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_str_needs_rehash(const char *str,
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#define crypto_pwhash_PRIMITIVE "argon2id,argon2i"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,122 +0,0 @@
|
||||
#ifndef crypto_pwhash_argon2i_H
|
||||
#define crypto_pwhash_argon2i_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_pwhash_argon2i_ALG_ARGON2I13 1
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2i_alg_argon2i13(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_BYTES_MIN 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 4294967295U)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_PASSWD_MIN 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_PASSWD_MAX 4294967295U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_SALTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_saltbytes(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_STRBYTES 128U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_strbytes(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_STRPREFIX "$argon2i$"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_argon2i_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_MIN 3U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_MAX 4294967295U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_MIN 8192U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_MAX \
|
||||
((SIZE_MAX >= 4398046510080U) ? 4398046510080U : (SIZE_MAX >= 2147483648U) ? 2147483648U : 32768U)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE 4U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE 33554432U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_MODERATE 6U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_moderate(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_MODERATE 134217728U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_moderate(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_sensitive(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE 536870912U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_sensitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2i(unsigned char * const out,
|
||||
unsigned long long outlen,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit, size_t memlimit,
|
||||
int alg)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2i_str(char out[crypto_pwhash_argon2i_STRBYTES],
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2i_str_verify(const char * str,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2i_str_needs_rehash(const char * str,
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,122 +0,0 @@
|
||||
#ifndef crypto_pwhash_argon2id_H
|
||||
#define crypto_pwhash_argon2id_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_pwhash_argon2id_ALG_ARGON2ID13 2
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2id_alg_argon2id13(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_BYTES_MIN 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 4294967295U)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_PASSWD_MIN 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_PASSWD_MAX 4294967295U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_SALTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_saltbytes(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_STRBYTES 128U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_strbytes(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_STRPREFIX "$argon2id$"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_argon2id_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_OPSLIMIT_MIN 1U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_OPSLIMIT_MAX 4294967295U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_MEMLIMIT_MIN 8192U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_MEMLIMIT_MAX \
|
||||
((SIZE_MAX >= 4398046510080U) ? 4398046510080U : (SIZE_MAX >= 2147483648U) ? 2147483648U : 32768U)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE 2U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_opslimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE 67108864U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_memlimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_OPSLIMIT_MODERATE 3U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_opslimit_moderate(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_MEMLIMIT_MODERATE 268435456U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_memlimit_moderate(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE 4U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_opslimit_sensitive(void);
|
||||
|
||||
#define crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE 1073741824U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2id_memlimit_sensitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2id(unsigned char * const out,
|
||||
unsigned long long outlen,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit, size_t memlimit,
|
||||
int alg)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2id_str(char out[crypto_pwhash_argon2id_STRBYTES],
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2id_str_verify(const char * str,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2id_str_needs_rehash(const char * str,
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,120 +0,0 @@
|
||||
#ifndef crypto_pwhash_scryptsalsa208sha256_H
|
||||
#define crypto_pwhash_scryptsalsa208sha256_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_BYTES_MIN 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_BYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX, 0x1fffffffe0ULL)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_SALTBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_saltbytes(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_STRBYTES 102U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_strbytes(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_STRPREFIX "$7$"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_scryptsalsa208sha256_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN 32768U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX 4294967295U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN 16777216U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX \
|
||||
SODIUM_MIN(SIZE_MAX, 68719476736ULL)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE 524288U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE 16777216U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_memlimit_interactive(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE 33554432U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE 1073741824U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256(unsigned char * const out,
|
||||
unsigned long long outlen,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit,
|
||||
size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha256_STRBYTES],
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
unsigned long long opslimit,
|
||||
size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_str_verify(const char * str,
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen,
|
||||
const uint8_t * salt, size_t saltlen,
|
||||
uint64_t N, uint32_t r, uint32_t p,
|
||||
uint8_t * buf, size_t buflen)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(const char * str,
|
||||
unsigned long long opslimit,
|
||||
size_t memlimit)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,46 +0,0 @@
|
||||
#ifndef crypto_scalarmult_H
|
||||
#define crypto_scalarmult_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_scalarmult_curve25519.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_bytes(void);
|
||||
|
||||
#define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_scalarbytes(void);
|
||||
|
||||
#define crypto_scalarmult_PRIMITIVE "curve25519"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_scalarmult_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_base(unsigned char *q, const unsigned char *n)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/*
|
||||
* NOTE: Do not use the result of this function directly for key exchange.
|
||||
*
|
||||
* Hash the result with the public keys in order to compute a shared
|
||||
* secret key: H(q || client_pk || server_pk)
|
||||
*
|
||||
* Or unless this is not an option, use the crypto_kx() API instead.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult(unsigned char *q, const unsigned char *n,
|
||||
const unsigned char *p)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,42 +0,0 @@
|
||||
#ifndef crypto_scalarmult_curve25519_H
|
||||
#define crypto_scalarmult_curve25519_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_scalarmult_curve25519_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_curve25519_bytes(void);
|
||||
|
||||
#define crypto_scalarmult_curve25519_SCALARBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_curve25519_scalarbytes(void);
|
||||
|
||||
/*
|
||||
* NOTE: Do not use the result of this function directly for key exchange.
|
||||
*
|
||||
* Hash the result with the public keys in order to compute a shared
|
||||
* secret key: H(q || client_pk || server_pk)
|
||||
*
|
||||
* Or unless this is not an option, use the crypto_kx() API instead.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,
|
||||
const unsigned char *p)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_curve25519_base(unsigned char *q,
|
||||
const unsigned char *n)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,51 +0,0 @@
|
||||
|
||||
#ifndef crypto_scalarmult_ed25519_H
|
||||
#define crypto_scalarmult_ed25519_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_scalarmult_ed25519_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_ed25519_bytes(void);
|
||||
|
||||
#define crypto_scalarmult_ed25519_SCALARBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_ed25519_scalarbytes(void);
|
||||
|
||||
/*
|
||||
* NOTE: Do not use the result of this function directly for key exchange.
|
||||
*
|
||||
* Hash the result with the public keys in order to compute a shared
|
||||
* secret key: H(q || client_pk || server_pk)
|
||||
*
|
||||
* Or unless this is not an option, use the crypto_kx() API instead.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n,
|
||||
const unsigned char *p)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_ed25519_noclamp(unsigned char *q, const unsigned char *n,
|
||||
const unsigned char *p)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_ed25519_base(unsigned char *q, const unsigned char *n)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_ed25519_base_noclamp(unsigned char *q, const unsigned char *n)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,43 +0,0 @@
|
||||
|
||||
#ifndef crypto_scalarmult_ristretto255_H
|
||||
#define crypto_scalarmult_ristretto255_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_scalarmult_ristretto255_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_ristretto255_bytes(void);
|
||||
|
||||
#define crypto_scalarmult_ristretto255_SCALARBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_scalarmult_ristretto255_scalarbytes(void);
|
||||
|
||||
/*
|
||||
* NOTE: Do not use the result of this function directly for key exchange.
|
||||
*
|
||||
* Hash the result with the public keys in order to compute a shared
|
||||
* secret key: H(q || client_pk || server_pk)
|
||||
*
|
||||
* Or unless this is not an option, use the crypto_kx() API instead.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_ristretto255(unsigned char *q, const unsigned char *n,
|
||||
const unsigned char *p)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_scalarmult_ristretto255_base(unsigned char *q,
|
||||
const unsigned char *n)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,93 +0,0 @@
|
||||
#ifndef crypto_secretbox_H
|
||||
#define crypto_secretbox_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_secretbox_xsalsa20poly1305.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_keybytes(void);
|
||||
|
||||
#define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_noncebytes(void);
|
||||
|
||||
#define crypto_secretbox_MACBYTES crypto_secretbox_xsalsa20poly1305_MACBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_macbytes(void);
|
||||
|
||||
#define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_secretbox_primitive(void);
|
||||
|
||||
#define crypto_secretbox_MESSAGEBYTES_MAX crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_easy(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_detached(unsigned char *c, unsigned char *mac,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_open_detached(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* -- NaCl compatibility interface ; Requires padding -- */
|
||||
|
||||
#define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_zerobytes(void);
|
||||
|
||||
#define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_boxzerobytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_open(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,70 +0,0 @@
|
||||
#ifndef crypto_secretbox_xchacha20poly1305_H
|
||||
#define crypto_secretbox_xchacha20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_stream_xchacha20.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_keybytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_noncebytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_MACBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_macbytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_MESSAGEBYTES_MAX \
|
||||
(crypto_stream_xchacha20_MESSAGEBYTES_MAX - crypto_secretbox_xchacha20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xchacha20poly1305_easy(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xchacha20poly1305_open_easy(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xchacha20poly1305_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 2, 5, 6)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,69 +0,0 @@
|
||||
#ifndef crypto_secretbox_xsalsa20poly1305_H
|
||||
#define crypto_secretbox_xsalsa20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_stream_xsalsa20.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_secretbox_xsalsa20poly1305_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xsalsa20poly1305_keybytes(void);
|
||||
|
||||
#define crypto_secretbox_xsalsa20poly1305_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xsalsa20poly1305_noncebytes(void);
|
||||
|
||||
#define crypto_secretbox_xsalsa20poly1305_MACBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xsalsa20poly1305_macbytes(void);
|
||||
|
||||
/* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */
|
||||
#define crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX \
|
||||
(crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_secretbox_xsalsa20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xsalsa20poly1305_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xsalsa20poly1305(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xsalsa20poly1305_open(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_secretbox_xsalsa20poly1305_keygen(unsigned char k[crypto_secretbox_xsalsa20poly1305_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* -- NaCl compatibility interface ; Requires padding -- */
|
||||
|
||||
#define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xsalsa20poly1305_boxzerobytes(void);
|
||||
|
||||
#define crypto_secretbox_xsalsa20poly1305_ZEROBYTES \
|
||||
(crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES + \
|
||||
crypto_secretbox_xsalsa20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xsalsa20poly1305_zerobytes(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,108 +0,0 @@
|
||||
#ifndef crypto_secretstream_xchacha20poly1305_H
|
||||
#define crypto_secretstream_xchacha20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_aead_xchacha20poly1305.h"
|
||||
#include "crypto_stream_chacha20.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_ABYTES \
|
||||
(1U + crypto_aead_xchacha20poly1305_ietf_ABYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretstream_xchacha20poly1305_abytes(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_HEADERBYTES \
|
||||
crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretstream_xchacha20poly1305_headerbytes(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_KEYBYTES \
|
||||
crypto_aead_xchacha20poly1305_ietf_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretstream_xchacha20poly1305_keybytes(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES, \
|
||||
(64ULL * ((1ULL << 32) - 2ULL)))
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretstream_xchacha20poly1305_messagebytes_max(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_TAG_MESSAGE 0x00
|
||||
SODIUM_EXPORT
|
||||
unsigned char crypto_secretstream_xchacha20poly1305_tag_message(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_TAG_PUSH 0x01
|
||||
SODIUM_EXPORT
|
||||
unsigned char crypto_secretstream_xchacha20poly1305_tag_push(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_TAG_REKEY 0x02
|
||||
SODIUM_EXPORT
|
||||
unsigned char crypto_secretstream_xchacha20poly1305_tag_rekey(void);
|
||||
|
||||
#define crypto_secretstream_xchacha20poly1305_TAG_FINAL \
|
||||
(crypto_secretstream_xchacha20poly1305_TAG_PUSH | \
|
||||
crypto_secretstream_xchacha20poly1305_TAG_REKEY)
|
||||
SODIUM_EXPORT
|
||||
unsigned char crypto_secretstream_xchacha20poly1305_tag_final(void);
|
||||
|
||||
typedef struct crypto_secretstream_xchacha20poly1305_state {
|
||||
unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES];
|
||||
unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES];
|
||||
unsigned char _pad[8];
|
||||
} crypto_secretstream_xchacha20poly1305_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretstream_xchacha20poly1305_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_secretstream_xchacha20poly1305_keygen
|
||||
(unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretstream_xchacha20poly1305_init_push
|
||||
(crypto_secretstream_xchacha20poly1305_state *state,
|
||||
unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
|
||||
const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretstream_xchacha20poly1305_push
|
||||
(crypto_secretstream_xchacha20poly1305_state *state,
|
||||
unsigned char *c, unsigned long long *clen_p,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *ad, unsigned long long adlen, unsigned char tag)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretstream_xchacha20poly1305_init_pull
|
||||
(crypto_secretstream_xchacha20poly1305_state *state,
|
||||
const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
|
||||
const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretstream_xchacha20poly1305_pull
|
||||
(crypto_secretstream_xchacha20poly1305_state *state,
|
||||
unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,
|
||||
const unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *ad, unsigned long long adlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_secretstream_xchacha20poly1305_rekey
|
||||
(crypto_secretstream_xchacha20poly1305_state *state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,41 +0,0 @@
|
||||
#ifndef crypto_shorthash_H
|
||||
#define crypto_shorthash_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_shorthash_siphash24.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_shorthash_BYTES crypto_shorthash_siphash24_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_shorthash_bytes(void);
|
||||
|
||||
#define crypto_shorthash_KEYBYTES crypto_shorthash_siphash24_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_shorthash_keybytes(void);
|
||||
|
||||
#define crypto_shorthash_PRIMITIVE "siphash24"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_shorthash_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_shorthash(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,50 +0,0 @@
|
||||
#ifndef crypto_shorthash_siphash24_H
|
||||
#define crypto_shorthash_siphash24_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -- 64-bit output -- */
|
||||
|
||||
#define crypto_shorthash_siphash24_BYTES 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_shorthash_siphash24_bytes(void);
|
||||
|
||||
#define crypto_shorthash_siphash24_KEYBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_shorthash_siphash24_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_shorthash_siphash24(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
|
||||
#ifndef SODIUM_LIBRARY_MINIMAL
|
||||
/* -- 128-bit output -- */
|
||||
|
||||
#define crypto_shorthash_siphashx24_BYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_shorthash_siphashx24_bytes(void);
|
||||
|
||||
#define crypto_shorthash_siphashx24_KEYBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_shorthash_siphashx24_keybytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((nonnull(1, 4)));
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,107 +0,0 @@
|
||||
#ifndef crypto_sign_H
|
||||
#define crypto_sign_H
|
||||
|
||||
/*
|
||||
* THREAD SAFETY: crypto_sign_keypair() is thread-safe,
|
||||
* provided that sodium_init() was called before.
|
||||
*
|
||||
* Other functions, including crypto_sign_seed_keypair() are always thread-safe.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_sign_ed25519.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef crypto_sign_ed25519ph_state crypto_sign_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_statebytes(void);
|
||||
|
||||
#define crypto_sign_BYTES crypto_sign_ed25519_BYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_bytes(void);
|
||||
|
||||
#define crypto_sign_SEEDBYTES crypto_sign_ed25519_SEEDBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_seedbytes(void);
|
||||
|
||||
#define crypto_sign_PUBLICKEYBYTES crypto_sign_ed25519_PUBLICKEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_publickeybytes(void);
|
||||
|
||||
#define crypto_sign_SECRETKEYBYTES crypto_sign_ed25519_SECRETKEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_secretkeybytes(void);
|
||||
|
||||
#define crypto_sign_MESSAGEBYTES_MAX crypto_sign_ed25519_MESSAGEBYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_messagebytes_max(void);
|
||||
|
||||
#define crypto_sign_PRIMITIVE "ed25519"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_sign_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||
const unsigned char *seed)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign(unsigned char *sm, unsigned long long *smlen_p,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *sk) __attribute__ ((nonnull(1, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_open(unsigned char *m, unsigned long long *mlen_p,
|
||||
const unsigned char *sm, unsigned long long smlen,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *sk) __attribute__ ((nonnull(1, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_verify_detached(const unsigned char *sig,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_init(crypto_sign_state *state);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_update(crypto_sign_state *state,
|
||||
const unsigned char *m, unsigned long long mlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig,
|
||||
unsigned long long *siglen_p,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((nonnull(1, 2, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,124 +0,0 @@
|
||||
#ifndef crypto_sign_ed25519_H
|
||||
#define crypto_sign_ed25519_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct crypto_sign_ed25519ph_state {
|
||||
crypto_hash_sha512_state hs;
|
||||
} crypto_sign_ed25519ph_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_ed25519ph_statebytes(void);
|
||||
|
||||
#define crypto_sign_ed25519_BYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_ed25519_bytes(void);
|
||||
|
||||
#define crypto_sign_ed25519_SEEDBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_ed25519_seedbytes(void);
|
||||
|
||||
#define crypto_sign_ed25519_PUBLICKEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_ed25519_publickeybytes(void);
|
||||
|
||||
#define crypto_sign_ed25519_SECRETKEYBYTES (32U + 32U)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_ed25519_secretkeybytes(void);
|
||||
|
||||
#define crypto_sign_ed25519_MESSAGEBYTES_MAX (SODIUM_SIZE_MAX - crypto_sign_ed25519_BYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_sign_ed25519_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519(unsigned char *sm, unsigned long long *smlen_p,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((nonnull(1, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_open(unsigned char *m, unsigned long long *mlen_p,
|
||||
const unsigned char *sm, unsigned long long smlen,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_detached(unsigned char *sig,
|
||||
unsigned long long *siglen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((nonnull(1, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_verify_detached(const unsigned char *sig,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_keypair(unsigned char *pk, unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||
const unsigned char *seed)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
|
||||
const unsigned char *ed25519_pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
|
||||
const unsigned char *ed25519_sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_sk_to_seed(unsigned char *seed,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519ph_init(crypto_sign_ed25519ph_state *state)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519ph_update(crypto_sign_ed25519ph_state *state,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519ph_final_create(crypto_sign_ed25519ph_state *state,
|
||||
unsigned char *sig,
|
||||
unsigned long long *siglen_p,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((nonnull(1, 2, 4)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519ph_final_verify(crypto_sign_ed25519ph_state *state,
|
||||
const unsigned char *sig,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,55 +0,0 @@
|
||||
#ifndef crypto_sign_edwards25519sha512batch_H
|
||||
#define crypto_sign_edwards25519sha512batch_H
|
||||
|
||||
/*
|
||||
* WARNING: This construction was a prototype, which should not be used
|
||||
* any more in new projects.
|
||||
*
|
||||
* crypto_sign_edwards25519sha512batch is provided for applications
|
||||
* initially built with NaCl, but as recommended by the author of this
|
||||
* construction, new applications should use ed25519 instead.
|
||||
*
|
||||
* In Sodium, you should use the high-level crypto_sign_*() functions instead.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_sign_edwards25519sha512batch_BYTES 64U
|
||||
#define crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES 32U
|
||||
#define crypto_sign_edwards25519sha512batch_SECRETKEYBYTES (32U + 32U)
|
||||
#define crypto_sign_edwards25519sha512batch_MESSAGEBYTES_MAX (SODIUM_SIZE_MAX - crypto_sign_edwards25519sha512batch_BYTES)
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_edwards25519sha512batch(unsigned char *sm,
|
||||
unsigned long long *smlen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((deprecated)) __attribute__ ((nonnull(1, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_edwards25519sha512batch_open(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
const unsigned char *sm,
|
||||
unsigned long long smlen,
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((deprecated)) __attribute__ ((nonnull(3, 5)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk,
|
||||
unsigned char *sk)
|
||||
__attribute__ ((deprecated)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,59 +0,0 @@
|
||||
#ifndef crypto_stream_H
|
||||
#define crypto_stream_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "crypto_stream_xsalsa20.h"
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_keybytes(void);
|
||||
|
||||
#define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_noncebytes(void);
|
||||
|
||||
#define crypto_stream_MESSAGEBYTES_MAX crypto_stream_xsalsa20_MESSAGEBYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_messagebytes_max(void);
|
||||
|
||||
#define crypto_stream_PRIMITIVE "xsalsa20"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_stream_primitive(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,106 +0,0 @@
|
||||
#ifndef crypto_stream_chacha20_H
|
||||
#define crypto_stream_chacha20_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_chacha20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_chacha20_keybytes(void);
|
||||
|
||||
#define crypto_stream_chacha20_NONCEBYTES 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_chacha20_noncebytes(void);
|
||||
|
||||
#define crypto_stream_chacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_chacha20_messagebytes_max(void);
|
||||
|
||||
/* ChaCha20 with a 64-bit nonce and a 64-bit counter, as originally designed */
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_chacha20(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* ChaCha20 with a 96-bit nonce and a 32-bit counter (IETF) */
|
||||
|
||||
#define crypto_stream_chacha20_ietf_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_chacha20_ietf_keybytes(void);
|
||||
|
||||
#define crypto_stream_chacha20_ietf_NONCEBYTES 12U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_chacha20_ietf_noncebytes(void);
|
||||
|
||||
#define crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX \
|
||||
SODIUM_MIN(SODIUM_SIZE_MAX, 64ULL * (1ULL << 32))
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_chacha20_ietf_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint32_t ic,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_chacha20_ietf_keygen(unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* Aliases */
|
||||
|
||||
#define crypto_stream_chacha20_IETF_KEYBYTES crypto_stream_chacha20_ietf_KEYBYTES
|
||||
#define crypto_stream_chacha20_IETF_NONCEBYTES crypto_stream_chacha20_ietf_NONCEBYTES
|
||||
#define crypto_stream_chacha20_IETF_MESSAGEBYTES_MAX crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,61 +0,0 @@
|
||||
#ifndef crypto_stream_salsa20_H
|
||||
#define crypto_stream_salsa20_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_salsa20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa20_keybytes(void);
|
||||
|
||||
#define crypto_stream_salsa20_NONCEBYTES 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa20_noncebytes(void);
|
||||
|
||||
#define crypto_stream_salsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa20_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa20(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_salsa20_keygen(unsigned char k[crypto_stream_salsa20_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,53 +0,0 @@
|
||||
#ifndef crypto_stream_salsa2012_H
|
||||
#define crypto_stream_salsa2012_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_salsa2012_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa2012_keybytes(void);
|
||||
|
||||
#define crypto_stream_salsa2012_NONCEBYTES 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa2012_noncebytes(void);
|
||||
|
||||
#define crypto_stream_salsa2012_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa2012_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa2012(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_salsa2012_keygen(unsigned char k[crypto_stream_salsa2012_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,56 +0,0 @@
|
||||
#ifndef crypto_stream_salsa208_H
|
||||
#define crypto_stream_salsa208_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_salsa208_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa208_keybytes(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
#define crypto_stream_salsa208_NONCEBYTES 8U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa208_noncebytes(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
#define crypto_stream_salsa208_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_salsa208_messagebytes_max(void)
|
||||
__attribute__ ((deprecated));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa208(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((deprecated)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_salsa208_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((deprecated)) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_salsa208_keygen(unsigned char k[crypto_stream_salsa208_KEYBYTES])
|
||||
__attribute__ ((deprecated)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,61 +0,0 @@
|
||||
#ifndef crypto_stream_xchacha20_H
|
||||
#define crypto_stream_xchacha20_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_xchacha20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_xchacha20_keybytes(void);
|
||||
|
||||
#define crypto_stream_xchacha20_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_xchacha20_noncebytes(void);
|
||||
|
||||
#define crypto_stream_xchacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_xchacha20_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xchacha20(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,61 +0,0 @@
|
||||
#ifndef crypto_stream_xsalsa20_H
|
||||
#define crypto_stream_xsalsa20_H
|
||||
|
||||
/*
|
||||
* WARNING: This is just a stream cipher. It is NOT authenticated encryption.
|
||||
* While it provides some protection against eavesdropping, it does NOT
|
||||
* provide any security against active attacks.
|
||||
* Unless you know what you're doing, what you are looking for is probably
|
||||
* the crypto_box functions.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_stream_xsalsa20_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_xsalsa20_keybytes(void);
|
||||
|
||||
#define crypto_stream_xsalsa20_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_xsalsa20_noncebytes(void);
|
||||
|
||||
#define crypto_stream_xsalsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_stream_xsalsa20_messagebytes_max(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xsalsa20(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xsalsa20_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream_xsalsa20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void crypto_stream_xsalsa20_keygen(unsigned char k[crypto_stream_xsalsa20_KEYBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,23 +0,0 @@
|
||||
#ifndef crypto_verify_16_H
|
||||
#define crypto_verify_16_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_verify_16_BYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_verify_16_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_verify_16(const unsigned char *x, const unsigned char *y)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,23 +0,0 @@
|
||||
#ifndef crypto_verify_32_H
|
||||
#define crypto_verify_32_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_verify_32_BYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_verify_32_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_verify_32(const unsigned char *x, const unsigned char *y)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,23 +0,0 @@
|
||||
#ifndef crypto_verify_64_H
|
||||
#define crypto_verify_64_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_verify_64_BYTES 64U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_verify_64_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_verify_64(const unsigned char *x, const unsigned char *y)
|
||||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,57 +0,0 @@
|
||||
|
||||
#ifndef sodium_export_H
|
||||
#define sodium_export_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if !defined(__clang__) && !defined(__GNUC__)
|
||||
# ifdef __attribute__
|
||||
# undef __attribute__
|
||||
# endif
|
||||
# define __attribute__(a)
|
||||
#endif
|
||||
|
||||
#ifdef SODIUM_STATIC
|
||||
# define SODIUM_EXPORT
|
||||
# define SODIUM_EXPORT_WEAK
|
||||
#else
|
||||
# if defined(_MSC_VER)
|
||||
# ifdef SODIUM_DLL_EXPORT
|
||||
# define SODIUM_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define SODIUM_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# if defined(__SUNPRO_C)
|
||||
# ifndef __GNU_C__
|
||||
# define SODIUM_EXPORT __attribute__ (visibility(__global))
|
||||
# else
|
||||
# define SODIUM_EXPORT __attribute__ __global
|
||||
# endif
|
||||
# elif defined(_MSG_VER)
|
||||
# define SODIUM_EXPORT extern __declspec(dllexport)
|
||||
# else
|
||||
# define SODIUM_EXPORT __attribute__ ((visibility ("default")))
|
||||
# endif
|
||||
# endif
|
||||
# if defined(__ELF__) && !defined(SODIUM_DISABLE_WEAK_FUNCTIONS)
|
||||
# define SODIUM_EXPORT_WEAK SODIUM_EXPORT __attribute__((weak))
|
||||
# else
|
||||
# define SODIUM_EXPORT_WEAK SODIUM_EXPORT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CRYPTO_ALIGN
|
||||
# if defined(__INTEL_COMPILER) || defined(_MSC_VER)
|
||||
# define CRYPTO_ALIGN(x) __declspec(align(x))
|
||||
# else
|
||||
# define CRYPTO_ALIGN(x) __attribute__ ((aligned(x)))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)
|
||||
|
||||
#endif
|
||||
@ -1,72 +0,0 @@
|
||||
|
||||
#ifndef randombytes_H
|
||||
#define randombytes_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct randombytes_implementation {
|
||||
const char *(*implementation_name)(void); /* required */
|
||||
uint32_t (*random)(void); /* required */
|
||||
void (*stir)(void); /* optional */
|
||||
uint32_t (*uniform)(const uint32_t upper_bound); /* optional, a default implementation will be used if NULL */
|
||||
void (*buf)(void * const buf, const size_t size); /* required */
|
||||
int (*close)(void); /* optional */
|
||||
} randombytes_implementation;
|
||||
|
||||
#define randombytes_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 0xffffffffUL)
|
||||
|
||||
#define randombytes_SEEDBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t randombytes_seedbytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_buf(void * const buf, const size_t size)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_buf_deterministic(void * const buf, const size_t size,
|
||||
const unsigned char seed[randombytes_SEEDBYTES])
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_random(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_uniform(const uint32_t upper_bound);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_stir(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int randombytes_close(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int randombytes_set_implementation(const randombytes_implementation *impl)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_implementation_name(void);
|
||||
|
||||
/* -- NaCl compatibility interface -- */
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes(unsigned char * const buf, const unsigned long long buf_len)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,22 +0,0 @@
|
||||
|
||||
#ifndef randombytes_internal_random_H
|
||||
#define randombytes_internal_random_H
|
||||
|
||||
#include "export.h"
|
||||
#include "randombytes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_internal_implementation;
|
||||
|
||||
/* Backwards compatibility with libsodium < 1.0.18 */
|
||||
#define randombytes_salsa20_implementation randombytes_internal_implementation
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,19 +0,0 @@
|
||||
|
||||
#ifndef randombytes_sysrandom_H
|
||||
#define randombytes_sysrandom_H
|
||||
|
||||
#include "export.h"
|
||||
#include "randombytes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_sysrandom_implementation;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,55 +0,0 @@
|
||||
|
||||
#ifndef sodium_runtime_H
|
||||
#define sodium_runtime_H
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_neon(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_armcrypto(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_sse2(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_sse3(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_ssse3(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_sse41(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_avx(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_avx2(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_avx512f(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_pclmul(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_aesni(void);
|
||||
|
||||
SODIUM_EXPORT_WEAK
|
||||
int sodium_runtime_has_rdrand(void);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int _sodium_runtime_get_cpu_features(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,179 +0,0 @@
|
||||
|
||||
#ifndef sodium_utils_H
|
||||
#define sodium_utils_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef SODIUM_C99
|
||||
# if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
|
||||
# define SODIUM_C99(X)
|
||||
# else
|
||||
# define SODIUM_C99(X) X
|
||||
# endif
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_memzero(void * const pnt, const size_t len);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_stackzero(const size_t len);
|
||||
|
||||
/*
|
||||
* WARNING: sodium_memcmp() must be used to verify if two secret keys
|
||||
* are equal, in constant time.
|
||||
* It returns 0 if the keys are equal, and -1 if they differ.
|
||||
* This function is not designed for lexicographical comparisons.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/*
|
||||
* sodium_compare() returns -1 if b1_ < b2_, 1 if b1_ > b2_ and 0 if b1_ == b2_
|
||||
* It is suitable for lexicographical comparisons, or to compare nonces
|
||||
* and counters stored in little-endian format.
|
||||
* However, it is slower than sodium_memcmp().
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int sodium_compare(const unsigned char *b1_, const unsigned char *b2_,
|
||||
size_t len) __attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_is_zero(const unsigned char *n, const size_t nlen);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_increment(unsigned char *n, const size_t nlen);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_add(unsigned char *a, const unsigned char *b, const size_t len);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_sub(unsigned char *a, const unsigned char *b, const size_t len);
|
||||
|
||||
SODIUM_EXPORT
|
||||
char *sodium_bin2hex(char * const hex, const size_t hex_maxlen,
|
||||
const unsigned char * const bin, const size_t bin_len)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen,
|
||||
const char * const hex, const size_t hex_len,
|
||||
const char * const ignore, size_t * const bin_len,
|
||||
const char ** const hex_end)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
#define sodium_base64_VARIANT_ORIGINAL 1
|
||||
#define sodium_base64_VARIANT_ORIGINAL_NO_PADDING 3
|
||||
#define sodium_base64_VARIANT_URLSAFE 5
|
||||
#define sodium_base64_VARIANT_URLSAFE_NO_PADDING 7
|
||||
|
||||
/*
|
||||
* Computes the required length to encode BIN_LEN bytes as a base64 string
|
||||
* using the given variant. The computed length includes a trailing \0.
|
||||
*/
|
||||
#define sodium_base64_ENCODED_LEN(BIN_LEN, VARIANT) \
|
||||
(((BIN_LEN) / 3U) * 4U + \
|
||||
((((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) | (((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) >> 1)) & 1U) * \
|
||||
(4U - (~((((VARIANT) & 2U) >> 1) - 1U) & (3U - ((BIN_LEN) - ((BIN_LEN) / 3U) * 3U)))) + 1U)
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t sodium_base64_encoded_len(const size_t bin_len, const int variant);
|
||||
|
||||
SODIUM_EXPORT
|
||||
char *sodium_bin2base64(char * const b64, const size_t b64_maxlen,
|
||||
const unsigned char * const bin, const size_t bin_len,
|
||||
const int variant) __attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_base642bin(unsigned char * const bin, const size_t bin_maxlen,
|
||||
const char * const b64, const size_t b64_len,
|
||||
const char * const ignore, size_t * const bin_len,
|
||||
const char ** const b64_end, const int variant)
|
||||
__attribute__ ((nonnull(1)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_mlock(void * const addr, const size_t len)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_munlock(void * const addr, const size_t len)
|
||||
__attribute__ ((nonnull));
|
||||
|
||||
/* WARNING: sodium_malloc() and sodium_allocarray() are not general-purpose
|
||||
* allocation functions.
|
||||
*
|
||||
* They return a pointer to a region filled with 0xd0 bytes, immediately
|
||||
* followed by a guard page.
|
||||
* As a result, accessing a single byte after the requested allocation size
|
||||
* will intentionally trigger a segmentation fault.
|
||||
*
|
||||
* A canary and an additional guard page placed before the beginning of the
|
||||
* region may also kill the process if a buffer underflow is detected.
|
||||
*
|
||||
* The memory layout is:
|
||||
* [unprotected region size (read only)][guard page (no access)][unprotected pages (read/write)][guard page (no access)]
|
||||
* With the layout of the unprotected pages being:
|
||||
* [optional padding][16-bytes canary][user region]
|
||||
*
|
||||
* However:
|
||||
* - These functions are significantly slower than standard functions
|
||||
* - Each allocation requires 3 or 4 additional pages
|
||||
* - The returned address will not be aligned if the allocation size is not
|
||||
* a multiple of the required alignment. For this reason, these functions
|
||||
* are designed to store data, such as secret keys and messages.
|
||||
*
|
||||
* sodium_malloc() can be used to allocate any libsodium data structure.
|
||||
*
|
||||
* The crypto_generichash_state structure is packed and its length is
|
||||
* either 357 or 361 bytes. For this reason, when using sodium_malloc() to
|
||||
* allocate a crypto_generichash_state structure, padding must be added in
|
||||
* order to ensure proper alignment. crypto_generichash_statebytes()
|
||||
* returns the rounded up structure size, and should be preferred to sizeof():
|
||||
* state = sodium_malloc(crypto_generichash_statebytes());
|
||||
*/
|
||||
|
||||
SODIUM_EXPORT
|
||||
void *sodium_malloc(const size_t size)
|
||||
__attribute__ ((malloc));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void *sodium_allocarray(size_t count, size_t size)
|
||||
__attribute__ ((malloc));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_free(void *ptr);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_mprotect_noaccess(void *ptr) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_mprotect_readonly(void *ptr) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_mprotect_readwrite(void *ptr) __attribute__ ((nonnull));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
||||
size_t unpadded_buflen, size_t blocksize, size_t max_buflen)
|
||||
__attribute__ ((nonnull(2)));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
|
||||
size_t padded_buflen, size_t blocksize)
|
||||
__attribute__ ((nonnull(2)));
|
||||
|
||||
/* -------- */
|
||||
|
||||
int _sodium_alloc_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,33 +0,0 @@
|
||||
|
||||
#ifndef sodium_version_H
|
||||
#define sodium_version_H
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#define SODIUM_VERSION_STRING "1.0.20"
|
||||
|
||||
#define SODIUM_LIBRARY_VERSION_MAJOR 26
|
||||
#define SODIUM_LIBRARY_VERSION_MINOR 2
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *sodium_version_string(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_library_version_major(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_library_version_minor(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_library_minimal(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
19
main.cpp
19
main.cpp
@ -1,9 +1,7 @@
|
||||
#include "widget.h"
|
||||
#include "licesing.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include "globals.h"
|
||||
#include "license_dialog.h"
|
||||
|
||||
// 全局变量存储原始的消息处理器
|
||||
QtMessageHandler originalHandler = nullptr;
|
||||
@ -22,11 +20,26 @@ void customMessageHandler(QtMsgType type, const QMessageLogContext &context, con
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
// // 调用 iniLowMac 函数初始化与下位机的连接
|
||||
// if (!iniLowMac()) {
|
||||
// qDebug() << "Failed to initialize connection.";
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
// 安装自定义消息处理器,保存原始处理器
|
||||
originalHandler = qInstallMessageHandler(customMessageHandler);
|
||||
|
||||
|
||||
// QFile file("C:/Users/Administrator/Documents/cotton_double/styles/style.qss"); // 或者使用文件路径
|
||||
// if (file.open(QFile::ReadOnly)) {
|
||||
// QString styleSheet = QLatin1String(file.readAll());
|
||||
// qApp->setStyleSheet(styleSheet);
|
||||
// }
|
||||
|
||||
|
||||
Widget w;
|
||||
// 设置窗口标志以隐藏标题栏和边框,并确保窗口是顶级窗口
|
||||
w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint /*| Qt::WindowStaysOnTopHint*/);
|
||||
|
||||
@ -47,20 +47,6 @@ yellow_a_max = 7
|
||||
yellow_b_min = 20
|
||||
yellow_b_max = 21
|
||||
|
||||
expansionRaidus = 1
|
||||
file_delay = 1180
|
||||
lab_denoising = 1
|
||||
lowmac_dp = 350
|
||||
lowmac_sg = 70
|
||||
lowmac_sm = 1200
|
||||
lowmac_td = 7
|
||||
lowmac_ts = 10
|
||||
machine_num = 0
|
||||
max_valves_together = 18
|
||||
saturation_denoising = 1
|
||||
saturation_threshold = 165
|
||||
screen_left_0 = 0
|
||||
screen_left_1 = 0
|
||||
screen_right_0 = 10
|
||||
screen_right_1 = 0
|
||||
sizeThreshold = 4
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// storageworker.cpp
|
||||
#include "storage_worker.h"
|
||||
#include "storageworker.h"
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
@ -1,6 +1,6 @@
|
||||
// storageworker.h
|
||||
#ifndef STORAGE_WORKER_H
|
||||
#define STORAGE_WORKER_H
|
||||
#ifndef STORAGEWORKER_H
|
||||
#define STORAGEWORKER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <opencv2/opencv.hpp>
|
||||
@ -20,4 +20,4 @@ private:
|
||||
QString getSaveDirectory(); // 获取保存目录的函数
|
||||
};
|
||||
|
||||
#endif // STORAGE_WORKER_H
|
||||
#endif // STORAGEWORKER_H
|
||||
1213
ui_widget.h
1213
ui_widget.h
File diff suppressed because it is too large
Load Diff
527
widget.cpp
527
widget.cpp
@ -14,8 +14,8 @@
|
||||
#include <QDateTime>
|
||||
#include <QTabBar>
|
||||
#include <img_utils.h>
|
||||
#include <detection_worker.h>
|
||||
#include <QString>
|
||||
#include <detectionworker.h>
|
||||
#include <Qstring>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
@ -23,54 +23,29 @@
|
||||
#include <cctype>
|
||||
#include <warning.h>
|
||||
#include <QMessageBox>
|
||||
#include "license_dialog.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// 硬编码参数值
|
||||
int file_delay = 1100; // 延迟时间(毫秒)
|
||||
int file_delay = 1180; // 延迟时间(毫秒)
|
||||
int file_encoder = 12000; // 行频
|
||||
int file_valve = 200; // 喷阀触发频率
|
||||
|
||||
//下位机参数
|
||||
int lowmac_dp = 350; //偏振延迟时间
|
||||
int lowmac_sm = 1800; //吹气量 valve/12 = 吹气时间ms
|
||||
int lowmac_sm = 1200; //吹气量 valve/12 = 吹气时间ms
|
||||
int lowmac_ts = 10; //模板匹配阈值
|
||||
int lowmac_sg = 65; //偏振绿色通道大小阈值
|
||||
int lowmac_td = 7; //偏振红色通道差值
|
||||
|
||||
Widget::Widget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::Widget)
|
||||
{ m_lic = new Licesing();
|
||||
// 1. 用户给定 SSH 公钥
|
||||
QString sshEd25519Key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAt0TioFZxdeimnBJE3s/QMrefCqZyw+nhj1ZfRFTu9s lizhenye@lzyMacBook.local";
|
||||
// 2. 解析32字节
|
||||
QByteArray pubKey32 = Licesing::parseEd25519FromSshPubKey(sshEd25519Key);
|
||||
if (pubKey32.isEmpty()) {
|
||||
qWarning() << "Failed to parse 32-byte pubkey";
|
||||
}
|
||||
|
||||
// 3. 创建 Licesing 对象
|
||||
m_lic->setPublicKey(pubKey32);
|
||||
|
||||
// 4. 检查 License
|
||||
bool license_ok = m_lic->checkLocalLicense(getConfigDirectory() + "/license.json"); // 读文件
|
||||
if (!license_ok){
|
||||
// start the first request if we got invalid license
|
||||
m_lic->requestNewCertificate(m_lic->serverRenewAddress, m_lic->getLocalMac());
|
||||
}
|
||||
else {
|
||||
qDebug() << "License verified successfully.";
|
||||
}
|
||||
connect(m_lic, &Licesing::certificateFailedManyTimes, this, &Widget::onCertificateRequestFailed);
|
||||
|
||||
{
|
||||
this->isCamRunning = false;
|
||||
this->isLicenseValid = false;
|
||||
ui->setupUi(this);
|
||||
|
||||
// 确认 tabWidget 是 QTabWidget 类型并隐藏tab
|
||||
// 确认 tabWidget 是 QTabWidget 类型
|
||||
QTabWidget* tab = qobject_cast<QTabWidget*>(ui->tabWidget);
|
||||
if (tab) {
|
||||
QTabBar* tabBar = tab->tabBar();
|
||||
@ -82,22 +57,20 @@ Widget::Widget(QWidget *parent)
|
||||
} else {
|
||||
qWarning() << "ui->tabWidget 不是 QTabWidget 类型!";
|
||||
}
|
||||
|
||||
ui->camera_0_img->setScaledContents(false);
|
||||
ui->camera_1_img->setScaledContents(false);
|
||||
|
||||
iniOnnx();
|
||||
// iniColor();
|
||||
loadConfig(getConfigDirectory()+"/color_range_config.txt"); // 读取配置文件
|
||||
loadConfig(getConfigDirectory()+"/color_range_config.txt");
|
||||
iniLowMac();
|
||||
iniCamera();
|
||||
|
||||
// 更新界面
|
||||
update_main_settings(); // 更新主要设定
|
||||
update_colorlist(); // 更新色彩列表
|
||||
update_polar(); // 更新偏振相机界面
|
||||
|
||||
update_colorlist();
|
||||
// 初始化存储工作者和线程
|
||||
storageWorker = new StorageWorker();
|
||||
storageWorker->moveToThread(&storageThread);
|
||||
|
||||
connect(&storageThread, &QThread::started, storageWorker, &StorageWorker::process);
|
||||
connect(this, &Widget::destroyed, &storageThread, &QThread::quit);
|
||||
connect(&storageThread, &QThread::finished, storageWorker, &QObject::deleteLater);
|
||||
@ -107,191 +80,24 @@ Widget::Widget(QWidget *parent)
|
||||
// 启动显示定时器,每秒检查一次
|
||||
QTimer* timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, &Widget::refreshImage);
|
||||
timer->start(40); // 每40毫秒秒刷新一次界面
|
||||
|
||||
// 启动PLC定时器,每秒检查一次
|
||||
plc_connector = std::make_unique<PLCConnector>(params["machine_num"]);
|
||||
QTimer* timer_plc = new QTimer(this);
|
||||
connect(timer_plc, &QTimer::timeout, this, &Widget::heart_beat);
|
||||
heart_beat();
|
||||
timer_plc->start(30000); // 每30秒发送一次心跳包
|
||||
|
||||
// 启动PLC定时器,每秒检查一次
|
||||
QTimer* timer_lower = new QTimer(this);
|
||||
connect(timer_lower, &QTimer::timeout, this, &Widget::check_lower_machine);
|
||||
check_lower_machine(); // 先尝试一次连接
|
||||
timer_lower->start(10000); // 每10秒检查一次FPGA的状态
|
||||
timer->start(40); // 每50毫秒秒刷新一次界面
|
||||
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
showStartupCountdown();
|
||||
}
|
||||
|
||||
void Widget::check_lower_machine(){
|
||||
if(g_lower_machine_connected.load()){
|
||||
return;
|
||||
}
|
||||
bool temp_status = iniLowMac();
|
||||
g_lower_machine_connected.store(temp_status);
|
||||
if(temp_status)
|
||||
{ this->ui->lab_fpga->setStyleSheet(
|
||||
"QLabel{"
|
||||
"background-color: green;"
|
||||
"color: white;"
|
||||
"border: 1px solid black;"
|
||||
"padding: 5px;"
|
||||
"border-radius: 5px;"
|
||||
"font: 20pt \"Microsoft YaHei UI\";"
|
||||
"}"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui->lab_fpga->setStyleSheet(
|
||||
"QLabel{"
|
||||
"background-color: red;"
|
||||
"color: white;"
|
||||
"border: 1px solid black;"
|
||||
"padding: 5px;"
|
||||
"border-radius: 5px;"
|
||||
"font: 20pt \"Microsoft YaHei UI\";"
|
||||
"}"
|
||||
);
|
||||
qWarning() << "FPGA Disconnected!";
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::heart_beat()
|
||||
{
|
||||
QMutexLocker locker(&plc_mutex); // 锁住互斥锁,自动解锁
|
||||
if(this->plc_connector == nullptr)
|
||||
{
|
||||
qDebug() << "plc_connector is null!";
|
||||
return;
|
||||
}
|
||||
if(!this->plc_connector->is_connected())
|
||||
{
|
||||
if(!this->plc_connector->try_connect()){
|
||||
// 未连接的情况下尝试连接失败,设置 lab_plc 为红色
|
||||
qDebug() << "Try to connect to the PLC";
|
||||
this->ui->lab_plc->setStyleSheet(
|
||||
"QLabel{"
|
||||
"background-color: red;"
|
||||
"color: white;"
|
||||
"border: 1px solid black;"
|
||||
"padding: 5px;"
|
||||
"border-radius: 5px;"
|
||||
"font: 20pt \"Microsoft YaHei UI\";"
|
||||
"}"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(this->plc_connector->send_heart_beat())
|
||||
{
|
||||
// 心跳发送成功,保持绿色
|
||||
this->ui->lab_plc->setStyleSheet(
|
||||
"QLabel{"
|
||||
"background-color: green;"
|
||||
"color: white;"
|
||||
"border: 1px solid black;"
|
||||
"padding: 5px;"
|
||||
"border-radius: 5px;"
|
||||
"font: 20pt \"Microsoft YaHei UI\";"
|
||||
"}"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 心跳发送失败,设置为红色
|
||||
this->ui->lab_plc->setStyleSheet(
|
||||
"QLabel{"
|
||||
"background-color: red;"
|
||||
"color: white;"
|
||||
"border: 1px solid black;"
|
||||
"padding: 5px;"
|
||||
"border-radius: 5px;"
|
||||
"font: 20pt \"Microsoft YaHei UI\";"
|
||||
"}"
|
||||
);
|
||||
qWarning() << "Connection established but write to PLC Failed!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Widget::showStartupCountdown()
|
||||
{
|
||||
CountdownDialog* countdown = new CountdownDialog(10, this);
|
||||
countdown->setAttribute(Qt::WA_DeleteOnClose); // 对话框关闭后自动删除
|
||||
|
||||
// 连接倒计时完成信号
|
||||
connect(countdown, &CountdownDialog::countdownFinished, this, &Widget::onCountdownFinished);
|
||||
|
||||
// 连接对话框的关闭事件,以处理用户提前关闭
|
||||
connect(countdown, &QDialog::rejected, this, &Widget::onCountdownCancelled);
|
||||
|
||||
countdown->show(); // 非模态显示,允许用户在倒计时期间与主窗口交互
|
||||
}
|
||||
|
||||
|
||||
void Widget::onCountdownCancelled()
|
||||
{
|
||||
qDebug() << "用户取消了启动倒计时。";
|
||||
// 根据需求处理取消后的操作,例如不启动识别任务
|
||||
// 可以选择什么都不做,或者提供提示
|
||||
}
|
||||
|
||||
|
||||
void Widget::onCountdownFinished()
|
||||
{
|
||||
qDebug() << "启动倒计时结束,继续执行开机操作。";
|
||||
on_btn_start_clicked();
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete m_lic;
|
||||
// 停止检测工作者线程
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
g_recognitionRunning[i]->store(false);
|
||||
g_img_Queue[i]->stop(); // 停止队列以唤醒线程
|
||||
}
|
||||
|
||||
// 等待检测工作者线程结束
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
if(g_recognitionThread[i] && g_recognitionThread[i]->joinable())
|
||||
{
|
||||
g_recognitionThread[i]->join();
|
||||
delete g_recognitionThread[i];
|
||||
g_recognitionThread[i] = nullptr;
|
||||
}
|
||||
|
||||
if(g_recognitionRunning[i])
|
||||
{
|
||||
delete g_recognitionRunning[i];
|
||||
g_recognitionRunning[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// 停止存储线程
|
||||
g_storageQueue.stop();
|
||||
storageThread.quit();
|
||||
storageThread.wait();
|
||||
|
||||
|
||||
// 现有清理代码...
|
||||
DestoryCamera();
|
||||
DestoryLowMac();
|
||||
|
||||
delete ui;
|
||||
if (m_errorDialog) {
|
||||
delete m_errorDialog; // 确保对话框被正确删除
|
||||
}
|
||||
|
||||
// 重启电脑
|
||||
QProcess::startDetached("shutdown", QStringList() << "/r" << "/f" << "/t" << "0");
|
||||
}
|
||||
|
||||
void Widget::refreshImage()
|
||||
@ -303,24 +109,12 @@ void Widget::refreshImage()
|
||||
this->ui->btn_start->setEnabled(!this->isCamRunning);
|
||||
this->ui->btn_stop->setEnabled(this->isCamRunning);
|
||||
this->ui->btn_take_photos->setEnabled(this->isCamRunning);
|
||||
|
||||
// refresh checkouts
|
||||
this->ui->dl_enable_0->setEnabled(!this->isCamRunning);
|
||||
this->ui->dl_enable_1->setEnabled(!this->isCamRunning);
|
||||
this->ui->tra_enable_0->setEnabled(!this->isCamRunning);
|
||||
this->ui->tra_enable_1->setEnabled(!this->isCamRunning);
|
||||
this->ui->btn_quit->setEnabled(!this->isCamRunning);
|
||||
|
||||
// refresh settings buttons
|
||||
this->ui->btn_setColor->setEnabled(!this->isCamRunning);
|
||||
this->ui->btn_reset_color->setEnabled(!this->isCamRunning);
|
||||
this->ui->btn_del_color->setEnabled(!this->isCamRunning);
|
||||
this->ui->btn_add_color->setEnabled(!this->isCamRunning);
|
||||
|
||||
this->ui->btn_reset_polar->setEnabled(!this->isCamRunning);
|
||||
this->ui->btn_save_polar->setEnabled(!this->isCamRunning);
|
||||
|
||||
this->ui->btn_set_lower->setEnabled(!this->isCamRunning);
|
||||
//
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
ui->label_currentDateTime->setText(now.toString("yyyy-MM-dd hh:mm:ss"));
|
||||
@ -364,11 +158,7 @@ void Widget::refreshImage()
|
||||
}
|
||||
else
|
||||
{
|
||||
if(g_camera_error.load()){
|
||||
info = "图像问题!!!";
|
||||
} else {
|
||||
info = "运行";
|
||||
}
|
||||
};
|
||||
}else {
|
||||
info = "停止";
|
||||
@ -512,7 +302,7 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result,
|
||||
return;
|
||||
}
|
||||
|
||||
// 缩放图像
|
||||
// 高质量缩放图像
|
||||
QSize labelSize = cameraLabels[camera_id]->size();
|
||||
QPixmap scaledPixmap = pixmap.scaled(labelSize);
|
||||
|
||||
@ -522,10 +312,15 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result,
|
||||
|
||||
|
||||
|
||||
void Widget::on_pushButton_2_clicked()
|
||||
{
|
||||
SaveImg_Flag = 1;
|
||||
}
|
||||
|
||||
void Widget::on_btn_stop_clicked()
|
||||
{
|
||||
stop_grab();
|
||||
DestoryLowMac();
|
||||
|
||||
this->isCamRunning = false;
|
||||
// 恢复显示的图片
|
||||
{
|
||||
@ -543,14 +338,6 @@ void Widget::on_btn_stop_clicked()
|
||||
|
||||
void Widget::on_btn_start_clicked()
|
||||
{
|
||||
//
|
||||
if(!m_lic->is_valid())
|
||||
{
|
||||
onCertificateRequestFailed("License Invalid!");
|
||||
return;
|
||||
}
|
||||
// 设置相机参数
|
||||
setLowMacParam();
|
||||
g_dl_enable[0] = !this->ui->dl_enable_0->isChecked();
|
||||
g_dl_enable[1] = !this->ui->dl_enable_0->isChecked();
|
||||
g_traditional_enable[0] = !this->ui->tra_enable_0->isChecked();
|
||||
@ -572,12 +359,17 @@ void Widget::on_btn_start_clicked()
|
||||
HANDLE hThread = static_cast<HANDLE>(g_recognitionThread[i]->native_handle());
|
||||
|
||||
// 设置线程优先级为最高
|
||||
if(!SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST))
|
||||
if(SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST))
|
||||
{
|
||||
std::cout << "DL Thread " << i << " set highest thread priority。" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "SET thread " << i << " failed, error code:" << GetLastError() << std::endl;
|
||||
}
|
||||
}
|
||||
start_camera();
|
||||
Start_camera();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -595,6 +387,33 @@ void Widget::on_btn_take_photos_released()
|
||||
|
||||
void Widget::on_btn_quit_clicked()
|
||||
{
|
||||
// // 停止检测工作者线程
|
||||
// for(int i = 0; i < 2; ++i)
|
||||
// {
|
||||
// g_recognitionRunning[i]->store(false);
|
||||
// g_img_Queue[i]->stop(); // 停止队列以唤醒线程
|
||||
// }
|
||||
|
||||
// // 等待检测工作者线程结束
|
||||
// for(int i = 0; i < 2; ++i)
|
||||
// {
|
||||
// if(g_recognitionThread[i] && g_recognitionThread[i]->joinable())
|
||||
// {
|
||||
// g_recognitionThread[i]->join();
|
||||
// delete g_recognitionThread[i];
|
||||
// g_recognitionThread[i] = nullptr;
|
||||
// }
|
||||
|
||||
// if(g_recognitionRunning[i])
|
||||
// {
|
||||
// delete g_recognitionRunning[i];
|
||||
// g_recognitionRunning[i] = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
DestoryCamera();
|
||||
DestoryLowMac();
|
||||
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
@ -603,38 +422,11 @@ void Widget::on_btn_quit_clicked()
|
||||
void Widget::on_btn_set_lower_clicked()
|
||||
{
|
||||
// 硬编码参数值
|
||||
lowmac_sm = ui->spinbox_maintime->value();
|
||||
params["lowmac_sm"]=lowmac_sm;
|
||||
params["machine_num"] = ui->spinbox_machine_code->value();
|
||||
params["max_valves_together"] = ui->spinbox_max_valves_together->value();
|
||||
params["screen_left_0"] = ui->spb_screen_left_0->value();
|
||||
params["screen_right_0"] = ui->spb_screen_right_0->value();
|
||||
params["screen_left_1"] = ui->spb_screen_left_1->value();
|
||||
params["screen_right_1"] = ui->spb_screen_right_1->value();
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt", params, colors);
|
||||
|
||||
// 两个过去的参量不支持读取配置文件
|
||||
file_delay = ui->spinbox_delaytime->text().toInt(); // 延迟时间(毫秒)
|
||||
file_encoder = ui->spinbox_encoder->text().toInt(); // 编码器值++
|
||||
file_valve = ui->spinbox_valve->text().toInt(); // 阀门通道
|
||||
// 重新初始化 PLCConnector
|
||||
{
|
||||
QMutexLocker locker(&plc_mutex);
|
||||
plc_connector = std::make_unique<PLCConnector>(params["machine_num"]);
|
||||
}
|
||||
heart_beat();
|
||||
}
|
||||
|
||||
void Widget::update_main_settings()
|
||||
{
|
||||
ui->lab_machine_num->setText(QString("%1号机").arg(params["machine_num"]));
|
||||
ui->spinbox_machine_code->setValue(params["machine_num"]);
|
||||
ui->spinbox_maintime->setValue(params["lowmac_sm"]);
|
||||
ui->spinbox_max_valves_together->setValue(params["max_valves_together"]);
|
||||
ui->spb_screen_left_0->setValue(params["screen_left_0"]);
|
||||
ui->spb_screen_left_1->setValue(params["screen_left_1"]);
|
||||
ui->spb_screen_right_0->setValue(params["screen_right_0"]);
|
||||
ui->spb_screen_right_1->setValue(params["screen_right_1"]);
|
||||
}
|
||||
|
||||
void Widget::on_btn_set_valve_clicked()
|
||||
{
|
||||
@ -656,7 +448,7 @@ void Widget::on_btn_live_clicked()
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_2_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(5);
|
||||
ui->tabWidget->setCurrentIndex(3);
|
||||
}
|
||||
|
||||
|
||||
@ -793,13 +585,7 @@ bool Widget::loadConfig(const QString &filePath)
|
||||
}
|
||||
|
||||
file.close();
|
||||
lowmac_dp = params["lowmac_dp"]; //偏振延迟时间
|
||||
lowmac_ts = params["lowmac_ts"]; //模板匹配阈值
|
||||
lowmac_sg = params["lowmac_sg"]; //偏振绿色通道大小阈值
|
||||
lowmac_td = params["lowmac_td"]; //偏振红色通道差值
|
||||
file_delay = params["file_delay"]; // 延迟时间
|
||||
expansionRaidus = params["expansionRaidus"]; // 扩展半径
|
||||
sizeThreshold = params["sizeThreshold"]; // 大小过滤
|
||||
|
||||
qDebug() << "配置已成功从" << filePath << "加载";
|
||||
// qDebug()<<colors;
|
||||
return true;
|
||||
@ -824,13 +610,13 @@ void Widget::initDefaultConfig()
|
||||
{"blue_b_min", -48}, {"blue_b_max", -8},
|
||||
|
||||
// Orange
|
||||
{"orange_L_min", 67}, {"orange_L_max", 93},
|
||||
{"orange_a_min", -8}, {"orange_a_max", 8},
|
||||
{"orange_b_min", 36}, {"orange_b_max", 58},
|
||||
{"orange_L_min", 63}, {"orange_L_max", 78},
|
||||
{"orange_a_min", 7}, {"orange_a_max", 14},
|
||||
{"orange_b_min", 23}, {"orange_b_max", 47},
|
||||
|
||||
// Black
|
||||
{"black_L_min", 0}, {"black_L_max", 30},
|
||||
{"black_a_min", -5}, {"black_a_max", 3},
|
||||
{"black_L_min", 0}, {"black_L_max", 8},
|
||||
{"black_a_min", -4}, {"black_a_max", 2},
|
||||
{"black_b_min", -3}, {"black_b_max", 4},
|
||||
|
||||
// Red
|
||||
@ -839,8 +625,8 @@ void Widget::initDefaultConfig()
|
||||
{"red_b_min", -80}, {"red_b_max", 37},
|
||||
|
||||
// Purple
|
||||
{"purple_L_min", 38}, {"purple_L_max", 60},
|
||||
{"purple_a_min", 10}, {"purple_a_max", 25},
|
||||
{"purple_L_min", 38}, {"purple_L_max", 54},
|
||||
{"purple_a_min", 10}, {"purple_a_max", 20},
|
||||
{"purple_b_min", -45}, {"purple_b_max", 1},
|
||||
|
||||
// Yellow
|
||||
@ -851,24 +637,7 @@ void Widget::initDefaultConfig()
|
||||
// Other parameters
|
||||
{"lab_denoising", 1},
|
||||
{"saturation_threshold", 165},
|
||||
{"saturation_denoising", 1},
|
||||
{"lowmac_sg",lowmac_sg},
|
||||
{"lowmac_td",lowmac_td},
|
||||
{"lowmac_ts",lowmac_ts},
|
||||
{"lowmac_dp",lowmac_dp},
|
||||
|
||||
{"lowmac_sm", lowmac_sm},
|
||||
{"machine_num", params["machine_num"]},
|
||||
{"max_valves_together", params["max_valves_together"]},
|
||||
{"screen_left_0", params["screen_left_0"]},
|
||||
{"screen_left_1", params["screen_left_1"]},
|
||||
{"screen_right_0", params["screen_right_0"]},
|
||||
{"screen_right_1", params["screen_right_1"]},
|
||||
|
||||
{"sizeThreshold",4},
|
||||
{"file_delay",1180},
|
||||
{"expansionRaidus",1}
|
||||
|
||||
{"saturation_denoising", 1}
|
||||
};
|
||||
}
|
||||
|
||||
@ -877,24 +646,14 @@ void Widget::on_btn_setColor_clicked()
|
||||
std::string current_color=ui->comboBox_colorlist->currentText().toLocal8Bit().constData();
|
||||
if (!(std::find(colors.begin(), colors.end(), current_color) != colors.end()))
|
||||
return;
|
||||
// 设置当前色彩
|
||||
params[current_color+"_L_min"]=ui->spinBox_L_min->value();
|
||||
params[current_color+"_L_max"]=ui->spinBox_L_max->value();
|
||||
params[current_color+"_a_min"]=ui->spinBox_A_min->value();
|
||||
params[current_color+"_a_max"]=ui->spinBox_A_max->value();
|
||||
params[current_color+"_b_min"]=ui->spinBox_B_min->value();
|
||||
params[current_color+"_b_max"]=ui->spinBox_B_max->value();
|
||||
// 准备写入本地
|
||||
params["file_delay"]=ui->spinbox_delaytime->value();
|
||||
params["saturation_threshold"]=ui->spb_saturation->value(); // 这个参数会通过params直接被调用无需赋值给其他全局变量
|
||||
params["sizeThreshold"]=ui->spinbox_msize_color->value();
|
||||
params["expansionRaidus"]=ui->spb_expandsize->value();
|
||||
// 写入内存进行使用
|
||||
file_delay = params["file_delay"];
|
||||
sizeThreshold = params["sizeThreshold"];
|
||||
expansionRaidus = params["expansionRaidus"];
|
||||
// 存入本地
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
|
||||
}
|
||||
|
||||
void Widget::update_colorlist()
|
||||
@ -904,10 +663,6 @@ void Widget::update_colorlist()
|
||||
{
|
||||
ui->comboBox_colorlist->addItem(QString::fromStdString(color));
|
||||
}
|
||||
ui->spinbox_delaytime->setValue(params["file_delay"]);
|
||||
ui->spb_saturation->setValue(params["saturation_threshold"]);
|
||||
ui->spinbox_msize_color->setValue(params["sizeThreshold"]);
|
||||
ui->spb_expandsize->setValue(params["expansionRaidus"]);
|
||||
|
||||
}
|
||||
|
||||
@ -935,23 +690,12 @@ void Widget::on_comboBox_colorlist_currentIndexChanged(int index)
|
||||
void Widget::on_btn_add_color_clicked()
|
||||
{
|
||||
std::string current_color=ui->lineEdit_color->text().toLocal8Bit().constData();
|
||||
// 空不添加
|
||||
if(current_color== "")
|
||||
{
|
||||
QMessageBox::warning(this, "什么颜色?", "这名字起的不雅");
|
||||
return;
|
||||
}
|
||||
// 必须跟之前所有颜色都不一致
|
||||
if (!(std::find(colors.begin(), colors.end(), current_color) != colors.end()))
|
||||
{
|
||||
colors.push_back(current_color);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, "已有名字", "这名字跟别的色撞了");
|
||||
return;
|
||||
}
|
||||
// 存盘刷界面
|
||||
params[current_color+"_L_min"]=ui->spinBox_L_min->value();
|
||||
params[current_color+"_L_max"]=ui->spinBox_L_max->value();
|
||||
params[current_color+"_a_min"]=ui->spinBox_A_min->value();
|
||||
@ -1045,6 +789,8 @@ void Widget::on_btn_del_color_clicked()
|
||||
|
||||
void Widget::on_btn_reset_color_clicked()
|
||||
{
|
||||
// 新增全部还原槽
|
||||
|
||||
// 确认重置
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "全部还原", "确定要将配置还原为默认设置吗?",
|
||||
@ -1079,142 +825,3 @@ void Widget::on_btn_reset_color_clicked()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab_color_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(3);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_3_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(5);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_5_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab_color_2_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(3);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_6_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(4);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_7_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(5);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_8_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab_color_3_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(3);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_9_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(4);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_tab3_backtab2_4_clicked()
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(4);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_save_polar_clicked()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "确定保存", "确定要将偏振配置保存吗?",
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
params["lowmac_td"]=ui->spb_diff->value();
|
||||
params["lowmac_sg"]=ui->spb_green->value();
|
||||
params["lowmac_dp"]=ui->spb_delay_polar->value();
|
||||
params["lowmac_ts"]=ui->spb_msize_polar->value();
|
||||
lowmac_dp = params["lowmac_dp"]; //偏振延迟时间
|
||||
lowmac_ts = params["lowmac_ts"]; //模板匹配阈值
|
||||
lowmac_sg = params["lowmac_sg"]; //偏振绿色通道大小阈值
|
||||
lowmac_td = params["lowmac_td"]; //偏振红色通道差值
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_reset_polar_clicked()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "确定重置", "确定要将偏振部分配置重置吗?",
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
params["lowmac_td"]= 2;
|
||||
params["lowmac_sg"]= 60;
|
||||
params["lowmac_dp"]= 350;
|
||||
params["lowmac_ts"]= 13;
|
||||
lowmac_dp = params["lowmac_dp"]; //偏振延迟时间
|
||||
lowmac_ts = params["lowmac_ts"]; //模板匹配阈值
|
||||
lowmac_sg = params["lowmac_sg"]; //偏振绿色通道大小阈值
|
||||
lowmac_td = params["lowmac_td"]; //偏振红色通道差值
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
update_polar();
|
||||
}
|
||||
|
||||
void Widget::update_polar()
|
||||
{
|
||||
ui->spb_green->setValue(lowmac_sg);
|
||||
ui->spb_diff->setValue(lowmac_td);
|
||||
ui->spb_delay_polar->setValue(lowmac_dp);
|
||||
ui->spb_msize_polar->setValue(lowmac_ts);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_tabWidget_currentChanged(int index)
|
||||
{
|
||||
update_main_settings();
|
||||
update_colorlist(); // 更新色彩列表
|
||||
update_polar(); // 更新偏振相机界面
|
||||
}
|
||||
|
||||
void Widget::onCertificateRequestFailed(const QString errorMsg)
|
||||
{
|
||||
if (!m_errorDialog) { // 如果没有活动的错误对话框
|
||||
if(this->isCamRunning)
|
||||
{
|
||||
this->on_btn_stop_clicked();
|
||||
}
|
||||
m_errorDialog = new LicenseDialog(m_lic, this);
|
||||
m_errorDialog->setAttribute(Qt::WA_DeleteOnClose); // 确保对话框关闭时删除
|
||||
connect(m_errorDialog, &QDialog::finished, [this](int) {
|
||||
m_errorDialog = nullptr; // 当对话框关闭时重置指针
|
||||
});
|
||||
m_errorDialog->setModal(true); // 设置为模态对话框
|
||||
m_errorDialog->show();
|
||||
} else {
|
||||
// 窗口已存在,使其跳动
|
||||
m_errorDialog->raise(); // 将对话框带到前台
|
||||
m_errorDialog->activateWindow(); // 将焦点设置到对话框窗口
|
||||
}
|
||||
}
|
||||
|
||||
59
widget.h
59
widget.h
@ -1,17 +1,13 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
#include <windows.h>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QWidget>
|
||||
#include <camera.h>
|
||||
#include <QTcpServer>
|
||||
#include <QPushButton>
|
||||
#include "globals.h"
|
||||
#include "storage_worker.h"
|
||||
#include "countdown_dialog.h"
|
||||
#include "plc_connector.h"
|
||||
#include "licesing.h"
|
||||
#include "storageworker.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@ -30,18 +26,12 @@ public:
|
||||
public slots:
|
||||
void refreshImage(); // 刷新图片的槽函数
|
||||
|
||||
void heart_beat();
|
||||
|
||||
void check_lower_machine(); // 检查下位机状态
|
||||
|
||||
private slots:
|
||||
|
||||
void onCountdownFinished();
|
||||
|
||||
void onCountdownCancelled();
|
||||
|
||||
void refreshSingleImage(int camera_id, bool overlay_traditional_result = false, bool overlay_dl_result = false, bool mirror = false);
|
||||
|
||||
void on_pushButton_2_clicked();
|
||||
|
||||
void on_btn_stop_clicked();
|
||||
|
||||
void on_btn_start_clicked();
|
||||
@ -82,58 +72,15 @@ private slots:
|
||||
|
||||
void on_btn_reset_color_clicked();
|
||||
|
||||
void on_btn_tab_color_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_3_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_5_clicked();
|
||||
|
||||
void on_btn_tab_color_2_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_6_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_7_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_8_clicked();
|
||||
|
||||
void on_btn_tab_color_3_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_9_clicked();
|
||||
|
||||
void on_btn_tab3_backtab2_4_clicked();
|
||||
|
||||
void on_btn_save_polar_clicked();
|
||||
|
||||
void on_btn_reset_polar_clicked();
|
||||
|
||||
void update_polar();
|
||||
|
||||
void update_main_settings();
|
||||
|
||||
void on_tabWidget_currentChanged(int index);
|
||||
|
||||
void onCertificateRequestFailed(const QString errorMsg);
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
|
||||
bool isCamRunning;
|
||||
bool isLicenseValid;
|
||||
|
||||
std::unique_ptr<PLCConnector> plc_connector;
|
||||
QMutex plc_mutex; // 添加互斥锁
|
||||
|
||||
QDateTime startTime; // 记录点“开始分选”的时间,用于计算总运行时长
|
||||
|
||||
QThread storageThread; // 存储线程
|
||||
|
||||
StorageWorker* storageWorker; // 存储工作者
|
||||
|
||||
Licesing* m_lic;
|
||||
|
||||
void showStartupCountdown();
|
||||
|
||||
QDialog *m_errorDialog = nullptr; // 追踪错误对话框的状态
|
||||
|
||||
};
|
||||
#endif // WIDGET_H
|
||||
|
||||
Loading…
Reference in New Issue
Block a user