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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C.11 Implementation Helper Classes<br />

102 private byte [ ] DHContribution = new byte [ 5 1 2 ] ;<br />

103 void p r o t o c o l I n i t i a l i s e ( ) {<br />

104 try {<br />

105 KeyPairGenerator myKeyGenerator = KeyPairGenerator . g e t I n s t a n c e (<br />

106 "RSA" ) ;<br />

107 myKeyGenerator . i n i t i a l i z e (512) ;<br />

108 KeyPair myKeyPair = myKeyGenerator . genKeyPair ( ) ;<br />

109 mySignatureGenerationKey = myKeyPair . g e t P r i v a t e ( ) ;<br />

110 mySignatureVerificationKey = myKeyPair . g e t P u b l i c ( ) ;<br />

111 mySignature = S i g n a t u r e . g e t I n s t a n c e ( "SHA1withRSA" ) ;<br />

112 } catch ( Exception cE ) {<br />

113 System . out . p r i n t l n (<br />

114 " P r o t o c o l Helper Class I n i t i a l i s a t i o n F a i l e d : "<br />

+ cE . getMessage ( ) ) ;<br />

115 }<br />

116 }<br />

117 byte [ ] GenerateDHPublicValue ( ) throws NoSuchAlgorithmException ,<br />

118 InvalidKeyException ,<br />

119 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 />

120 NoSuchProviderException ,<br />

121 BadPaddingException ,<br />

122 NoSuchPaddingException ,<br />

123 InvalidKeySpecException {<br />

124 rsaCipher = Cipher . g e t I n s t a n c e ( "RSA/None/NoPadding" , "BC" ) ;<br />

125 KeyFactory myKeyFactory = KeyFactory . g e t I n s t a n c e ( "RSA" , "BC" ) ;<br />

126 myRNG = SecureRandom . g e t I n s t a n c e ( "SHA1PRNG" ) ;<br />

127 myRNG. nextBytes ( randomExponent ) ;<br />

128 RSAPublicKeySpec myPublicKeySpec = new RSAPublicKeySpec (new<br />

129 B i g I n t e g e r ( dhModulus , 16) , new B i g I n t e g e r ( byteToString<br />

130 ( randomExponent ) , 16) ) ;<br />

131 myRSAPublicKey = ( RSAPublicKey ) myKeyFactory . g e n e r a t e P u b l i c<br />

132 ( myPublicKeySpec ) ;<br />

133 rsaCipher . i n i t ( Cipher .ENCRYPT_MODE, myRSAPublicKey ) ;<br />

134 DHContribution = rsaCipher . doFinal ( dhBase ) ;<br />

135 return DHContribution ;<br />

136 }<br />

137 byte [ ] GenerateDHSessionKeyMaterial (byte [ ] i n b u f f , int o f f s e t , int<br />

138 l e n g t h ) throws NoSuchAlgorithmException , InvalidKeyException ,<br />

139 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 , NoSuchProviderException ,<br />

140 BadPaddingException , NoSuchPaddingException ,<br />

141 InvalidKeySpecException {<br />

142 rsaCipher . i n i t ( Cipher .ENCRYPT_MODE, myRSAPublicKey ) ;<br />

143 return rsaCipher . doFinal ( i n b u f f , o f f s e t , l e n g t h ) ;<br />

144 }<br />

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

146 byte [ ] outbuff , int o u t b u f f O f f s e t , byte [ ] MacKey)<br />

147 throws NoSuchAlgorithmException ,<br />

148 InvalidKeyException , 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 />

149 NoSuchProviderException , BadPaddingException ,<br />

150 NoSuchPaddingException , InvalidKeySpecException {<br />

151 AESEngine AESMacEngine = new AESEngine ( ) ;<br />

436

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

Saved successfully!

Ooh no, something went wrong!