Query calls have a low instruction limit on purpose because the IC doesn’t charge for them yet.
Azle also adds quite a bit of overhead. Calling a similar function in Motoko or Rust would probably work.
You can change your function to an update call to have a higher instruction limit for a single message execution.
Can you try running it inside of init or post upgrade? Currently Azle’s crypto functionality is mostly implemented in JavaScript, and some operations can unfortunately use many many cycles. We hope to address this in the coming months.
You might be able to do this in init or post upgrade, since they have a 200 billion instruction limit.
Please note that canister memory, execution and call and response data is not hidden from the node providers. So you should neither generate nor store secret key material in the canister, nor should you transmit secret keys into or out of the canister.
What you can do in your case is to create an asset canister, ie frontend hosted in a canister, which can then generate a key pair client side for the user.