Datasheet
AN156
9 of 23
Using SHAiButtonCopr and SHAiButtonUser for Authentication Figure 16
Figure 17 illustrates how to use the OneWireContainer18 class to produce a random challenge. Also
included in that caption is the declaration of the variables used in the rest of the code snippets for this
section.
Using the Coprocessor to Generate a Random Challenge Figure 17
After performing the steps in Figure 17, the scratchpad buffer of the coprocessor now contains the 20-
byte result of a SHA calculation, starting at index 8. Since any three bytes are as good as any other three
for a challenge, it is safe to leave the result as it is in the scratchpad. Indices 20 to 22 of the coprocessor’s
scratchpad hold the challenge bytes that will be used for the Read Authenticated Page. Using these three
particular bytes makes it unnecessary to write the challenge back to the coprocessor later.
byte[] rawData = new byte[42];
byte[] scratchpad = new byte[32];
byte[] responseMAC = new byte[20];
byte[] challenge = new byte[3];
/* Use the coprocessor to generate the challenge, page number is irrelevant but a
* highly used page will generate a more random (less repeating) number */
coprDevice.eraseScratchPad(authPageNumber);
coprDevice.SHAFunction(ibcL.COMPUTE_CHALLENGE, authPageNumber << 5);
coprDevice.readScratchPad(scratchpad, 0);
/* copy the challenge bytes into challenge buffer */
System.arraycopy(scratchpad, 20, challenge, 0, 3);
/* Use coprocessor to generate a random challenge */
copr.generateChallenge(0, challenge, 0);
/* issue challenge to user getting back the account data, response MAC, and the
* value of the write-cycle counter */
int wcc = user18.readAccountData(challenge, 0, rawData, 0, responseMAC, 0);
scratchpad[8] = (wcc&0x0ff);
scratchpad[9] = ((wcc>>=8)&0x0ff);
scratchpad[10] = ((wcc>>=8)&0x0ff);
scratchpad[11] = ((wcc>>=8)&0x0ff);
/* get user’s full binding code */
fullBindCode = user18.getFullBindCode();
/* create the coprocessor’s “signing” scratchpad */
System.arraycopy(fullBindCode, 4, scratchpad, 12, 8);
System.arraycopy(challenge, 0, scratchpad, 20, 3);
if(copr.verifyAuthentication(fullBindCode, rawData, scratchpad, responseMAC,
user18.getAuthorizationCommand()))
System.out.println(“User Token Authentication Successful!”);










