06.11.2014 Views

A User Centric Security Model for Tamper-Resistant Devices

A User Centric Security Model for Tamper-Resistant Devices

A User Centric Security Model for Tamper-Resistant Devices

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C.11 Implementation Helper Classes<br />

152 KeyParameter myMacKey = new KeyParameter (MacKey) ;<br />

153 CBCBlockCipherMac myAESMac = new CBCBlockCipherMac ( AESMacEngine ,<br />

154 128) ;<br />

155 ParametersWithIV ivparam = new ParametersWithIV (myMacKey ,<br />

156 I n i t i a l i s a t i o n V e c t o r ) ;<br />

157 myAESMac. i n i t ( ivparam ) ;<br />

158 myAESMac. update ( i n b u f f , i n b u f f O f f s e t , inbuffLength ) ;<br />

159 myAESMac. doFinal ( outbuff , o u t b u f f O f f s e t ) ;<br />

160 }<br />

161 boolean SignatureMethod ( byte [ ] inBuff , int i n B u f f O f f s e t , int<br />

162 inBuffLength , byte [ ] outBuff , int<br />

163 o u t B u f f O f f s e t , Key inKey , short SIGN_MODE)<br />

164 throws InvalidKeyException ,<br />

165 SignatureException {<br />

166 ByteBuffer myTempByteBuffer = ByteBuffer . wrap ( inBuff ,<br />

167 i n B u f f O f f s e t , inBuffLength ) ;<br />

168 i f ( inKey == null && SIGN_MODE == this .SIGN_MODE_GENERATION) {<br />

169 inKey = (Key) this . mySignatureGenerationKey ;<br />

170 } else i f ( inKey == null && SIGN_MODE ==<br />

171 this .SIGN_MODE_VERIFICATION) {<br />

172 inKey = (Key) this . mySignatureVerificationKey ;<br />

173 }<br />

174 switch (SIGN_MODE) {<br />

175 case SIGN_MODE_GENERATION: mySignature . i n i t S i g n ( ( PrivateKey )<br />

176 inKey ) ;<br />

177 mySignature . update ( myTempByteBuffer ) ;<br />

178 mySignature . s i g n ( outBuff , o u t B u f f O f f s e t , 64) ;<br />

179 return true ;<br />

180 case SIGN_MODE_VERIFICATION:<br />

181 mySignature . i n i t V e r i f y ( ( PublicKey ) inKey ) ;<br />

182 mySignature . update ( myTempByteBuffer ) ;<br />

183 return mySignature . v e r i f y ( outBuff , o u t B u f f O f f s e t , 64) ;<br />

184 default :<br />

185 System . out . p r i n t l n ( "ERROR−−−−−−−−−−−−WRONG MODE SELECTION" ) ;<br />

186 }<br />

187 return f a l s e ;<br />

188 }<br />

189 void GenerateDecryption ( byte [ ] i n b u f f , int i n b u f f O f f s e t , int<br />

190 inbuffLength , byte [ ] outbuff , int<br />

191 o u t b u f f O f f s e t , byte [ ] EnKey) throws<br />

192 NoSuchAlgorithmException ,<br />

193 InvalidKeyException ,<br />

194 I l l e g a l B l o c k S i z e E x c e p t i o n ,<br />

195 NoSuchProviderException ,<br />

196 BadPaddingException , NoSuchPaddingException ,<br />

197 InvalidKeySpecException ,<br />

198 ShortBufferException ,<br />

199 InvalidAlgorithmParameterException {<br />

200 try {<br />

201 IvParameterSpec ivS = new IvParameterSpec ( I n i t i a l i s a t i o n V e c t o r ) ;<br />

202 myAESKey = new SecretKeySpec (EnKey , "AES" ) ;<br />

437

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!