Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Fido2Applet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wen Wei Li
Fido2Applet
Commits
24923806
Commit
24923806
authored
Jul 02, 2023
by
Wen Wei Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bugs
parent
b6c256c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
18 deletions
+32
-18
src/main/java/com/josh/vku2f/CTAP2.java
src/main/java/com/josh/vku2f/CTAP2.java
+6
-1
src/main/java/com/josh/vku2f/HKDF.java
src/main/java/com/josh/vku2f/HKDF.java
+24
-15
src/main/java/com/josh/vku2f/HMAC.java
src/main/java/com/josh/vku2f/HMAC.java
+2
-2
No files found.
src/main/java/com/josh/vku2f/CTAP2.java
View file @
24923806
...
...
@@ -471,13 +471,18 @@ public class CTAP2 extends Applet implements ExtendedLength {
// | ----- 32 byte is H(H(IV)||H(Nonce)) ----- | ----- 32 byte HMAC -----|
// for reduce the mem/flash usage, I reuse the buffer to store the retrun value
// put encryptedCx
in
t
counter
=
hkdf
.
getIteration
();
shor
t
counter
=
hkdf
.
getIteration
();
// using CBOR Encoder to assemble the return value
// H(H(IV) || H(Nonce)) ret1[0:31] 32 bytes
// Nonce 32 bytes ret2[0:31]
// HMAC(output_key, H(IV||Nonce)) 32 bytes ret2[32:64]
// Iteration(Counter) 4 bytes integer : counter
// total return length : 100 bytes
/** TODO
* Using CBOREncoding to assemble the return value
*/
}
/**
* for alternative framework purpose
...
...
src/main/java/com/josh/vku2f/HKDF.java
View file @
24923806
package
com.josh.vku2f
;
import
javacard.framework.*
;
public
class
HKDF
{
private
byte
[]
ikm
;
...
...
@@ -9,48 +10,55 @@ public class HKDF
private
HMAC
hmac
;
private
byte
[]
temp
=
JCSystem
.
makeTransientByteArray
((
short
)
32
,
JCSystem
.
CLEAR_ON_RESET
);
private
byte
[]
tempPrk
;
private
int
iteration
;
private
short
iteration
;
private
boolean
init
;
private
byte
[]
counter
=
new
byte
[
1
];
public
HKDF
(
byte
[]
key
,
byte
[]
iv
){
this
.
iteration
=
0
;
this
.
ikm
=
new
byte
[
key
.
length
];
this
.
iv
=
new
byte
[
iv
.
length
];
this
.
prev_key
=
new
byte
[
32
];
Util
.
arrayCopy
(
key
,
(
short
)
0
,
this
.
ikm
,
(
short
)
0
,
(
short
)
key
.
length
);
Util
.
arrayCopy
(
iv
,
(
short
)
0
,
this
.
iv
,
(
short
)
0
,
(
short
)
iv
.
length
);
hmac
=
new
HMAC
(
new
byte
[
32
]);
tempPrk
=
JCSystem
.
makeTransientByteArray
((
short
)
iv
.
length
,
JCSystem
.
CLEAR_ON_RESET
);
Util
.
arrayCopy
(
this
.
iv
,
(
short
)
0
,
this
.
prev_key
,
(
short
)
0
,
(
short
)
iv
.
length
);
prev_key
=
new
byte
[
32
];
this
.
iteration
=
0
;
this
.
init
=
true
;
}
public
void
setIteration
(
in
t
_iteration
){
public
void
setIteration
(
shor
t
_iteration
){
this
.
iteration
=
_iteration
;
this
.
init
=
false
;
}
public
in
t
getIteration
(){
public
shor
t
getIteration
(){
return
this
.
iteration
;
}
public
void
getOutputKey
(
byte
[]
info
,
short
length
,
byte
[]
output
,
short
offset
){
getPRK
(
tempPrk
,
(
short
)
0
);
expand
(
tempPrk
,
info
,
length
,
output
,
offset
);
}
public
void
getNextOutputKey
(
byte
[]
info
,
short
length
,
byte
[]
output
,
short
offset
){
if
(
this
.
init
==
false
){
getPRK
(
tempPrk
,
(
short
)
0
);
}
expand
(
prev_key
,
info
,
length
,
output
,
offset
);
}
public
void
getPRK
(
byte
[]
output
,
short
offset
){
public
void
getPRK
(
byte
[]
output
,
short
offset
){
//Util.arrayCopy(iv, (short)0, tempPrk, (short)0, (short)iv.length);
Util
.
arrayCopy
(
this
.
ikm
,(
short
)
0
,
tempPrk
,
(
short
)
0
,
(
short
)
32
);
for
(
short
i
=
0
;
i
<
this
.
iteration
;
i
++){
for
(
short
i
=
0
;
i
<
this
.
iteration
;
i
++){
extract
(
iv
,
tempPrk
,
tempPrk
,
(
short
)
0
);
}
Util
.
arrayCopy
(
tempPrk
,
(
short
)
0
,
output
,
(
short
)
0
,
(
short
)
tempPrk
.
length
);
Util
.
arrayCopy
(
tempPrk
,
(
short
)
0
,
prev_key
,
(
short
)
0
,
(
short
)
prev_key
.
length
);
this
.
init
=
true
;
}
public
void
nextPRK
(
byte
[]
output
,
short
offset
){
if
(
this
.
init
==
false
){
getPRK
(
tempPrk
,
(
short
)
0
);
}
Util
.
arrayCopy
(
this
.
prev_key
,
(
short
)
0
,
tempPrk
,
(
short
)
0
,
(
short
)
this
.
prev_key
.
length
);
extract
(
tempPrk
,
this
.
ikm
,
output
,
(
short
)
offset
);
Util
.
arrayCopy
(
output
,
(
short
)
offset
,
this
.
prev_key
,
(
short
)
0
,
(
short
)
32
);
this
.
iteration
++;
}
private
void
extract
(
byte
[]
key
,
byte
[]
msg
,
byte
[]
output
,
short
offset
){
hmac
.
setKey
(
key
);
...
...
@@ -59,7 +67,7 @@ public class HKDF
}
// prf: pseudo random function
private
void
expand
(
byte
[]
prf
,
byte
[]
info
,
short
length
,
byte
[]
output
,
short
offset
){
if
(
length
/
32
>=
255
&&
length
%
32
>
0
){
if
(
(
short
)(
length
/
32
)
>=
(
short
)
255
&&
(
short
)
length
%
(
short
)
32
>
(
short
)
0
){
// up to 255 rounds for hmac operation
// which means the max output length is 255*32=8160
return
;
...
...
@@ -74,9 +82,10 @@ public class HKDF
hmac
.
setKey
(
prf
);
hmac
.
update
(
info
,
(
short
)
0
,
(
short
)
info
.
length
);
counter
[
0
]
=
(
byte
)(
i
+
1
);
hmac
.
update
(
counter
,
(
short
)
0
,
(
short
)
info
.
length
);
if
(
i
<
N
-
1
)
hmac
.
doFinal
(
output
,
(
short
)(
i
*
32
+
offset
));
hmac
.
update
(
counter
,
(
short
)
0
,
(
short
)
counter
.
length
);
if
(
i
<
(
short
)(
N
-
1
))
{
hmac
.
doFinal
(
output
,
(
short
)
(
i
*
32
+
offset
));
}
else
{
if
(
remainder
==
0
)
hmac
.
doFinal
(
output
,
(
short
)(
i
*
32
+
offset
));
...
...
src/main/java/com/josh/vku2f/HMAC.java
View file @
24923806
...
...
@@ -34,7 +34,7 @@ public class HMAC
Util
.
arrayFillNonAtomic
(
okeypad
,
prkLength
,
(
short
)(
okeypad
.
length
-
prkLength
),
(
byte
)
0x5c
);
}
public
void
update
(
byte
[]
newMsg
,
short
offset
,
short
length
){
if
(
length
+
msgCursor
>
msg
.
length
)
if
(
(
short
)
(
length
+
msgCursor
)
>
(
short
)
msg
.
length
)
return
;
Util
.
arrayCopy
(
newMsg
,
offset
,
msg
,
msgCursor
,
length
);
msgCursor
+=(
short
)
newMsg
.
length
;
...
...
@@ -44,7 +44,7 @@ public class HMAC
sha256
.
doFinal
(
msg
,
(
short
)
0
,
msgCursor
,
output
,
offset
);
sha256
.
update
(
okeypad
,
(
short
)
0
,
(
short
)
okeypad
.
length
);
sha256
.
doFinal
(
output
,
(
short
)
0
,
(
short
)
32
,
output
,
offset
);
sha256
.
doFinal
(
output
,
(
short
)
offset
,
(
short
)
32
,
output
,
offset
);
msgCursor
=
(
short
)
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment