From 1e207400a33792cd186e733b11b07afd5f3f1bc4 Mon Sep 17 00:00:00 2001 From: n1ckl0s <25745329+n1ckl0sk0rtge@users.noreply.github.com> Date: Fri, 18 Mar 2022 20:28:26 +0100 Subject: [PATCH] add check for minimum key size, add negative test --- build/classes/java/test/PseudonymTest.class | Bin 2526 -> 2847 bytes .../previous-compilation-data.bin | Bin 907 -> 907 bytes .../ibm/unlinkablepseudonyms/Pseudonym.java | 7 +++++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/build/classes/java/test/PseudonymTest.class b/build/classes/java/test/PseudonymTest.class index b094634d6281aee25562a9c788214eec3d534d06..d1fd7be35069757dceed9a51307ed64c98e4f5f8 100644 GIT binary patch delta 975 zcmYL|+fo!)6o$W^>2c3=HnBtr5n>V*6jV-v#zcak4h}e=L5YVPbQl|Ggn>v)gdB#L zynr=cYk6gr7gmj4IAx`L0AC?hzCtQj-lhC|I5<Gv4mWMoc7=CmR0F~}K1#v{p)$1rE3NY*goG0M3V=lRBCFJm4T zxERI8J-+3V;d11!MCPjDJHz)5TY7^+5Z+rkztb+vF9u<-n|IAvfN_P5L#}tWcisp zhGokNzgT|dH^c9iBC8JDXL3uqj@evcsv~_T?=OVGyg>ipZe;#^emCCd79Do9v}WHI zo|~BQ^WkxJ^Rcv#esLUa)hPRko;u_m`NV-2IAtAT?2_G54Q}OAo$XoypYge#96>dz zO3ltATs*}p6=K=i_(-i=YDxZGi~xqIm90}jJx23t)U-oQ4T5YJ)PTUo1vO0*A^Tb7 z043UZsO(b?Q>K$=bn$|o>JkflAgm|sVV_noJXTMO)~MkTt?G>n`923Zgj*EEs-W6Q zXv~}_c8bq9R|MCt)@fa+!-^#}u#s+^QW}-epd(eLm35{^MIc4&EoDPpLf3aqmSge` zUv7xNzuL@*pP60d69E=ur~+It0XLR9)C z(SV4Y(w?Vv8YC?tGx`sat;rK`+_41Jq29NU!P;F=7=sHbgYT?ThuhUm?#y~s^^ c8PSWr&iC|U+A6vU$7z=LwE13rvrVMl0ZdnqR{#J2 delta 642 zcmXYvOH&h35QV>)WVp$2p~?iK0fQP;9vUKw-~*$GK_$L5D!xOABuGM(h$w2Z@CQJR zd&+WQl?$t)3oRG^0C%pfa_v9Rm1R%LS)9Iorca;lJF^!08LWQ$`{gSzOwDE^2W<{9 z;^VN7gv}9-x-ja(F~yk8agvI08y_cZPIAg+CKM@~)12{hmUA{y&f8qzqRU;fxlCGd z#f?`L*A$ZmO(TU;p^`B0^sK&2t@BoL3l(9fh6aQ}> zW;l3TbBDW{3{#pc(+2&{iq+}-Fa!Ra<{mQ!z0Myi;>0Z-(1gh=3YuB&Yvw3A1D?LI zl4hQ=;(_KN3z`a#6pNb2ENPzbRI#ji#&d(o3Ku3Rb1i}(fAk8eB) zZ-}jIkUMi96GP0}1v{KpU#NSNa7~gyD-l86I9qhGSu%qyQfo?W%J;qM)=m%*Y{N?k zC7oL2eH$Hu5&A_nD!R0&@^s0(JE+l%!!Fi{@ty(d#QDH(KC!pqSEgBdy^{&Ii<{!D zXu8F*h1c|m)+3!?(Z^1_%VJQIRxvEGDM}WX(bG&yyO>DxjEg~BKDi?U?U9pTtSm7a qY%KNp|5E#80YBz%>WcLiLz22TFf7qze*+J&O`@mT=#o*jJ7wnVsy^U(dyj~d cTLGUCzL8fXg#=LBdFB4*)*gW-vkC%%0q>(7=l}o! delta 70 zcmV-M0J;B*2a5-g77)&_Z%J~w1OH6E99J$=)hMwhB>@m@KytW*zo>6iReryYfpl7v cTLGUCMwR@j&XMD}3$~<(yd+e~vkC%%0S+J@djJ3c diff --git a/src/main/java/com/ibm/unlinkablepseudonyms/Pseudonym.java b/src/main/java/com/ibm/unlinkablepseudonyms/Pseudonym.java index aaec1c4..a540498 100644 --- a/src/main/java/com/ibm/unlinkablepseudonyms/Pseudonym.java +++ b/src/main/java/com/ibm/unlinkablepseudonyms/Pseudonym.java @@ -1,7 +1,6 @@ package com.ibm.unlinkablepseudonyms; import org.apache.commons.codec.digest.DigestUtils; - import java.math.BigInteger; import java.security.interfaces.RSAPrivateCrtKey; import java.security.interfaces.RSAPublicKey; @@ -23,7 +22,11 @@ public static byte[] convert( byte[] cipher, PRFSecretExponent currentSecretExponent, PRFSecretExponent targetSecretExponent, - RSAPrivateCrtKey privateKey) { + RSAPrivateCrtKey privateKey) throws Exception { + + if (privateKey.getModulus().bitLength() <= 256) { + throw new Exception("key size to small"); + } BigInteger phi = privateKey.getPrimeP().subtract(BigInteger.ONE).multiply(privateKey.getPrimeQ().subtract(BigInteger.ONE)); BigInteger value = (new BigInteger(cipher)).modPow(targetSecretExponent.asBigInt(), privateKey.getModulus());