Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
chore: scrypt switch to local vendor version
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhyc committed Dec 25, 2024
1 parent d8de3b9 commit d2fb4e0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions entry/src/main/ets/entryability/EntryAbility.ets
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { buffer, util } from '@kit.ArkTS';
import { IconManager } from '../common/icons';
import { dispatchImporter } from '../importers';


export class PreferencesManager {
private _instances: Map<string, OTP>;
private _secrets: SecretSchema[];
Expand Down Expand Up @@ -863,6 +864,7 @@ export default class EntryAbility extends UIAbility {
}
// TODO: restore settings
} catch (error) {
console.error((error as BusinessError).message);
promptAction.showToast({message: $r('app.string.setting_import_message_failed_decryption'), duration: 1000});
} finally {
await fs.close(file);
Expand Down
13 changes: 5 additions & 8 deletions entry/src/main/ets/importers/aegis.ets
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,9 @@ async function scryptKeyDeriveWrapper(password: string, material: ScryptMaterial
}

async function callScryptKeyDerive(password: string, material: ScryptMaterial): Promise<Uint8Array> {
console.time('scryptKeyDerive');
const task = new taskpool.Task(scryptKeyDeriveWrapper, password, material);
const result = await taskpool.execute(task, taskpool.Priority.HIGH);
console.timeEnd('scryptKeyDerive');
console.log(`${(result as Uint8Array).buffer}`);
return (result as Uint8Array);
const result: Uint8Array = await taskpool.execute(task, taskpool.Priority.HIGH) as Uint8Array;
return result;
}

export class AegisImporter implements ImporterBehavior {
Expand Down Expand Up @@ -232,7 +229,7 @@ export class AegisImporter implements ImporterBehavior {
if (slot.type!==1) { continue; }
const scrypt = slot as ScryptSlotSchema;
const salt = hexToUint8Array(scrypt.salt);
const material: ScryptMaterial = { n:scrypt.n, r:scrypt.r, p:scrypt.p, salt, length:32 };
const material: ScryptMaterial = { N:scrypt.n, r:scrypt.r, p:scrypt.p, salt, length:32 };
const key: Uint8Array = await callScryptKeyDerive(password, material);
//
try {
Expand All @@ -254,7 +251,7 @@ export class AegisImporter implements ImporterBehavior {

private async encryptAegisDB(password: string, db: AegisDBSchema): Promise<AegisExportSchema> {
const salt = await generateRandomAad32();
const material: ScryptMaterial = { n:32768, r:8, p:1, salt, length:32 };
const material: ScryptMaterial = { N:32768, r:8, p:1, salt, length:32 };
const key: Uint8Array = await callScryptKeyDerive(password, material);

// derive master key
Expand Down Expand Up @@ -285,7 +282,7 @@ export class AegisImporter implements ImporterBehavior {
nonce: uint8ArrayToHex(slot_nonce),
tag: uint8ArrayToHex(slot_tag),
},
n: material.n, r: material.r, p: material.p,
n: material.N, r: material.r, p: material.p,
salt: uint8ArrayToHex(salt),
repaired: false, is_backup: false,
} as ScryptSlotSchema],
Expand Down
21 changes: 15 additions & 6 deletions oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"modelVersion": "5.0.0",
"description": "Please describe the basic information.",
"dependencies": {
"scrypt": "^1.0.2"
"scrypt": "file:vendor/scrypt.har"
},
"devDependencies": {
"@ohos/hypium": "1.0.19",
Expand Down
Binary file added vendor/scrypt.har
Binary file not shown.

0 comments on commit d2fb4e0

Please sign in to comment.