| 3261 | |
| 3262 | |
| 3263 | dsc* evlEncryptDecrypt(thread_db* tdbb, const SysFunction* function, const NestValueArray& args, |
| 3264 | impure_value* impure, bool encryptFlag) |
| 3265 | { |
| 3266 | tomcryptInitializer(); |
| 3267 | |
| 3268 | fb_assert(args.getCount() == CRYPT_ARG_MAX); |
| 3269 | |
| 3270 | Request* request = tdbb->getRequest(); |
| 3271 | |
| 3272 | // parse args and check correctness |
| 3273 | const dsc* dscs[CRYPT_ARG_MAX]; |
| 3274 | for (unsigned i = 0; i < CRYPT_ARG_MAX; ++i) |
| 3275 | dscs[i] = EVL_expr(tdbb, request, args[i]); |
| 3276 | |
| 3277 | MetaName algorithmName, modeName, counterType; |
| 3278 | MOV_get_metaname(tdbb, dscs[CRYPT_ARG_ALGORITHM], algorithmName); |
| 3279 | |
| 3280 | const unsigned ALG_RC4 = 1; |
| 3281 | const unsigned ALG_CHACHA = 2; |
| 3282 | const unsigned ALG_SOBER = 3; |
| 3283 | static CodeValue algorithms[] = { |
| 3284 | { ALG_RC4, "RC4" }, |
| 3285 | { ALG_CHACHA, "CHACHA20" }, |
| 3286 | { ALG_SOBER, "SOBER128" }, |
| 3287 | { 0, nullptr } |
| 3288 | }; |
| 3289 | |
| 3290 | CodeValue* a = nullptr; |
| 3291 | string aName(algorithmName); |
| 3292 | aName.lower(); |
| 3293 | int cipher = find_cipher(aName.c_str()); |
| 3294 | if (cipher < 0) |
| 3295 | { |
| 3296 | a = find(algorithms, algorithmName); |
| 3297 | if (!a) |
| 3298 | status_exception::raise(Arg::Gds(isc_tom_algorithm) << algorithmName); |
| 3299 | } |
| 3300 | |
| 3301 | const unsigned MODE_ECB = 1; |
| 3302 | const unsigned MODE_CBC = 2; |
| 3303 | const unsigned MODE_CTR = 3; |
| 3304 | const unsigned MODE_CFB = 4; |
| 3305 | const unsigned MODE_OFB = 5; |
| 3306 | static CodeValue modes[] = { |
| 3307 | { MODE_ECB, "ECB" }, |
| 3308 | { MODE_CBC, "CBC" }, |
| 3309 | { MODE_CTR, "CTR" }, |
| 3310 | { MODE_CFB, "CFB" }, |
| 3311 | { MODE_OFB, "OFB" }, |
| 3312 | { 0, nullptr } |
| 3313 | }; |
| 3314 | |
| 3315 | CodeValue* m = nullptr; |
| 3316 | MOV_get_metaname(tdbb, dscs[CRYPT_ARG_MODE], modeName); |
| 3317 | if (cipher >= 0) |
| 3318 | { |
| 3319 | if (!modeName.hasData()) |
| 3320 | status_exception::raise(Arg::Gds(isc_tom_mode_miss)); |
no test coverage detected