-
linux/container_of.h 获得结构体指针
/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _LINUX_CONTAINER_OF_H #define _LINUX_CONTAINER_OF_H #include <linux/build_bug.h> #include <linux/err.h> #define typeof_member(T, m) typeof(((T*)0)->m) /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. * @type: the type of the container struct this is embedded in. * @member: the name of the member within the struct. * * WARNING: any const qualifier of @ptr is lost. */ #define container_of(ptr, type, member) ({ \ void *__mptr = (void *)(ptr); \ static_assert(__same_type(*(ptr), ((type *)0)->member) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) /** * container_of_const - cast a member of a structure out to the containing * structure and preserve the const-ness of the pointer * @ptr: the pointer to the member * @type: the type of the container struct this is embedded in. * @member: the name of the member within the struct. */ #define container_of_const(ptr, type, member) \ _Generic(ptr, \ const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\ default: ((type *)container_of(ptr, type, member)) \ ) #endif /* _LINUX_CONTAINER_OF_H */
-
openssl和Windows crypt32 AES加解密互通
// 在使用openssl加密时,为了让Windows crypt32 // API能很方便的解密,需要同步CryptDeriveKey的功能。 // 适用于win api端CryptCreateHash指定为CALG_MD5的情况。 // https://learn.microsoft.com/zh-cn/windows/win32/api/wincrypt/nf-wincrypt-cryptderivekey?redirectedfrom=MSDN unsigned char *crypt32DerivedKey(unsigned char *md5hash, int k /*hash长度*/, int keyBitSize) { /**step 1*/ unsigned char buffer1[64]; for (int i = 0; i < 64; i++) { buffer1[i] = 0x36; } // int k = n; for (int i = 0; i < k; i++) { buffer1[i] = buffer1[i] ^ md5hash[i]; } /*step 2*/ unsigned char buffer2[64]; for (int i = 0; i < 64; i++) { buffer2[i] = 0x5C; } for (int i = 0; i < k; i++) { buffer2[i] = buffer2[i] ^ md5hash[i]; } /*step 3*/ unsigned char hash1[MD5_DIGEST_LENGTH]; MD5(buffer1, 64, hash1); /*step 4*/ unsigned char hash2[MD5_DIGEST_LENGTH]; MD5(buffer2, 64, hash2); /*step 5*/ int resultLen = keyBitSize / 8; unsigned char *outputkey = (unsigned char *)malloc(resultLen); for (int i = 0; i < resultLen; i++) { if (i < 16) outputkey[i] = hash1[i]; else outputkey[i] = hash2[i - 16]; } return outputkey; }
-
常用的编译Qt的配置命令
Qt 5.15.2
configure -prefix "C:\Qt\5.15.2\debug" -confirm-license -opensource -debug -shared -platform win32-msvc -opengl desktop -nomake examples -nomake tests -nomake tools -no-compile-examples -skip qtwebengineconfigure -prefix "C:\Qt\5.15.2\release" -confirm-license -opensource -release -static -static-runtime -platform win32-msvc -opengl desktop -nomake examples -nomake tests -nomake tools -no-compile-examples -skip qtwebengine
Qt 6.4.2
configure -prefix "C:\Qt\6.4.2\debug" -confirm-license -opensource -debug -shared -platform win32-msvc -no-opengl -qt-pcre -qt-zlib -qt-sqlite -nomake examples -nomake tests -nomake toolsconfigure -prefix "C:\Qt\6.4.2\release" -confirm-license -opensource -release -static -static-runtime -platform win32-msvc -no-opengl -nomake examples -nomake tests -nomake tools -skip qtwebengine
-
不同模式和填充下AES密文的长度
算法/模式/填充 16 字节加密后数据长度 不满 16 字节加密后长度 AES/CBC/NoPadding 16 不支持 AES/CBC/PKCS5Padding 32 16 AES/CBC/ISO10126Padding 32 16 AES/CFB/NoPadding 16 原始数据长度 AES/CFB/PKCS5Padding 32 16 AES/CFB/ISO10126Padding 32 16 AES/ECB/NoPadding 16 不支持 AES/ECB/PKCS5Padding 32 16 AES/ECB/ISO10126Padding 32 16 AES/OFB/NoPadding 16 原始数据长度 AES/OFB/PKCS5Padding 32 16 AES/OFB/ISO10126Padding 32 16 AES/PCBC/NoPadding 16 不支持 AES/PCBC/PKCS5Padding 32 16 AES/PCBC/ISO10126Padding 32 16
-
阻止clang-format修改文件包含顺序
// clang-format off #include <b.h> #include <a.h> #include <c.h> // clang-format on #include <d.h> #include <e.h>

