@@ -0,0 +1,38 @@ | |||
BORINGSSL_DIR=/home/hdc/repos/cloudflare/boringssl | |||
BORINGSSL_LIB=$(BORINGSSL_DIR)/build.64bitRel/ | |||
CC = clang | |||
SRCDIR = src | |||
OBJDIR = obj | |||
DBG ?= 1 | |||
ifeq ($(DBG),1) | |||
DEBUG = -DDEBUG -g -O0 | |||
else | |||
DEBUG = -O3 | |||
endif | |||
CFLAGS = -std=c99 | |||
CFLAGS+= $(DEBUG) | |||
CFLAGS+= -I$(BORINGSSL_DIR)/ -I$(BORINGSSL_DIR)/include | |||
LDFLAGS = -L$(BORINGSSL_LIB)/crypto -L$(BORINGSSL_LIB)/ssl | |||
LDFLAGS+= -lssl -lcrypto -lpthread | |||
all: server client | |||
clean: | |||
rm -rf $(OBJDIR) | |||
rm -rf client server | |||
client: common | |||
$(CC) -c $(SRCDIR)/client.c -o $(OBJDIR)/client.o $(CFLAGS) | |||
$(CC) -o client $(OBJDIR)/client.o $(OBJDIR)/common.o $(LDFLAGS) | |||
server: common | |||
$(CC) -c $(SRCDIR)/server.c -o $(OBJDIR)/server.o $(CFLAGS) | |||
$(CC) -o server $(OBJDIR)/server.o $(OBJDIR)/common.o $(LDFLAGS) | |||
common: | |||
mkdir -p $(OBJDIR) | |||
$(CC) -c $(SRCDIR)/common.c -o $(OBJDIR)/common.o $(CFLAGS) |
@@ -0,0 +1,24 @@ | |||
-----BEGIN CERTIFICATE----- | |||
MIID8jCCAtqgAwIBAgIJALuIdyUDX1d+MA0GCSqGSIb3DQEBCwUAMIGFMQswCQYD | |||
VQQGEwJGUjENMAsGA1UECAwEUEFDQTEXMBUGA1UEBwwOQ2FnbmVzIHN1ciBNZXIx | |||
JjAkBgNVBAsMHURvbWFpbiBDb250cm9sIFZhbGlkYXRlZCBTQVJMMSYwJAYDVQQD | |||
DB1Eb21haW4gQ29udHJvbCBWYWxpZGF0ZWQgU0FSTDAeFw0xODA0MDkxNjMxMDVa | |||
Fw00NTA4MjUxNjMxMDVaMIGFMQswCQYDVQQGEwJGUjENMAsGA1UECAwEUEFDQTEX | |||
MBUGA1UEBwwOQ2FnbmVzIHN1ciBNZXIxJjAkBgNVBAsMHURvbWFpbiBDb250cm9s | |||
IFZhbGlkYXRlZCBTQVJMMSYwJAYDVQQDDB1Eb21haW4gQ29udHJvbCBWYWxpZGF0 | |||
ZWQgU0FSTDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALBjh23Spt4I | |||
AvaFLNL9LXDngLy6OyJbqPYNOEfn9vdvzcCJZbBDhD1HNoIuJux340wcio5TZajX | |||
sJCIUl/n+e+8BGwxzZvp3qM2e/Rs94roZjlUWHMaX/a8Q7MvrR9XWM1SaEp2fHa9 | |||
nBgdfSo+BvvILq8lZU7vO+xw7Yjtx0YNk1v3IAMoQyrfaeZcb9uE1tuAj0oPwmEp | |||
CWqGVkQEIJ6MJBbA+6SW6yi/5h3s0mbc7hdcmLr+vSv5Bkg8qOaPwh0ffuTCMuGq | |||
8q9en4WSW/mnbDZpPdGZwp4Ub7po4Zp9dVQoD7Skf9chz26+pivmIfUB1Xwr48b2 | |||
gFfbZcwDsFsCAwEAAaNjMGEwHQYDVR0OBBYEFPSjEiJgM3NjauAc0lzUrgExAgvg | |||
MB8GA1UdIwQYMBaAFPSjEiJgM3NjauAc0lzUrgExAgvgMA8GA1UdEwEB/wQFMAMB | |||
Af8wDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4IBAQAQALRSOq1IwOMG | |||
qZeXvNmd+jGomDH4IDV+s+agGWWneVzRJzP1qSxvrG5BgyP+STzvxEJBgGfCZKHw | |||
qW2HH2bt3vU0KhF90zthmLlZSphuF3XTBUyWfhmUgxuSWxgScBLHrk2vwQv55Mxn | |||
N88DPwYfRLjJUfEIDhzgNRsrVP1mbP0tmXjfmuQzE9Ht8L3fqJ+Tfk/eHdJIOkeM | |||
YRYSOT6oa7g49Vi6ONE7m+BqCDS7D+2p6t6Zb/1lEI82TvmbUq7gd9xHCROFmhis | |||
gBKsJxp0aVI5pB9mLqnluB21c4sVqt6si8sWcJjtTCmojp192aSxB3A6hVI0P8qY | |||
7iJBFwa1 | |||
-----END CERTIFICATE----- |
@@ -0,0 +1,8 @@ | |||
-----BEGIN EC PARAMETERS----- | |||
BggqhkjOPQMBBw== | |||
-----END EC PARAMETERS----- | |||
-----BEGIN EC PRIVATE KEY----- | |||
MHcCAQEEIF8KXjVrcF0u+J3dDxrOPHr3/xQlxwpZowwdDxiM72iUoAoGCCqGSM49 | |||
AwEHoUQDQgAE7HJPLOV22gIiLMIR1btCTDQMbtwwWqhuErrk2r4+p3Oino2fSDBm | |||
9T76CNfnLjmUue1qoLj144aK86GB0rGy4A== | |||
-----END EC PRIVATE KEY----- |
@@ -0,0 +1,15 @@ | |||
-----BEGIN CERTIFICATE----- | |||
MIICTTCCATUCCQD7FNAespFtBDANBgkqhkiG9w0BAQsFADCBhTELMAkGA1UEBhMC | |||
RlIxDTALBgNVBAgMBFBBQ0ExFzAVBgNVBAcMDkNhZ25lcyBzdXIgTWVyMSYwJAYD | |||
VQQLDB1Eb21haW4gQ29udHJvbCBWYWxpZGF0ZWQgU0FSTDEmMCQGA1UEAwwdRG9t | |||
YWluIENvbnRyb2wgVmFsaWRhdGVkIFNBUkwwHhcNMTgwNDA5MjAxMTEwWhcNNDUw | |||
ODI0MjAxMTEwWjAWMRQwEgYDVQQDDAt3d3cuZG12LmNvbTBZMBMGByqGSM49AgEG | |||
CCqGSM49AwEHA0IABOxyTyzldtoCIizCEdW7Qkw0DG7cMFqobhK65Nq+Pqdzop6N | |||
n0gwZvU++gjX5y45lLntaqC49eOGivOhgdKxsuAwDQYJKoZIhvcNAQELBQADggEB | |||
ADEx+x0XXiTyBjEi5wVFEx/36tD4TMck5GLzyWFBPMgY5rVk0/scyYslqikF7j/M | |||
OY/Z+3WG/Wx0OqH+inA+aYb2xg6qLd4JR9eIRU7luSKyFDRCK3BYcpPYa9DQKVim | |||
Q4jA17rLRKqLLSDWUr0VO+YaXk9EqpkjjEeo3Dn1xIKtwwqvEocFUWlc1MPUrfgX | |||
OpPP4fSyqPcE0I75vWsznGyrYax9k7fAFV/UdC2p/jQPs+lVVesml2DJA9IjEdpJ | |||
1HOKpzjPXrPkCixoXqjM0HZRLuCNUb1sl8bWvpCQ6xTtDH0mkt8yHO6HeqKLpgpZ | |||
2O99VHKVMmEzsFOyE+4khVM= | |||
-----END CERTIFICATE----- |
@@ -0,0 +1,30 @@ | |||
-----BEGIN RSA PRIVATE KEY----- | |||
Proc-Type: 4,ENCRYPTED | |||
DEK-Info: AES-256-CBC,298AA9B5B7606E863BB9183F689D9346 | |||
VvURRUrBBi/AlUA4AlFUKm+aVzvnG4TQrhHKTV3nFGOHeqB+Sua+3R+e6svyiY+p | |||
d0VaZtlpS2mE7lxPqy0+VOarCYYkJOF2juGVMwFzEG8lkoEUyC8qyOobaRj4OCcb | |||
PgIk9b3i5Lv2PBLTpC4lxo6FrUykKXqLKeg0Lp4EEfFRGOKQB5CQBDeGOA1oBeqt | |||
cwRxXP8k3KPiIs+P+Lswk5qLD4gTtlf8ycQmJuCDFUQ3ARgRvngqFvu/44fm5Ztv | |||
6fBvAQvoHXJ9I+HuJAJcT1wGn9itZYFRMXyA2pf1Q2WHpxm1ZS7AiZrn5nyqPpnV | |||
aoBlwR7D0OxyoRumSHA3Y4YheN+uId27Gg12AWUalDcFes3DD2DZOkSQrzsIT0X3 | |||
EifJSSnuOTLe8w+SSvUVIMxkW5CRE0uOi/wuZHTpRN0ZxsvmeL+EHQmqtAOcjS5g | |||
RPMidMdSGfCnqC0N2EAalUU2BsIGRgG5yvmG5ZIqu0Bm6WIIX1T34HS8HUhDqgRX | |||
jOi8Ch7J/6xMZcxSeqRvdss96s6SzehqpG3kW7EsualJqWwmAGF0oJOxX6LupIRd | |||
0GacwZv+NcWPYKL9oDNINPrU8hvobhaSeLvK8Gum8DK4TTd0evng6LYvkgejIcRF | |||
pzfC+ONTiHZO4ayxleJVFAdph2LY3itO/TKD6KBLq0vnd+HvOKPWq0s0zDtQ/mSF | |||
PMEwZ0DvYq5mtko5MOIqlIJKXS+p+jmzAhIZzqPt57HoyZjuRKTKkvlTeOoY7cax | |||
UDGJffDrnagbP3R12i+bm7Bmz7aQQktuwhV7/SrEnJDM2PLDOYuWnGV5v/Cb+L/7 | |||
gGMFs9PTro8p4OkCLcpyGS/FoA7J5B1JixhUJ4tSEzEkTBSYz5WCi7NqrRZ9nnDf | |||
drYBNpMHlK4DNRe9qhusdRPrbd9srDH8g74QQgzWorYx0TqBUS45NLyyUZPydFxJ | |||
vAT1lmdWo7DhhnqSkPAcrwKdakDIravzvw0Ex+iEzAPSaflDvVybu6Gf8r6FrFIR | |||
SrR2pT4EztvPViaS9KZHZ0PQYKporwsWM1ZLyGX2qi3d5+YFijE3IT67rSLuEBMO | |||
/RFY0OCHbmKNrOiCaXk51+04hXg8ptjAxD8YCFpOzaDlSW2LX9D2QAfghoArZVTb | |||
OHThemZ4zIvamGkZLQB44nuvduIRGBA2LiQ0YiH4FhuJCP7zTCtCqQu4Wnn6J4tb | |||
YCEtm9ntFSGGCipErqqENPTBhxz6exO8emd2/y0INY4d9xJYjfhqCrKShpeF+/Lf | |||
6pJ3Pj9qA3D8wWcizER5N4R1fzmhTOSCxinC6OVJOzdk76M6gi+bD5RV8HD60TyG | |||
VEmTusA8lrLlKSYiE+4VFYBJjBSCopybJAaNsKXaYM3hwaPTPJwsgPWxwQ5m/vPT | |||
7dvkPOnhqwQ7DEvr2y3AgEUJxXxtsNwQEiKgMuRxNIQNE5mp68dJ5hMFnbJUPvvo | |||
80IsUH11LLDQJV60aLLF8M37BFvNPUayaS+oP78UwRMbnpC92nuHNgvGfdXFKhV3 | |||
/8z6lNYPlMGgBwdCD6NBXpXHkp7rxOAGvHx5eUocjgXfF2b8zSXyN/9egK9sfMZZ | |||
-----END RSA PRIVATE KEY----- |
@@ -0,0 +1,19 @@ | |||
-----BEGIN CERTIFICATE----- | |||
MIIDGDCCAgACCQD7FNAespFtAjANBgkqhkiG9w0BAQsFADCBhTELMAkGA1UEBhMC | |||
RlIxDTALBgNVBAgMBFBBQ0ExFzAVBgNVBAcMDkNhZ25lcyBzdXIgTWVyMSYwJAYD | |||
VQQLDB1Eb21haW4gQ29udHJvbCBWYWxpZGF0ZWQgU0FSTDEmMCQGA1UEAwwdRG9t | |||
YWluIENvbnRyb2wgVmFsaWRhdGVkIFNBUkwwHhcNMTgwNDA5MTYzMjEwWhcNNDUw | |||
ODI0MTYzMjEwWjAWMRQwEgYDVQQDDAt3d3cuZG12LmNvbTCCASIwDQYJKoZIhvcN | |||
AQEBBQADggEPADCCAQoCggEBANDw1tIr4IHqfivyIBMn4MPRaPQFxOZPIRaIOo85 | |||
4gaeHD11tLbxIh++lzfxk//ubC5a5K/PUDsVhLupTQVNKklcg4eRymZROkXoqgRg | |||
+ibEH5IYRu64aVlhQe4lGiK/Z8njUtq31zeyn2RaYWW/4uq/wmOKB/qVinARISKf | |||
lvTjtSN5cBg55tyDV5Cb7GgpSBXVGc8J4WKU6BAn43FTqgj8XkVvGYR3C/X5ZR/+ | |||
3xXVqe/VwLHyYNe61ySYRmymdoXJnJE7l0+MJhcpvepzEZ1pCULomNbHcxGfSZnc | |||
XsajvNKp/Y+cjC/IYmzkpTHgHhUEVs1rAdotNr0j5vRS/iECAwEAATANBgkqhkiG | |||
9w0BAQsFAAOCAQEAXjyhGLvT1waoYofYhkN3xmrkDxtM8HmG/xGad1vhkx6Qi2M/ | |||
kdX/UlEMwlkh1Of20iJVcMmTPleiOcIO2cE8F0BQ4wIGN3PGw8guxa11ToyyMarg | |||
cWNUWdA4gwYvMQv6tceUtsJUjNp0O6JW563jejVaiqBHhG50riJ2wfzqgMItjZY0 | |||
/TLVRQbEJ+NGeYZJ9/jL5xmHxoL8ROQ3RXtZjxU6Jr0pe3Y7XKT27QE3007EkCYb | |||
XG7K1U/rbixqfphXys677gjJ8xXChunjNqCijNk2xjHmu2MakspSqIB86oB50oLj | |||
Pu+AVI/SGD1qlJBC9qlgDoUkm9VI9mTIKJzALg== | |||
-----END CERTIFICATE----- |
@@ -0,0 +1,40 @@ | |||
-----BEGIN PRIVATE KEY----- | |||
MIIG/QIBADANBgkqhkiG9w0BAQEFAASCBucwggbjAgEAAoIBgQDChoUsywwSGecu | |||
aHGGNMY8PrvM7nPjXpFXD0MK1OG0Yf3eV/QqRC3ahS7SICUvhRTiDzClez45NOKx | |||
YpH1C0u/M/DvojFgrGJlKVvO0vdckxlWCyK6DVKiwBP7ySkXjy+TuRuIZ4kxHzWC | |||
AEldbgPHlIGPxvhU4dAHXHcdHGdAgHL+7AhZh32acIDq3pkla3PQAawKcl/72l7v | |||
PXju594jWZkzrqPjXKpJ2GRX8q5XFoMNUe3hDR1Fk4aij7Y2k5aWmkD3WVGHti9K | |||
Zdjua2CYIp1+BUZ205wxOiWHlshpXzs73Exj2uv9OM/fcVliy5T+uR87a6KoIq+7 | |||
vrU642yWCWOx3pzhvfgBANCnJRWXCq4CPAyImNUaapgnrM9TIWRyBmtD7/qsfQ0b | |||
DKJItf+p4Zzx1QatLKFG8qaaoP+6liQQaYFRP/v+cXM7c9LaU7elKI3yyClLSUoV | |||
rg6vp/xUsIcaYjUP2j+3VMv54Dy18eWt2FkmRB1ompSp+g6XoI8CAQMCggGBAIGv | |||
A3MyCAwRRMma9ll4hCgp0oie9+zptjoKLLHjQSLr/pQ6osbYHpGuHzbAGMpYuJa0 | |||
yxj81CYjQcuXC/iyMn939fUWy5XIQZjGPTSMpOhiEOQHbHwI4cHVYqfbcLpfdQ0m | |||
ElrvsMtqI6wAMOj0AoUNq7UvUDiWiq+S+hNoRNWq91SdWuZaU7xLAJyUZhjyTTVW | |||
crGhlVKRlJ9+UJ9FPsI7u3fJwpeTHDE67Y/3HuS5rLOL8+teE4O3rxcKeXm3uI/h | |||
4O6rL2hwJDWSZ0LDnCCRpPQQwjlh6/xg57+R7Fgn8UW9u6dtyuNTHHpR+iiouE+Y | |||
7unzF5SC/ipQDFUYHmNiygGZL6KMy1H5NlosQiQZ/BY7A6UsNnySa6XwZu1/HTMt | |||
6pEtFbiXs3XaR6aA9Ervjt6OEHTldQ5/mBc2A6cvtvLB/wa74fkX5vhA2ruapTWr | |||
T501rYPTKhUKxmyaSe0U7qZ4rLcgOpxKbr/Rh6fkoXfgBOov5supefCRPeCsuwKB | |||
wQDpmuped2B80mnSchyL3KG/x5GFxSfALgnWGYovzHLHPxJQGLrSa841N4j+Qggb | |||
4n/r4e93+L1Ps++9Zl4A9HFQ+F0oKE+j18mB6LEkvFCqhIRC29mJcQyfNbchFqhl | |||
Ph+6XE/Ul8p5UdF2gZfNyQoJ5TGnWPEusxwD8T3IY5helGd6i8SY6FztIzlsNv/p | |||
hZ/9YjHjP9ngmGruXjgQBb1NFKuELbGE2gMw60faiKbPmJVHtotVwauS8OA+67jH | |||
w30CgcEA1SyFMuEp7juPJ5ghfmlUp4CUiib7YJKwYI8/uG9zHeQ/Ayb4FkptcwSc | |||
KbRaCewAm3HJZIZB+apCvuBEukrNr/zXh1CFyhL9hCJN+yZhtl8vngeth2V2wFk/ | |||
ja2MiaSY6uU7lZSPnkeuc8OfASuHL5UU/Kb8zyFVrUIEr2xh4ToqKbq+Lj3MG6pf | |||
WtuK12Yf10Vko7fLJPQgB7+s/LrQI/x1nH+AeE/km/nd/51KaoJeMlHGcTqXpCt9 | |||
gjR4/tn7AoHBAJu8nD76QFM28Tb2vbKTFn/aYQPYxSrJW+QRBsqITITUtuAQfIxH | |||
3s4lBf7WsBKW//KWn6VQfjUin9OZlACi9jX66MVwNRflMQFFy23S4HGtrYHn5lug | |||
sxTOehYPGu4panw9io26hvuL4PmruokwsVvuIRo7S3R3aAKg09rtED8NmlGygxCa | |||
6J4Xe515//EDv/5Bdpd/5pW68fQ+0AqufjNjHQLJIQM8AiCc2pGwbzUQY4UkXOPW | |||
cmH16tSdJdqCUwKBwQCOHa4h63FJfQoaZWupm43FAGMGxKeVtyBAX3/QSky+mCoC | |||
Gfq5hvOiAxLGeDwGnVW89oZDBCv7xtcp6th8Md51UzpaNa6Gt1OtbDP8xEEkP3UU | |||
BR5aQ6SAO3+zyQhbwxCcmNJjuF++2nRNLRSrclofuLiob1M0wOPI1q3KSEFA0XFx | |||
Jyl0KTK9HD+R57Hk7r/k2O3Ceodt+BVaf8iofIrCqE5oVQBQNUMSppP/vjGcVul2 | |||
4S72Jw/Cx6kBeFCp5qcCgcBF+fb8F59HYjZJAjV4Qv2obehNvcb7swHMOYTLBkBq | |||
j9cnVysTQ9lc6vwB5Vh4rzwOSmJRKPvv6+1oinImwtzZFLuggunkXxmrPLiRcF82 | |||
Gj7RL62D6msMbNo0vMXmXa20D/M3lATSuWuOsBz1BAfFrkO/kwAz02s9dleOidX3 | |||
YkuSiPhm3bQD3qezO3OQmZ2s1OfzZMQpXE8+4ymTWW5H9KtKxrDs7/05goy1/OPk | |||
u5evFUiLOWw7CJ9Sy1/Jaws= | |||
-----END PRIVATE KEY----- |
@@ -0,0 +1,18 @@ | |||
-----BEGIN CERTIFICATE----- | |||
MIIC1DCCAnsCCQCY04gkucQIkzAKBggqhkjOPQQDAjB9MQswCQYDVQQGEwJGUjEN | |||
MAsGA1UECAwEUEFDQTEXMBUGA1UEBwwOQ2FnbmVzIHN1ciBNZXIxIjAgBgNVBAsM | |||
GUNlcnQgVGVzdGluZyBPcmdhbml6YXRpb24xIjAgBgNVBAMMGUNlcnQgVGVzdGlu | |||
ZyBPcmdhbml6YXRpb24wHhcNMTgwNDE3MTMyNzA4WhcNMTgwNTE3MTMyNzA4WjAf | |||
MR0wGwYDVQQDDBR3d3cuY2VydF90ZXN0aW5nLmNvbTCCAaAwDQYJKoZIhvcNAQEB | |||
BQADggGNADCCAYgCggGBAMKGhSzLDBIZ5y5ocYY0xjw+u8zuc+NekVcPQwrU4bRh | |||
/d5X9CpELdqFLtIgJS+FFOIPMKV7Pjk04rFikfULS78z8O+iMWCsYmUpW87S91yT | |||
GVYLIroNUqLAE/vJKRePL5O5G4hniTEfNYIASV1uA8eUgY/G+FTh0Adcdx0cZ0CA | |||
cv7sCFmHfZpwgOremSVrc9ABrApyX/vaXu89eO7n3iNZmTOuo+NcqknYZFfyrlcW | |||
gw1R7eENHUWThqKPtjaTlpaaQPdZUYe2L0pl2O5rYJginX4FRnbTnDE6JYeWyGlf | |||
OzvcTGPa6/04z99xWWLLlP65Hztroqgir7u+tTrjbJYJY7HenOG9+AEA0KclFZcK | |||
rgI8DIiY1RpqmCesz1MhZHIGa0Pv+qx9DRsMoki1/6nhnPHVBq0soUbyppqg/7qW | |||
JBBpgVE/+/5xcztz0tpTt6UojfLIKUtJShWuDq+n/FSwhxpiNQ/aP7dUy/ngPLXx | |||
5a3YWSZEHWialKn6DpegjwIBAzAKBggqhkjOPQQDAgNHADBEAiBiXGvdsqXGxDtR | |||
09lV6d2w2rYVteso/RVCQVxUWo5BuQIgRXF5XrvhRbpTOaRgLgnOpyLZv7nEwWNG | |||
cRb2Q37V4VM= | |||
-----END CERTIFICATE----- |
@@ -0,0 +1,212 @@ | |||
#include <unistd.h> | |||
#include "common.h" | |||
// include/ path is here for a reason - to make sure we compile against boringssl (temporary solution) | |||
#include <include/openssl/ssl.h> | |||
#include <pthread.h> | |||
// Buffer used for read/write tests | |||
unsigned char rw_buf[BUFFER_SIZE]; | |||
static const int Curves[1] = {NID_X25519}; | |||
static const uint16_t TLS_PROT_VERSION = TLS1_3_VERSION; | |||
SSL_CTX *setup_client_ctx(void) | |||
{ | |||
SSL_CTX* ctx = NULL; | |||
ctx = SSL_CTX_new(TLS_method()); | |||
assert(ctx != NULL); | |||
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL); | |||
if( SSL_CTX_load_verify_locations(ctx, CACERT, NULL) != 1) { | |||
ERR("Error loading CA DIR"); | |||
} | |||
if (SSL_CTX_set1_curves(ctx, Curves, 1) != 1) { | |||
ERR("Can't set SIDH group"); | |||
} | |||
if (SSL_CTX_set_min_proto_version(ctx, TLS_PROT_VERSION) != 1 || | |||
SSL_CTX_set_max_proto_version(ctx, TLS_PROT_VERSION) != 1) { | |||
ERR("Enforcing protocol to TLSv1.2"); | |||
} | |||
return ctx; | |||
} | |||
int do_client_loop(SSL* ssl) | |||
{ | |||
int err, nwritten; | |||
char buf[80]; | |||
for(;;) | |||
{ | |||
if( !fgets(buf, sizeof(buf), stdin) ) | |||
break; | |||
for(nwritten = 0; nwritten < strlen(buf); nwritten += err) | |||
{ | |||
err = SSL_write(ssl, buf + nwritten, strlen(buf) - nwritten); | |||
if(err<=0) | |||
return 0; | |||
} | |||
} | |||
return 1; | |||
} | |||
void test_Handshake(size_t handshake_nb) { | |||
SSL* ssl; | |||
SSL_CTX* ctx; | |||
int err; | |||
init(); | |||
ctx = setup_client_ctx(); | |||
DBG("Trying to connect"); | |||
for (size_t i=0; i<handshake_nb; i++) { | |||
int fd = connect_once(); | |||
DBG("SSL ctx setup"); | |||
if (!(ssl = SSL_new(ctx))) { | |||
ERR("Error creating an SSL context"); | |||
} | |||
SSL_set_fd(ssl, fd); | |||
DBG("SSL handshake"); | |||
// OZAPTF: do handshake thing | |||
err = SSL_connect(ssl); | |||
if (err<=0) { | |||
ERR("Error connecting SSL err=%d", err); | |||
} | |||
assert(!SSL_session_reused(ssl)); | |||
SSL_free(ssl); | |||
close(fd); | |||
} | |||
SSL_CTX_free(ctx); | |||
} | |||
void test_Read() { | |||
int err, nread=0; | |||
SSL* ssl; | |||
SSL_CTX* ctx; | |||
init(); | |||
ctx = setup_client_ctx(); | |||
DBG("Trying to connect"); | |||
int fd = connect_once(); | |||
DBG("SSL ctx setup"); | |||
if (!(ssl = SSL_new(ctx))) { | |||
ERR("Error creating an SSL context"); | |||
} | |||
SSL_set_fd(ssl, fd); | |||
DBG("SSL handshake"); | |||
err = SSL_connect(ssl); | |||
if (err<=0) { | |||
ERR("Error connecting SSL err=%d", err); | |||
} | |||
DBG("SSL writing"); | |||
if (SSL_write(ssl, (unsigned char*)READ_REQUEST, sizeof(READ_REQUEST) ) <= 0) { | |||
ERR("SSL_write"); | |||
} | |||
DBG("Continue reading"); | |||
do { | |||
#ifdef DEBUG | |||
fwrite(rw_buf,1, nread, stdout); | |||
#endif | |||
for(nread=0; nread<sizeof(rw_buf); nread+=err) { | |||
err = SSL_read(ssl, rw_buf+nread, sizeof(rw_buf) - nread); | |||
if(err <= 0) { | |||
break; | |||
} | |||
} | |||
} while(err>0); | |||
if (0==(SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN)) { | |||
ERR("SSL_Read"); | |||
} | |||
DBG("Shutdown"); | |||
assert(SSL_shutdown(ssl) == 1); | |||
SSL_free(ssl); | |||
SSL_CTX_free(ctx); | |||
close(fd); | |||
} | |||
void test_Write() { | |||
SSL* ssl; | |||
SSL_CTX* ctx; | |||
int err,nread=0; | |||
init(); | |||
ctx = setup_client_ctx(); | |||
DBG("Trying to connect"); | |||
int fd = connect_once(); | |||
DBG("SSL ctx setup"); | |||
if (!(ssl = SSL_new(ctx))) { | |||
ERR("Error creating an SSL context"); | |||
} | |||
SSL_set_fd(ssl, fd); | |||
DBG("SSL handshake"); | |||
err = SSL_connect(ssl); | |||
if (err<=0) { | |||
ERR("Error connecting SSL err=%d", err); | |||
} | |||
DBG("Writing"); | |||
fill_buffer_from_file(rw_buf, sizeof(rw_buf)); | |||
for (size_t i=0; i<RW_ITERATIONS; i++) { | |||
for(nread=0; nread<sizeof(rw_buf); nread+=err) { | |||
err = SSL_write(ssl, rw_buf+nread, sizeof(rw_buf) - nread); | |||
if(err <= 0) { | |||
ERR("SSL_write"); | |||
} | |||
} | |||
} | |||
DBG("Shutdown"); | |||
assert(SSL_shutdown(ssl) == 0); | |||
assert(SSL_shutdown(ssl) == 1); | |||
SSL_free(ssl); | |||
SSL_CTX_free(ctx); | |||
close(fd); | |||
} | |||
int main(int argc, char* argv[]) { | |||
if (argc < 2) { | |||
goto usage; | |||
} | |||
if (!strncmp("test_Handshake", argv[1], strlen("test_Handshake"))) { | |||
test_Handshake(HANDHAKE_REPS); | |||
} else if (!strncmp("test_Read", argv[1], strlen("test_Read"))) { | |||
test_Read(); | |||
} else if (!strncmp("test_Write", argv[1], strlen("test_Write"))) { | |||
test_Write(); | |||
} else { | |||
printf("Unknown test"); | |||
goto usage; | |||
} | |||
exit: | |||
cleanup(); | |||
return 0; | |||
usage: | |||
ERR("\n\nUsage: %s <host>:<port> test_name\nOptions for 'test_name':\n\t" | |||
"test_Handshake\n\ttest_Write\n\ttest_Read\n", argv[0]); | |||
goto exit; | |||
} |
@@ -0,0 +1,84 @@ | |||
#include "common.h" | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <fcntl.h> | |||
#include <netinet/tcp.h> | |||
#include <sys/socket.h> | |||
#include <arpa/inet.h> | |||
#include <unistd.h> | |||
#include <include/openssl/ssl.h> | |||
/* ----------------------------------------------------------------------------- | |||
* @brief Performs TCP 3-way handshake with IP:PORT | |||
* -------------------------------------------------------------------------------- */ | |||
int connect_once(void) { | |||
struct sockaddr_in a; | |||
int fd = socket(AF_INET, SOCK_STREAM, 0); | |||
memset(&a, 0, sizeof(a)); | |||
a.sin_family = AF_INET; | |||
a.sin_addr.s_addr = inet_addr(IP); | |||
a.sin_port = htons(PORT); | |||
// Set socket to blocking, in order to make things simpler | |||
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK )<0) { | |||
ERR("fcntl"); | |||
} | |||
if (connect(fd, (struct sockaddr *) &a, sizeof(a))<0) { | |||
ERR("Econnect"); | |||
} | |||
DBG("Connected"); | |||
return fd; | |||
} | |||
/* ----------------------------------------------------------------------------- | |||
* @brief Fills the buffer with random data. | |||
*------------------------------------------------------------------------------ */ | |||
void fill_buffer_from_file(unsigned char *b, size_t sz) { | |||
FILE * fd = fopen(RANDOM_DATA_FILE, "r"); | |||
if (!fd) { | |||
ERR("fopen"); | |||
} | |||
if (fread(b, 1, sz, fd) < sz) { | |||
// Random data file smaller than a buffer | |||
ERR("fread"); | |||
} | |||
if (fclose(fd)) { | |||
ERR("fclose"); | |||
} | |||
} | |||
/* ----------------------------------------------------------------------------- | |||
* @brief Initializes BoringSSL structures | |||
*------------------------------------------------------------------------------ */ | |||
void init(void) { | |||
OpenSSL_add_all_algorithms(); | |||
SSL_load_error_strings(); | |||
SSL_library_init(); | |||
CRYPTO_library_init(); | |||
if(!SSL_library_init()) | |||
{ | |||
fprintf(stderr, "** OpenSSL initialization failed!\n"); | |||
exit(-1); | |||
} | |||
} | |||
/* ----------------------------------------------------------------------------- | |||
* @brief Tears down what was initialized in init() above | |||
*------------------------------------------------------------------------------ */ | |||
void cleanup(void) { | |||
ERR_free_strings(); | |||
ERR_clear_error(); | |||
CRYPTO_set_locking_callback(NULL); | |||
CRYPTO_set_id_callback(NULL); | |||
EVP_cleanup(); | |||
CRYPTO_cleanup_all_ex_data(); | |||
} |
@@ -0,0 +1,64 @@ | |||
#ifndef __COMMON_H__ | |||
#define __COMMON_H__ | |||
#include <string.h> | |||
#include <stdlib.h> | |||
#include <assert.h> | |||
#ifdef DEBUG | |||
#include <stdio.h> | |||
#endif | |||
#define PORT 1443 | |||
#define IP "127.0.0.1" | |||
#define SERVER "localhost" | |||
#define CLIENT "localhost" | |||
#define CACERT "etc/ca/ca.cert.pem" | |||
//#define CERT_HOSTNAME "www.cert_testing.com" | |||
#define CERT_HOSTNAME "www.dmv.com" | |||
#define KEYFILE_PASS "test123" | |||
#define READ_REQUEST "ReadRequest" | |||
#define HANDHAKE_REPS 200 | |||
// Keep random data file must at least same size as a buffer size | |||
#define RANDOM_DATA_FILE "etc/random_data" | |||
#define BUFFER_SIZE 1024 | |||
// Amount bytes of plaintext data exchanged in read-write stets is BUFFER_SIZE*RW_ITERATOIONS | |||
#ifdef DEBUG | |||
#define RW_ITERATIONS (1024*10) // 10 MB | |||
#else | |||
#define RW_ITERATIONS (1024*200) // 1GB | |||
#endif | |||
// Utils | |||
#define LOG_I(...) \ | |||
do { \ | |||
(void) fprintf(stdout, "[%s() %s:%d] ", __func__, __FILE__, __LINE__); \ | |||
(void) fprintf(stdout, __VA_ARGS__); \ | |||
(void) fprintf(stdout, "\n"); \ | |||
} while (0) | |||
#define ERR(...) \ | |||
do { \ | |||
LOG_I(__VA_ARGS__); \ | |||
exit(-1); \ | |||
} while (0) | |||
#define LOG(...) LOG_I(__VA_ARGS__) | |||
#ifdef DEBUG | |||
#define DBG(...) LOG_I(__VA_ARGS__) | |||
#else | |||
#define DBG(...) | |||
#endif | |||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) | |||
int connect_once(void); | |||
void init(void); | |||
void cleanup(void); | |||
void fill_buffer_from_file(unsigned char *b, size_t sz); | |||
// Available tests | |||
void test_Write(void); | |||
void test_Read(void); | |||
void test_Handshake(size_t); | |||
#endif // __COMMON_H__ |
@@ -0,0 +1,260 @@ | |||
#include <netinet/tcp.h> | |||
#include <sys/socket.h> | |||
#include <arpa/inet.h> | |||
// include/ path is here for a reason - to make sure we compile against boringssl (temporary solution) | |||
#include <include/openssl/rand.h> | |||
#include <include/openssl/ssl.h> | |||
#include <include/openssl/x509v3.h> | |||
#include <pthread.h> | |||
#include "common.h" | |||
// Enforce this protocol version | |||
#define TLS_PROT_VERSION TLS1_3_VERSION | |||
static const int Curves[3] = {NID_CECPQ2, NID_CECPQ2b, NID_X25519}; | |||
static const struct CertDesc_t { | |||
const char* arg; | |||
const char* cert; | |||
const char* key; | |||
const char* cipher; | |||
const int* curves; | |||
} Certs[] = { | |||
{ | |||
.arg = "RSA_2048", | |||
.key = "etc/rsa_2048.key", | |||
.cert = "etc/rsa_2048.pem", | |||
.cipher = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", | |||
.curves = Curves, | |||
}, | |||
{ | |||
.arg = "RSA_3072", | |||
.key = "etc/rsa_3072.key", | |||
.cert = "etc/rsa_3072.pem", | |||
.cipher = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", | |||
.curves = Curves, | |||
}, | |||
{ | |||
.arg = "ECDSA_256", | |||
.key = "etc/ecdsa_256.key", | |||
.cert = "etc/ecdsa_256.pem", | |||
.cipher = "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", | |||
.curves = Curves, | |||
} | |||
}; | |||
const struct CertDesc_t* get_cert_desc(const char* c) { | |||
for(size_t i=0; i<ARRAY_SIZE(Certs); i++) { | |||
if (!memcmp(Certs[i].arg, c, strlen(Certs[i].arg))) { | |||
return &Certs[i]; | |||
} | |||
} | |||
ERR("Critical error"); | |||
} | |||
// Buffer used for read/write tests | |||
unsigned char rw_buf[BUFFER_SIZE]; | |||
int pass_cb(char *buf, int size, int rwflag, void *u) { | |||
DBG("Using password " KEYFILE_PASS); | |||
// password for all keys is "test123" | |||
memcpy(buf, KEYFILE_PASS, strlen(KEYFILE_PASS)); | |||
return strlen(KEYFILE_PASS); | |||
} | |||
static int accept_once(void) { | |||
int fd, client; | |||
int reuseval = 1; | |||
struct sockaddr_in a; | |||
size_t a_len = sizeof(a); | |||
// configure | |||
memset(&a, 0, a_len); | |||
a.sin_family = AF_INET; | |||
a.sin_port = htons(PORT); | |||
a.sin_addr.s_addr = INADDR_ANY; | |||
fd = socket(PF_INET, SOCK_STREAM, 0); | |||
if (setsockopt(fd,SOL_SOCKET, SO_REUSEADDR, &reuseval, sizeof(reuseval))) { | |||
ERR("setsockopt"); | |||
} | |||
if (bind(fd, (struct sockaddr *)&a, sizeof(a))) { | |||
ERR("bind"); | |||
} | |||
if (listen(fd, 1)) { | |||
ERR("listen"); | |||
} | |||
client = accept(fd, (struct sockaddr *)&a, (socklen_t *)&a_len); | |||
if (client<0) { | |||
ERR("accept"); | |||
} | |||
return client; | |||
} | |||
static SSL_CTX* setup_server_ctx(const char* cert_name) { | |||
SSL_CTX* ctx = SSL_CTX_new(TLS_method()); | |||
assert(ctx); | |||
const struct CertDesc_t *c = get_cert_desc(cert_name); | |||
SSL_CTX_set_default_passwd_cb(ctx, &pass_cb); | |||
if(SSL_CTX_use_certificate_file(ctx, c->cert, SSL_FILETYPE_PEM) != 1) | |||
ERR("Error loading certificate from file"); | |||
if(SSL_CTX_use_PrivateKey_file(ctx, c->key, SSL_FILETYPE_PEM) != 1) | |||
ERR("Error loading private key from file"); | |||
if (SSL_CTX_set_strict_cipher_list(ctx, c->cipher) != 1) { | |||
ERR("Error setting cipher list"); | |||
} | |||
if (!SSL_CTX_set1_curves(ctx, c->curves, 1)) { | |||
ERR("Enforcing curve"); | |||
} | |||
if (SSL_CTX_set_min_proto_version(ctx, TLS_PROT_VERSION) != 1 || | |||
SSL_CTX_set_max_proto_version(ctx, TLS_PROT_VERSION) != 1) { | |||
ERR("Enforcing protocol to TLSv1.2"); | |||
} | |||
return ctx; | |||
} | |||
static void start_writing(SSL *ssl) { | |||
int nread,err; | |||
DBG("Start writing"); | |||
fill_buffer_from_file(rw_buf, sizeof(rw_buf)); | |||
for (size_t i=0; i<RW_ITERATIONS; i++) { | |||
for(nread=0; nread<sizeof(rw_buf); nread+=err) { | |||
err = SSL_write(ssl, rw_buf+nread, sizeof(rw_buf) - nread); | |||
if(err <= 0) { | |||
ERR("SSL_write"); | |||
} | |||
} | |||
} | |||
} | |||
static int do_server_loop(SSL* ssl) { | |||
int nread,err; | |||
DBG("Check if first packet is ReadRequest"); | |||
for(nread=0; nread<strlen(READ_REQUEST); nread+=err) { | |||
err = SSL_read(ssl, rw_buf+nread, sizeof(rw_buf) - nread); | |||
if (err <=0) { | |||
break; | |||
} | |||
} | |||
DBG("Check if server loop should be finished"); | |||
// Stop here if shutdown requested | |||
if (SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) { | |||
return 1; | |||
} | |||
// Check if client wants to read | |||
if (nread && !memcmp(READ_REQUEST, rw_buf, nread)) { | |||
start_writing(ssl); | |||
return 2; // server initiated closure | |||
} | |||
// Keep reading till connection closed | |||
DBG("Continue reading"); | |||
do { | |||
for(nread=0; nread<sizeof(rw_buf); nread+=err) { | |||
err = SSL_read(ssl, rw_buf+nread, sizeof(rw_buf) - nread); | |||
if(err <= 0) { | |||
break; | |||
} | |||
} | |||
} while(err>0); | |||
return (SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) ? 1 : 0; | |||
} | |||
#ifdef DEBUG | |||
static const char* DBG_get_curve(SSL* ssl) { | |||
const int id = SSL_get_curve_id(ssl); | |||
if (!id) return "N/A"; | |||
return SSL_get_curve_name(id); | |||
} | |||
#endif | |||
// Interface for accepting | |||
int main(int argc, char *argv[]) | |||
{ | |||
SSL *ssl; | |||
SSL_CTX *ctx; | |||
int fd, ret; | |||
if (argc < 2) { | |||
goto usage; | |||
} | |||
// Start server | |||
init(); | |||
ctx = setup_server_ctx(argv[1]); | |||
fd = accept_once(); | |||
for(;;) { | |||
DBG("SSL Accepting"); | |||
if(!(ssl = SSL_new(ctx))) { | |||
DBG("Error creating SSL context"); | |||
} | |||
SSL_set_fd(ssl, fd); | |||
ret = SSL_accept(ssl); | |||
//printf("%s\n", SSL_get_curve_name(SSL_get_curve_id(ssl))); | |||
if (ret<=0) { | |||
ret = SSL_get_error(ssl, ret); | |||
if (ret == SSL_ERROR_SYSCALL) { | |||
DBG("Connection closed"); | |||
goto end; | |||
} else { | |||
ERR("Critical error occured %d", ret); | |||
} | |||
} | |||
DBG("Protocol: %s Cipher %s Curve %s", SSL_get_version(ssl), SSL_get_cipher_name(ssl), DBG_get_curve(ssl)); | |||
DBG("server loop"); | |||
ret = do_server_loop(ssl); | |||
if(ret) { | |||
DBG("Shutdown"); | |||
SSL_set_read_ahead(ssl, 0); | |||
if (ret==2) { | |||
// Server is closing | |||
SSL_shutdown(ssl); | |||
} | |||
assert(SSL_shutdown(ssl)==1); | |||
} | |||
else { | |||
DBG("Shutdown - error case"); | |||
goto end; | |||
} | |||
SSL_clear(ssl); | |||
} | |||
SSL_CTX_free(ctx); | |||
end: | |||
cleanup(); | |||
return 0; | |||
usage: | |||
ERR("\n\nUsage: %s server certificate \nOptions for 'server certificate':\n\t" | |||
"RSA_2048\n\t" | |||
"RSA_3072\n\t" | |||
"ECDSA_256\n\t", | |||
argv[0]); | |||
goto end; | |||
} |
@@ -0,0 +1,92 @@ | |||
# This file is automatically @generated by Cargo. | |||
# It is not intended for manual editing. | |||
[[package]] | |||
name = "bitflags" | |||
version = "1.1.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "cc" | |||
version = "1.0.38" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "cfg-if" | |||
version = "0.1.9" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "ctrlc" | |||
version = "3.1.3" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
dependencies = [ | |||
"nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", | |||
] | |||
[[package]] | |||
name = "libc" | |||
version = "0.2.60" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "nix" | |||
version = "0.14.1" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
dependencies = [ | |||
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | |||
] | |||
[[package]] | |||
name = "rawhammer" | |||
version = "0.1.0" | |||
dependencies = [ | |||
"ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"thread-control 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", | |||
] | |||
[[package]] | |||
name = "thread-control" | |||
version = "0.1.2" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "void" | |||
version = "1.0.2" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "winapi" | |||
version = "0.3.7" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
dependencies = [ | |||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | |||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | |||
] | |||
[[package]] | |||
name = "winapi-i686-pc-windows-gnu" | |||
version = "0.4.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[[package]] | |||
name = "winapi-x86_64-pc-windows-gnu" | |||
version = "0.4.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
[metadata] | |||
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" | |||
"checksum cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "ce400c638d48ee0e9ab75aef7997609ec57367ccfe1463f21bf53c3eca67bf46" | |||
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" | |||
"checksum ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7dfd2d8b4c82121dfdff120f818e09fc4380b0b7e17a742081a89b94853e87f" | |||
"checksum libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "d44e80633f007889c7eff624b709ab43c92d708caad982295768a7b13ca3b5eb" | |||
"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" | |||
"checksum thread-control 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22e002431352cce4e76fd6fe77d5bf1b75ff790ea790602f0579ce58641c2eea" | |||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" | |||
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" | |||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | |||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@@ -0,0 +1,11 @@ | |||
[package] | |||
name = "rawhammer" | |||
version = "0.1.0" | |||
authors = ["Kris Kwiatkowski <kris@cloudflare.com>"] | |||
edition = "2018" | |||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |||
[dependencies] | |||
ctrlc = "3.1.3" | |||
thread-control = "0.1.2" |
@@ -0,0 +1,284 @@ | |||
use std::io::Write; | |||
use std::net::*; | |||
use std::env; | |||
use std::time::Duration; | |||
use std::sync::mpsc::sync_channel; | |||
use std::thread; | |||
use std::time; | |||
use ctrlc; | |||
use thread_control::*; | |||
static CH_X25519: &'static [u8] = b"\ | |||
\x16\x03\x01\x00\xfc\x01\x00\x00\xf8\x03\x03\x84\x14\x34\x1d\x32\ | |||
\x62\x53\x6c\x37\xb5\xdd\xe6\xd9\x58\x34\xd7\x3b\x36\xf0\xb8\x05\ | |||
\xd1\xba\x5c\xa6\x47\x15\xae\xd6\x35\x54\x62\x20\x1f\x31\x5c\xc0\ | |||
\x2a\xb3\x05\xb3\x7f\x36\x5d\xe5\xe1\x22\x36\xd3\xd7\x29\xf2\x87\ | |||
\xe3\x3a\xbf\xac\x9f\x3b\xd6\x57\xd9\x54\xb5\x48\x00\x24\x13\x01\ | |||
\x13\x02\x13\x03\xc0\x2b\xc0\x2f\xc0\x2c\xc0\x30\xcc\xa9\xcc\xa8\ | |||
\xc0\x09\xc0\x13\xc0\x0a\xc0\x14\x00\x9c\x00\x9d\x00\x2f\x00\x35\ | |||
\x00\x0a\x01\x00\x00\x8b\x00\x00\x00\x17\x00\x15\x00\x00\x12\x77\ | |||
\x77\x77\x2e\x63\x6c\x6f\x75\x64\x66\x6c\x61\x72\x65\x2e\x63\x6f\ | |||
\x6d\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\x0a\x00\x04\x00\x02\ | |||
\x00\x1d\x00\x0b\x00\x02\x01\x00\x00\x23\x00\x00\x00\x0d\x00\x14\ | |||
\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08\x06\ | |||
\x06\x01\x02\x01\x00\x33\x00\x26\x00\x24\x00\x1d\x00\x20\x05\x4b\ | |||
\x0a\x0a\xb2\xe6\x39\xb1\x25\x40\x88\x8a\x18\x5b\x02\x88\x7e\x0c\ | |||
\x49\x5c\xfc\xc8\xd4\xcd\x9d\xab\x2c\x1d\x91\x23\xce\x42\x00\x2d\ | |||
\x00\x02\x01\x01\x00\x2b\x00\x09\x08\x03\x04\x03\x03\x03\x02\x03\x01"; | |||
static CH_P521: &'static [u8] = b"\ | |||
\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x1c\x35\x05\x88\x16\ | |||
\x84\x48\xae\xc7\xaf\x40\xed\x64\xa4\x25\x73\xbb\xb9\xc0\x2c\x46\ | |||
\x02\x2d\xc8\xa7\x18\x27\xca\x6e\x7a\xe9\x52\x20\x8f\x88\x3d\x7f\ | |||
\xd0\xe5\x75\x4e\xa1\x94\x0b\x60\x26\xdf\xdd\xe1\x61\xff\x04\x67\ | |||
\xd5\x47\x88\x83\x1f\x49\x2b\xdc\x08\xc2\x10\x82\x00\x24\x13\x01\ | |||
\x13\x02\x13\x03\xc0\x2b\xc0\x2f\xc0\x2c\xc0\x30\xcc\xa9\xcc\xa8\ | |||
\xc0\x09\xc0\x13\xc0\x0a\xc0\x14\x00\x9c\x00\x9d\x00\x2f\x00\x35\ | |||
\x00\x0a\x01\x00\x01\x8f\x00\x00\x00\x17\x00\x15\x00\x00\x12\x77\ | |||
\x77\x77\x2e\x63\x6c\x6f\x75\x64\x66\x6c\x61\x72\x65\x2e\x63\x6f\ | |||
\x6d\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\x0a\x00\x04\x00\x02\ | |||
\x00\x19\x00\x0b\x00\x02\x01\x00\x00\x23\x00\x00\x00\x0d\x00\x14\ | |||
\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08\x06\ | |||
\x06\x01\x02\x01\x00\x33\x00\x8b\x00\x89\x00\x19\x00\x85\x04\x01\ | |||
\xf0\xe8\x81\xa5\x0b\x6d\x59\x6a\xaf\xfc\xe3\xf0\xfc\x09\x09\x12\ | |||
\x2b\x00\x73\xd0\x06\xc5\x4f\x7e\xa1\xb2\x1c\x95\xe4\x2f\x7e\x96\ | |||
\x45\x33\xf0\x1e\x40\x31\x9c\xe9\xbe\xc1\x21\x10\xd0\x90\xc8\xa5\ | |||
\x0c\x08\xd1\x82\x05\xd9\x03\xcf\xfe\x57\xdc\x5e\xac\x80\x73\x09\ | |||
\xf7\x01\xaf\xde\xff\xee\xd4\x49\x05\x5f\xa4\xae\xbb\x16\x40\x36\ | |||
\x43\x24\xa6\x2a\x79\xd6\x1e\xa4\xe5\xd1\xf9\x89\xf8\x04\x1a\xf1\ | |||
\x42\x7a\xc9\x21\x27\xbc\x04\x7f\x3c\x90\x88\xab\x0c\x2d\xf8\xc8\ | |||
\xb4\x3b\x93\x63\x44\xe8\x49\xc0\xec\x46\xa3\x17\x4c\xa0\x8f\x82\ | |||
\x9d\x24\x94\x00\x2d\x00\x02\x01\x01\x00\x2b\x00\x09\x08\x03\x04\ | |||
\x03\x03\x03\x02\x03\x01\x00\x15\x00\x9b\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ | |||
\x00\x00\x00\x00\x00"; | |||
static CH_SIKE: &'static [u8] = b"\ | |||
\x16\x03\x01\x02\x46\x01\x00\x02\x42\x03\x03\xf6\x5d\xac\x6f\x1d\ | |||
\x7c\x4e\x8d\x33\x29\xc2\xc9\xf7\xde\x80\xe1\xd6\x75\xda\x34\x1f\ | |||
\x48\xbe\xec\x81\xed\x61\x99\x0b\x14\x0b\x7a\x20\xa6\xe1\x5c\xde\ | |||
\x61\xb5\x70\x01\x9a\x8c\x2e\xab\xb2\x52\x66\x53\xa7\x6b\xad\x5c\ | |||
\x6e\xc0\x0d\x1b\xba\x37\x4b\x3e\x2c\xbd\x83\x26\x00\x24\x13\x01\ | |||
\x13\x02\x13\x03\xc0\x2b\xc0\x2f\xc0\x2c\xc0\x30\xcc\xa9\xcc\xa8\ | |||
\xc0\x09\xc0\x13\xc0\x0a\xc0\x14\x00\x9c\x00\x9d\x00\x2f\x00\x35\ | |||
\x00\x0a\x01\x00\x01\xd5\x00\x00\x00\x17\x00\x15\x00\x00\x12\x77\ | |||
\x77\x77\x2e\x63\x6c\x6f\x75\x64\x66\x6c\x61\x72\x65\x2e\x63\x6f\ | |||
\x6d\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\x0a\x00\x04\x00\x02\ | |||
\xfe\x32\x00\x0b\x00\x02\x01\x00\x00\x23\x00\x00\x00\x0d\x00\x14\ | |||
\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08\x06\ | |||
\x06\x01\x02\x01\x00\x33\x01\x70\x01\x6e\xfe\x32\x01\x6a\x3d\x8e\ | |||
\x3e\x33\x88\xb4\x2e\xf9\x24\x6d\x42\x4a\xa1\x20\xc9\x8a\x94\xec\ | |||
\x68\xa0\x91\x83\xa9\x9b\xb3\x1f\x80\x17\x7f\xb2\xf0\x31\xc8\x04\ | |||
\x32\x67\x42\xc8\xda\x9a\x4d\x33\xbf\xb7\xa8\xb5\x1a\xea\x81\x7d\ | |||
\xfc\xc6\xad\x71\x10\x3e\xef\x8f\x70\xcd\x07\x30\x57\x1c\xe4\x2c\ | |||
\xec\xca\xbb\xbb\x57\x85\xcf\x83\x93\x1b\x57\x73\xdd\xc8\x84\x77\ | |||
\x42\xc3\x8b\x87\x00\xd9\x64\xeb\xa5\xfa\xcb\xbd\xa9\x94\x2e\xd8\ | |||
\x17\xf5\x77\x28\x8c\x77\xe5\x11\xbd\x51\x76\x52\x89\x50\x56\x7a\ | |||
\x3d\xbf\xfd\xa1\x22\xb0\xc7\xc4\xad\x89\x31\x27\x20\x7a\x45\x43\ | |||
\x6a\xf6\x3c\xff\x71\x11\xbd\x28\xf7\x78\x2f\x01\x36\x0e\x18\x72\ | |||
\xf3\x8a\x5f\x0e\x34\x6f\xa1\x8e\x33\xeb\x02\x25\x1e\xb8\x61\xb0\ | |||
\x10\xb0\xca\x03\x6b\x03\x3e\x71\x9a\xf9\x93\x83\x36\x29\x11\xdc\ | |||
\x89\xbd\xa3\xb1\x9b\xac\x3b\x39\x1c\xdc\xf3\x4e\xff\x9d\x86\xb6\ | |||
\xc8\x66\x00\x1b\x5e\x0f\x2b\xa2\x08\xde\x4c\xa6\x18\x03\x83\x89\ | |||
\x50\x7f\x60\x29\xfa\xac\xf1\x64\xfd\xbc\x0c\x6c\x3c\x48\x73\xd4\ | |||
\xc8\x24\xe4\x25\x9d\xb1\xd5\x14\xfa\x54\xc8\xea\xdc\xa1\xb0\x03\ | |||
\x4e\xad\x29\x29\xb7\xb6\x8d\xd2\xef\x00\x82\xb0\x3c\x2e\x01\x0b\ | |||
\xc3\x4e\x61\x04\xad\xd1\xbd\x4e\xac\x4a\xb5\x40\x46\x36\xfc\xf3\ | |||
\x48\xb1\x10\xfb\xcc\xd7\x3b\xa1\xc1\xca\x9e\xf2\xdd\x80\x7d\x8c\ | |||
\x12\xfc\x22\x05\x2d\xd8\x15\x8a\x33\x73\xc8\x92\xbd\xf0\x92\x51\ | |||
\x00\x5c\xa1\x7b\x4d\x95\x92\xd9\x52\x17\x7b\xbb\xaa\xa1\x02\xc7\ | |||
\x2c\x82\x51\x9a\xf0\xb3\xb0\xb7\x28\x78\x85\xf4\x0d\xee\xa4\x1b\ | |||
\x67\x72\x25\xf3\x77\xcf\x55\x11\x10\x3b\xa7\xad\xed\x32\x10\x41\ | |||
\xdd\x43\x85\xfd\x00\x68\x10\x01\x00\x2d\x00\x02\x01\x01\x00\x2b\ | |||
\x00\x09\x08\x03\x04\x03\x03\x03\x02\x03\x01"; | |||
static CH_NTRU: &'static [u8] = b"\ | |||
\x16\x03\x01\x05\x6e\x01\x00\x05\x6a\x03\x03\xea\xc2\x1e\xc1\x29\ | |||
\x8a\xee\x5b\x02\xf1\x7d\x1c\xf3\x54\x02\x8c\x87\x40\x56\x16\xad\ | |||
\xa9\x11\xf2\x48\x8a\xde\x33\x82\x42\x02\x04\x20\xd3\x7f\x7a\x35\ | |||
\xd3\x8f\xa1\x55\xe2\x49\x78\xca\xc0\xff\x48\xfc\x34\x72\x06\x85\ | |||
\xd9\x71\xaf\xb8\xfc\xdf\xef\x2f\x24\xf2\xf2\x51\x00\x24\x13\x01\ | |||
\x13\x02\x13\x03\xc0\x2b\xc0\x2f\xc0\x2c\xc0\x30\xcc\xa9\xcc\xa8\ | |||
\xc0\x09\xc0\x13\xc0\x0a\xc0\x14\x00\x9c\x00\x9d\x00\x2f\x00\x35\ | |||
\x00\x0a\x01\x00\x04\xfd\x00\x00\x00\x17\x00\x15\x00\x00\x12\x77\ | |||
\x77\x77\x2e\x63\x6c\x6f\x75\x64\x66\x6c\x61\x72\x65\x2e\x63\x6f\ | |||
\x6d\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\x0a\x00\x04\x00\x02\ | |||
\x41\x38\x00\x0b\x00\x02\x01\x00\x00\x23\x00\x00\x00\x0d\x00\x14\ | |||
\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08\x06\ | |||
\x06\x01\x02\x01\x00\x33\x04\x98\x04\x96\x41\x38\x04\x92\xef\x1c\ | |||
\x6b\x86\x5c\x41\xd0\x92\x5c\xcd\x8e\x44\xea\xbb\x5e\xb8\x7d\xd1\ | |||
\x96\x41\xeb\xd8\x59\xa1\xf0\xd0\x09\x6d\x50\xca\x69\x7c\xa0\x29\ | |||
\x5a\xb6\x07\xd6\xb9\x89\x0d\x4c\x29\xc5\x5e\xb8\xf9\x08\x34\xce\ | |||
\xde\xa3\xe0\x04\xee\xfc\x92\x06\x97\xc8\x5f\x48\x27\xd6\xe5\x36\ | |||
\xed\x48\x2d\x35\x84\xc2\x87\xc7\x5a\xc6\xbe\xdd\xc2\x52\x12\x23\ | |||
\xee\xa5\x0d\x95\xed\xaa\xee\xa6\x83\x4d\x61\xe9\xae\x6a\xb1\x49\ | |||
\x95\x5e\x0c\x55\xa1\x53\x48\xe5\x63\x3f\x7c\x85\xb6\xad\xd7\xc6\ | |||
\x23\xba\x67\xea\xf4\x0d\x5d\x08\x41\xf9\x46\xab\x86\x6d\x9c\xa3\ | |||
\x34\x1d\x77\x80\x3a\xe3\xab\x62\x24\xcb\x9a\xd9\xca\x2e\xb6\xa6\ | |||
\x24\x7d\xb5\x6b\x8c\xd5\x46\x03\x52\x36\xa0\x35\xdd\xc4\x52\xa1\ | |||
\x74\x1e\x82\xb1\xe0\xc4\x41\xf1\x0b\xa6\xd5\x51\xd1\xd0\x11\xe4\ | |||
\x76\x2c\x32\x49\xc6\xc7\x1c\xca\xb2\x4a\xd5\x76\x33\xbf\x52\x8f\ | |||
\xd1\x04\x07\xba\x4b\x91\x30\xd8\x35\x01\x62\xdb\x8f\x9f\x48\xd0\ | |||
\xf3\x2c\x86\x05\x0e\xaf\x32\xe8\x91\x7b\xa8\x8d\xd2\xf3\x1e\x61\ | |||
\x6d\xa3\x3a\x44\x23\x64\xf2\x6e\x53\x90\x33\xd7\x75\x71\x34\x27\ | |||
\xfd\x77\x7c\x11\xcc\x21\x19\x96\x2d\x65\xa5\xff\xdc\x9b\x3b\x05\ | |||
\xec\xc2\xe2\x3c\xf0\xad\xa7\xd7\x69\xcf\x83\xa7\xb9\xd9\x61\x99\ | |||
\xcc\x50\xee\x8d\x76\xac\xf6\x3d\x60\x39\xda\xbc\x96\x1a\xb5\x77\ | |||
\xe6\x59\xa4\x72\x54\xee\xc8\x93\x69\x40\x24\xc5\xc2\xdb\x49\x23\ | |||
\xf8\xce\xdf\x7e\x59\x80\x4d\x1d\xf9\x06\xf9\x8f\xf1\xd8\xf7\xd3\ | |||
\x56\xc2\xfd\x0c\x1c\xe0\x33\x63\xed\x47\xa7\xce\xb6\x2a\x85\x1b\ | |||
\x86\x69\xb9\x46\x37\x36\xac\xa5\x10\xe3\x0c\x77\xac\x0b\x17\x39\ | |||
\x88\xc3\x71\xac\xdb\x88\x04\x77\x7a\x49\xaf\x9a\xd2\xe6\x27\x51\ | |||
\x99\x41\xd9\xea\x9b\x23\x38\xd8\x96\x83\xaa\x0e\x3a\x7c\xe8\x3d\ | |||
\x50\x0d\xce\x40\xf2\x77\x1c\x2c\x1f\x20\x4f\x83\x7f\xfa\xc9\xf9\ | |||
\xf3\x17\x8d\xba\x92\xee\x18\xa6\xc1\x9f\x1a\x7b\x5d\xd2\xe3\x4f\ | |||
\xab\x49\xb3\xf1\x91\xc4\xd6\x7f\x32\xda\xad\x24\x41\x58\xef\xc5\ | |||
\xc6\xcc\x58\x6a\x69\x21\x0b\x6f\xa2\x02\xcc\x91\xe2\x2f\x68\x41\ | |||
\x43\x9b\x38\x1b\xfa\x03\x1b\x40\x5a\xdc\xfa\x25\xda\x21\x11\x4b\ | |||
\x40\x9f\x79\x13\xce\x77\x8d\xbb\x37\x04\xc3\x49\x0f\xf7\xd8\x70\ | |||
\xf4\x4e\xa3\xe1\x1b\x00\x09\x3a\x09\xb9\xed\x02\xbc\x06\xb7\x54\ | |||
\x75\x2a\x67\x97\xaf\x13\x0d\xd9\x3c\xa9\xff\x48\x66\x3a\xa8\x5b\ | |||
\x20\x23\xc7\xf9\x45\x16\x5f\x6c\xa1\x19\xc2\x54\xff\xd9\x5e\xbe\ | |||
\xcd\x73\xc1\x41\x09\xf7\xef\xc9\x26\x4b\x9d\xeb\x0c\x16\x06\x92\ | |||
\x66\x9d\x8e\xa0\x54\xe8\xe5\x9f\x6c\xfd\x79\x3a\xdd\xc8\x4c\xb8\ | |||
\xab\xfa\x42\xfd\x44\x50\xa1\x38\x9f\x6d\xef\x80\xf4\xd3\xe4\x06\ | |||
\x5c\xf7\x2e\x01\x75\xd8\x0c\xb9\x01\x7a\xf0\x71\x91\x5d\x1e\x6d\ | |||
\x03\x19\x2d\x59\x4d\x8a\x48\x3d\x9c\x4d\x93\xc4\xa3\x9a\xd1\xf5\ | |||
\x98\xf6\xf7\x2b\xf1\x9b\xbc\x06\x05\x04\xb6\x4b\x97\x55\x7d\x09\ | |||
\x4a\xf6\x69\xf6\x46\x76\xdf\x68\xd6\xd1\x82\xa5\xa6\xc1\x8b\xb9\ | |||
\x80\x55\xca\x7b\x6a\x58\x67\x73\x26\xbb\x77\x2c\xa5\xe1\xe2\xc6\ | |||
\x5f\x99\x39\x53\xbc\x66\x4f\x2e\xcf\xa8\xe5\x49\xea\xa1\x5b\xaf\ | |||
\xf4\x63\x8f\x7e\x72\xa8\x9c\x5b\x45\xba\xd5\x54\x62\xc8\xf6\xb5\ | |||
\xe2\x28\x8b\xd7\x96\xf6\xf7\xcd\xfb\x3b\x75\xd6\x73\x7d\x40\xf5\ | |||
\xfd\x3a\x5e\x82\xb5\x3f\xcc\x2f\xd6\x04\xf2\xce\x33\x6c\xe4\xb3\ | |||
\x56\x0c\x94\x5a\x59\x0a\xf8\xb8\x92\xd1\xaa\x92\x59\xa6\x91\xd5\ | |||
\xf5\x5b\x9f\x6b\x25\x02\x18\xa0\x03\x96\x90\x82\x73\x54\x2e\x83\ | |||
\xd7\x69\xb4\x73\x81\x69\x82\xca\x40\x50\x16\x46\x7e\x48\x18\xd1\ | |||
\x94\x66\xd8\xd1\x44\x4b\x48\x7d\xd7\x1b\xc2\x75\x9e\x29\x03\xa5\ | |||
\xef\x79\x5f\xd7\x05\x76\x28\xc8\x02\x3b\x36\x9d\xcb\x5e\x8b\x73\ | |||
\x69\x86\xa3\x70\x71\x2b\x3e\xe6\xba\x8e\x50\x64\x85\xb1\x3d\x34\ | |||
\xfd\x5f\x33\x95\xe0\xf0\xd5\xfd\x4a\xab\x96\xb4\xbe\xda\x9d\xc3\ | |||
\xf4\xf1\xd8\x57\xdc\x12\xe4\x2e\xa6\x64\x20\xa1\x78\xfd\xf5\x10\ | |||
\xba\x78\x18\x44\xa4\x8d\x47\x29\xdd\x12\x8e\x7d\x27\x3c\x3d\xc8\ | |||
\xe5\x7f\xa7\xaf\xa1\xdc\xa5\x1c\x1d\x84\x4d\x8f\x17\xdd\x15\x84\ | |||
\x52\xd9\x9a\x72\x5e\x1a\x68\xfd\xbc\xff\xe2\xd2\xbb\xdc\xc0\x19\ | |||
\x33\x96\xf7\x4e\x3b\xad\x3b\xde\xf2\x44\x9e\xf7\x77\x2a\x5b\x0e\ | |||
\xb9\xcd\x87\x6e\xc5\x63\x70\xc4\x3d\x0a\x12\x0d\x2a\x63\xca\x6f\ | |||
\xbb\x90\x04\x2f\x9c\xf8\x3a\xfd\x04\x20\x78\x58\x1b\x69\x72\x40\ | |||
\xfe\x75\xc2\x36\x30\x4f\x36\x6f\x07\x4d\xbb\xca\x8c\xf4\x8c\xd5\ | |||
\x1f\x4a\x03\x23\xc3\xcc\x32\xa6\xd8\xb0\xe9\x67\x0f\xda\x47\xa0\ | |||
\xa1\x03\xe3\x7a\xc1\xac\x5c\xc7\x3d\x8f\xff\x67\x30\x05\x97\xfb\ | |||
\x81\x7a\xc2\xd8\x52\x60\xd0\xdc\x3f\xa8\x97\x73\x55\x70\x81\x58\ | |||
\x5d\x17\x57\x13\xeb\xa4\x3d\x94\x93\x1e\x20\x06\x98\x7a\xbe\xd2\ | |||
\x79\xb4\x1a\xe8\x80\x73\x01\xa7\xee\xc7\x4f\xfd\x2c\xe5\xef\xc9\ | |||
\x76\x13\x3c\xe4\x0a\x9a\x1a\x54\xbb\xf2\xba\xf8\x37\xa5\x28\x0d\ | |||
\x73\x30\x4c\x66\x1c\xff\x36\x67\xa8\xd3\x04\x4f\x6e\x2a\x17\x22\ | |||
\xed\x77\x75\x3e\xb3\xf3\x63\x1b\x89\xd7\xfe\xd6\x97\x5b\x68\x59\ | |||
\x92\x79\x2d\xa0\x17\x9d\x37\x48\xb8\xad\xbf\x47\x2c\xa3\x6b\x00\ | |||
\x27\x09\xb4\x53\xe2\xeb\x54\x9e\xe6\x10\xd2\x2c\x6b\xd8\xf1\x61\ | |||
\x35\xb0\x26\xbe\xfb\xff\x55\xa9\xaf\xf2\xb6\xe1\xf6\x6a\x4f\xb7\ | |||
\x9f\xa7\xb7\xee\xea\x54\xd4\xcd\xdc\xb5\xfb\xc6\x67\xe2\xcf\x44\ | |||
\xe0\x25\x7a\xa2\x1c\xf4\x33\xed\x01\x8b\x96\x6b\xad\x41\xd8\x01\ | |||
\x00\x2d\x00\x02\x01\x01\x00\x2b\x00\x09\x08\x03\x04\x03\x03\x03\ | |||
\x02\x03\x01"; | |||
fn sleep(millis: u64, cmt: &'static str) { | |||
println!("[START] {}", cmt); | |||
sleep_no_comment(millis); | |||
println!("[DONE] {}", cmt); | |||
} | |||
fn sleep_no_comment(millis: u64) { | |||
let ten_millis = time::Duration::from_millis(millis); | |||
let _now = time::Instant::now(); | |||
thread::sleep(ten_millis); | |||
} | |||
fn main() -> std::io::Result<()> { | |||
// Condition variables to control threads | |||
let (flag_t1, control_t1) = make_pair(); | |||
let (flag_t2, control_t2) = make_pair(); | |||
ctrlc::set_handler(move || { | |||
println!("Stopping..."); | |||
control_t1.stop(); | |||
control_t2.stop(); | |||
}).expect("Error setting Ctrl-C handler"); | |||
// Parse arguments | |||
let _args: Vec<String> = env::args().collect(); | |||
// Argument 1 - <host>:<port> | |||
let addr_iter = _args[1].to_socket_addrs().unwrap(); | |||
// Argument 2 - timeout tcp TO. Fallback to 1 sec | |||
let dur_sec: u64 = _args[2].parse().unwrap_or(1); | |||
let dur = Duration::new(dur_sec, 0); | |||
// Argument 3 - which client hello to send | |||
let ch_case: usize = _args[3].parse().unwrap(); | |||
// Argument 4 - Sends per second | |||
let msg_per_sec: usize = _args[4].parse().unwrap(); | |||
// Argument 5 - Number of connections to keep open | |||
let con_num: usize = _args[5].parse().unwrap(); | |||
// create FIFO | |||
println!("We will keep {} connections open", con_num); | |||
let (tx, rx) = sync_channel(con_num); | |||
// Start a thread which sends CH | |||
let _t1 = thread::spawn(move || { | |||
let mut sent = 0; | |||
while flag_t1.is_alive() { | |||
// wait until connections are produced | |||
while rx.try_iter().next().is_none() { | |||
sleep(100, "Waiting for connections"); | |||
} | |||
// receive next connection and send CH | |||
let mut s: TcpStream = rx.recv().unwrap(); | |||
match ch_case { | |||
1 => s.write(&CH_NTRU).unwrap(), | |||
2 => s.write(&CH_SIKE).unwrap(), | |||
3 => s.write(&CH_X25519).unwrap(), | |||
4 => s.write(&CH_P521).unwrap(), | |||
_ => panic!("Unknown case"), | |||
}; | |||
s.shutdown(Shutdown::Both).expect("shutdown call failed"); | |||
sleep_no_comment(1000/msg_per_sec as u64); | |||
sent += 1; | |||
if sent % 100 == 0 { | |||
println!("nb of queries sent: {}", sent); | |||
} | |||
} | |||
}); | |||
// Start a thread which produces connections | |||
let _t2 = thread::spawn(move || { | |||
// First thread owns tx | |||
while flag_t2.is_alive() { | |||
let addr_ref = &addr_iter.as_slice()[0]; | |||
let sock = TcpStream::connect_timeout(addr_ref, dur); | |||
if sock.is_err() { | |||
sleep(1000, "Can't connect, waiting..."); | |||
continue; | |||
} | |||
let s = sock.unwrap(); | |||
s.set_nonblocking(true).expect("set_nonblocking call failed"); | |||
match tx.try_send(s) { | |||
Err(_) => sleep(1000, "Can't put in the queue"), | |||
Ok(_) => continue, | |||
} | |||
} | |||
}); | |||
// wait for TX thread to finish | |||
_t1.join().unwrap(); | |||
_t2.join().unwrap(); | |||
Ok(()) | |||
} |