@@ -16,8 +16,6 @@ import * as ZdoTypes from '../../../zspec/zdo/definition/tstypes';
16
16
import { DeviceJoinedPayload , DeviceLeavePayload , ZclPayload } from '../../events' ;
17
17
import {
18
18
EMBER_HIGH_RAM_CONCENTRATOR ,
19
- EMBER_INSTALL_CODE_CRC_SIZE ,
20
- EMBER_INSTALL_CODE_SIZES ,
21
19
EMBER_LOW_RAM_CONCENTRATOR ,
22
20
EMBER_MIN_BROADCAST_ADDRESS ,
23
21
INTERPAN_APS_FRAME_TYPE ,
@@ -70,8 +68,8 @@ import {
70
68
SecManContext ,
71
69
SecManKey ,
72
70
} from '../types' ;
73
- import { aesMmoHashInit , initNetworkCache , initSecurityManagerContext } from '../utils/initters' ;
74
- import { halCommonCrc16 , highByte , highLowToInt , lowByte , lowHighBytes } from '../utils/math' ;
71
+ import { initNetworkCache , initSecurityManagerContext } from '../utils/initters' ;
72
+ import { lowHighBytes } from '../utils/math' ;
75
73
import { FIXED_ENDPOINTS } from './endpoints' ;
76
74
import { EmberOneWaitress , OneWaitressEvents } from './oneWaitress' ;
77
75
@@ -1192,19 +1190,14 @@ export class EmberAdapter extends Adapter {
1192
1190
// Rather than give the real link key, the backup contains a hashed version of the key.
1193
1191
// This is done to prevent a compromise of the backup data from compromising the current link keys.
1194
1192
// This is per the Smart Energy spec.
1195
- const [ hashStatus , hashedKey ] = await this . emberAesHashSimple ( plaintextKey . contents ) ;
1196
-
1197
- if ( hashStatus === SLStatus . OK ) {
1198
- keyList . push ( {
1199
- deviceEui64 : context . eui64 ,
1200
- key : { contents : hashedKey } ,
1201
- outgoingFrameCounter : apsKeyMeta . outgoingFrameCounter ,
1202
- incomingFrameCounter : apsKeyMeta . incomingFrameCounter ,
1203
- } ) ;
1204
- } else {
1205
- // this should never happen?
1206
- logger . error ( `[BACKUP] Failed to hash link key at index ${ i } with status=${ SLStatus [ hashStatus ] } . Omitting from backup.` , NS ) ;
1207
- }
1193
+ const hashedKey = ZSpec . Utils . aes128MmoHash ( plaintextKey . contents ) ;
1194
+
1195
+ keyList . push ( {
1196
+ deviceEui64 : context . eui64 ,
1197
+ key : { contents : hashedKey } ,
1198
+ outgoingFrameCounter : apsKeyMeta . outgoingFrameCounter ,
1199
+ incomingFrameCounter : apsKeyMeta . incomingFrameCounter ,
1200
+ } ) ;
1208
1201
}
1209
1202
}
1210
1203
@@ -1494,26 +1487,6 @@ export class EmberAdapter extends Adapter {
1494
1487
return status ;
1495
1488
}
1496
1489
1497
- /**
1498
- * This is a convenience method when the hash data is less than 255
1499
- * bytes. It inits, updates, and finalizes the hash in one function call.
1500
- *
1501
- * @param data const uint8_t* The data to hash. Expected of valid length (as in, not larger alloc)
1502
- *
1503
- * @returns An ::SLStatus value indicating EMBER_SUCCESS if the hash was
1504
- * calculated successfully. EMBER_INVALID_CALL if the block size is not a
1505
- * multiple of 16 bytes, and EMBER_INDEX_OUT_OF_RANGE is returned when the
1506
- * data exceeds the maximum limits of the hash function.
1507
- * @returns result uint8_t* The location where the result of the hash will be written.
1508
- */
1509
- private async emberAesHashSimple ( data : Buffer ) : Promise < [ SLStatus , result : Buffer ] > {
1510
- const context = aesMmoHashInit ( ) ;
1511
-
1512
- const [ status , reContext ] = await this . ezsp . ezspAesMmoHash ( context , true , data ) ;
1513
-
1514
- return [ status , reContext ?. result ] ;
1515
- }
1516
-
1517
1490
/**
1518
1491
* Set the trust center policy bitmask using decision.
1519
1492
* @param decision
@@ -1716,43 +1689,10 @@ export class EmberAdapter extends Adapter {
1716
1689
1717
1690
// queued
1718
1691
public async addInstallCode ( ieeeAddress : string , key : Buffer ) : Promise < void > {
1719
- // codes with CRC, check CRC before sending to NCP, otherwise let NCP handle
1720
- if ( EMBER_INSTALL_CODE_SIZES . indexOf ( key . length ) !== - 1 ) {
1721
- // Reverse the bits in a byte (uint8_t)
1722
- const reverse = ( b : number ) : number => {
1723
- return ( ( ( ( ( b * 0x0802 ) & 0x22110 ) | ( ( b * 0x8020 ) & 0x88440 ) ) * 0x10101 ) >> 16 ) & 0xff ;
1724
- } ;
1725
- let crc = 0xffff ; // uint16_t
1726
-
1727
- // Compute the CRC and verify that it matches.
1728
- // The bit reversals, byte swap, and ones' complement are due to differences between halCommonCrc16 and the Smart Energy version.
1729
- for ( let index = 0 ; index < key . length - EMBER_INSTALL_CODE_CRC_SIZE ; index ++ ) {
1730
- crc = halCommonCrc16 ( reverse ( key [ index ] ) , crc ) ;
1731
- }
1732
-
1733
- crc = ~ highLowToInt ( reverse ( lowByte ( crc ) ) , reverse ( highByte ( crc ) ) ) & 0xffff ;
1734
-
1735
- if (
1736
- key [ key . length - EMBER_INSTALL_CODE_CRC_SIZE ] !== lowByte ( crc ) ||
1737
- key [ key . length - EMBER_INSTALL_CODE_CRC_SIZE + 1 ] !== highByte ( crc )
1738
- ) {
1739
- throw new Error ( `[ADD INSTALL CODE] Failed for '${ ieeeAddress } '; invalid code CRC.` ) ;
1740
- } else {
1741
- logger . debug ( `[ADD INSTALL CODE] CRC validated for '${ ieeeAddress } '.` , NS ) ;
1742
- }
1743
- }
1744
-
1745
1692
return await this . queue . execute < void > ( async ( ) => {
1746
- // Compute the key from the install code and CRC.
1747
- const [ aesStatus , keyContents ] = await this . emberAesHashSimple ( key ) ;
1748
-
1749
- if ( aesStatus !== SLStatus . OK ) {
1750
- throw new Error ( `[ADD INSTALL CODE] Failed AES hash for '${ ieeeAddress } ' with status=${ SLStatus [ aesStatus ] } .` ) ;
1751
- }
1752
-
1753
1693
// Add the key to the transient key table.
1754
1694
// This will be used while the DUT joins.
1755
- const impStatus = await this . ezsp . ezspImportTransientKey ( ieeeAddress as EUI64 , { contents : keyContents } ) ;
1695
+ const impStatus = await this . ezsp . ezspImportTransientKey ( ieeeAddress as EUI64 , { contents : ZSpec . Utils . aes128MmoHash ( key ) } ) ;
1756
1696
1757
1697
if ( impStatus == SLStatus . OK ) {
1758
1698
logger . debug ( `[ADD INSTALL CODE] Success for '${ ieeeAddress } '.` , NS ) ;
0 commit comments