Skip to content

Commit 7593787

Browse files
authored
Merge pull request #109 from cipherstash/rename-fields
Rename search term for consistency PR_BYPASS: required for customer demo. minor changes to the names of several functions and internal fields.
2 parents 77c4d4f + 2679db6 commit 7593787

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+570
-570
lines changed

DEVELOPMENT.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ Each type of encrypted index (`unique`, `match`, `ore`) has an associated type,
318318
These are transient runtime types, used internally by EQL functions and operators:
319319

320320
- `eql_v2.blake3`
321-
- `eql_v2.unique_index`
322-
- `eql_v2.match`
321+
- `eql_v2.hmac_256`
322+
- `eql_v2.bloom_filter`
323323
- `eql_v2.ore_cllw_u64_8`
324324
- `eql_v2.ore_cllw_var_8`
325-
- `eql_v2.ore_64_8_v2`
326-
- `eql_v2.ore_64_8_v2_term`
325+
- `eql_v2.ore_block_u64_8_256`
326+
- `eql_v2.ore_block_u64_8_256_term`
327327

328328
The data in the column is converted into these types, when any operations are being performed on that encrypted data.
329329

@@ -348,7 +348,7 @@ For example, it is possible to have both `unique` and `ore` indexes defined.
348348
For equality (`=`, `<>`) operations, a `unique` index term is a text comparison and should be preferred over an `ore` index term.
349349

350350
The index term types and functions are internal implementation details and should not be exposed as operators on the `eql_v2_encrypted` type.
351-
For example, `eql_v2_encrypted` should not have an operator with the `ore_64_8_v2` type.
351+
For example, `eql_v2_encrypted` should not have an operator with the `ore_block_u64_8_256` type.
352352
Users should never need to think about or interact with EQL internals.
353353

354354
#### Working without operators

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ Data is stored in the PostgreSQL database as:
148148
"t": "users"
149149
},
150150
"k": "ct",
151-
"m": null,
152-
"o": null,
151+
"bf": null,
152+
"ob": null,
153153
"u": null,
154154
"v": 1
155155
}
@@ -231,7 +231,7 @@ In order to use the specialized functions, you must first configure the correspo
231231

232232
### Equality search
233233

234-
Enable equality search on encrypted data using the `eql_v2.unique` function.
234+
Enable equality search on encrypted data using the `eql_v2.hmac_256` function.
235235

236236
**Index configuration example:**
237237

@@ -248,8 +248,8 @@ SELECT eql_v2.add_search_config(
248248

249249
```sql
250250
SELECT * FROM users
251-
WHERE eql_v2.unique(encrypted_email) = eql_v2.unique(
252-
'{"v":1,"k":"pt","p":"test@example.com","i":{"t":"users","c":"encrypted_email"},"q":"unique"}'
251+
WHERE eql_v2.hmac_256(encrypted_email) = eql_v2.hmac_256(
252+
'{"v":1,"k":"pt","p":"test@example.com","i":{"t":"users","c":"encrypted_email"},"q":"hmac_256"}'
253253
);
254254
```
255255

@@ -261,7 +261,7 @@ SELECT * FROM users WHERE email = 'test@example.com';
261261

262262
### Full-text search
263263

264-
Enables basic full-text search on encrypted data using the `eql_v2.match` function.
264+
Enables basic full-text search on encrypted data using the `eql_v2.bloom_filter` function.
265265

266266
**Index configuration example:**
267267

@@ -279,7 +279,7 @@ SELECT eql_v2.add_search_config(
279279

280280
```sql
281281
SELECT * FROM users
282-
WHERE eql_v2.match(encrypted_email) @> eql_v2.match(
282+
WHERE eql_v2.bloom_filter(encrypted_email) @> eql_v2.bloom_filter(
283283
'{"v":1,"k":"pt","p":"test","i":{"t":"users","c":"encrypted_email"},"q":"match"}'
284284
);
285285
```
@@ -292,7 +292,7 @@ SELECT * FROM users WHERE email LIKE '%test%';
292292

293293
### Range queries
294294

295-
Enable range queries on encrypted data using the `eql_v2.ore_64_8_v2`, `eql_v2.ore_cllw_u64_8`, or `eql_v2.ore_cllw_var_8` functions. Supports:
295+
Enable range queries on encrypted data using the `eql_v2.ore_block_u64_8_256`, `eql_v2.ore_cllw_u64_8`, or `eql_v2.ore_cllw_var_8` functions. Supports:
296296

297297
- `ORDER BY`
298298
- `WHERE`
@@ -301,7 +301,7 @@ Enable range queries on encrypted data using the `eql_v2.ore_64_8_v2`, `eql_v2.o
301301

302302
```sql
303303
SELECT * FROM users
304-
WHERE eql_v2.ore_64_8_v2(encrypted_date) < eql_v2.ore_64_8_v2(
304+
WHERE eql_v2.ore_block_u64_8_256(encrypted_date) < eql_v2.ore_block_u64_8_256(
305305
'{"v":1,"k":"pt","p":"2023-10-05","i":{"t":"users","c":"encrypted_date"},"q":"ore"}'
306306
);
307307
```
@@ -316,7 +316,7 @@ SELECT * FROM users WHERE date < '2023-10-05';
316316

317317
```sql
318318
SELECT id FROM users
319-
ORDER BY eql_v2.ore_64_8_v2(encrypted_field) DESC;
319+
ORDER BY eql_v2.ore_block_u64_8_256(encrypted_field) DESC;
320320
```
321321

322322
Equivalent plaintext query:

SUPABASE.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ In EQL, PostgreSQL operators are an alias for a function, so the implementation
2424

2525
### Core Functions
2626

27-
| Function | Description | Example |
28-
| ---------------------------- | ---------------------------------------------------- | ----------------------------------------------- |
29-
| `eql_v2.ciphertext(val)` | Extract ciphertext from encrypted value | `SELECT eql_v2.ciphertext(encrypted_field)` |
30-
| `eql_v2.blake3(val)` | Extract blake3 hash from encrypted value | `SELECT eql_v2.blake3(encrypted_field)` |
31-
| `eql_v2.unique(val)` | Extract unique index from encrypted value | `SELECT eql_v2.unique(encrypted_field)` |
32-
| `eql_v2.match(val)` | Extract match index from encrypted value | `SELECT eql_v2.match(encrypted_field)` |
33-
| `eql_v2.ore_64_8_v2(val)` | Extract ORE index from encrypted value | `SELECT eql_v2.ore_64_8_v2(encrypted_field)` |
34-
| `eql_v2.ore_cllw_u64_8(val)` | Extract CLLW ORE index from encrypted value | `SELECT eql_v2.ore_cllw_u64_8(encrypted_field)` |
35-
| `eql_v2.ore_cllw_var_8(val)` | Extract variable CLLW ORE index from encrypted value | `SELECT eql_v2.ore_cllw_var_8(encrypted_field)` |
27+
| Function | Description | Exa mple |
28+
| --------------------------------- | --------------------------------------------------------- | ----------------------------------------------- |
29+
| `eql_v2.ciphertext(val)` | Extract ciphertext from encrypted value | `SELECT eql_v2.ciphertext (encrypted_field)` |
30+
| `eql_v2.blake3(val)` | Extract blake3 hash from encrypted value | `SELECT eql_v2.blake3( encrypted_field)` |
31+
| `eql_v2.hmac_256(val)` | Extract hmac_256 index from encrypted value | `SELECT eql_v2.hmac_256(encrypted_fie ld)` |
32+
| `eql_v2.bloom_filter(val)` | Extract match index from encrypted value | `SELECT eql_v2.bloom_filter(encrypted_field)` |
33+
| `eql_v2.ore_block_u64_8_256(val)` | Extract ORE index from encrypted value | `SELECT eql_v2.ore_block_u64_8_256(encrypted_field)` |
34+
| `eql_v2.ore_cllw_u64_8(val)` | Extract CLLW ORE index from encrypted value | `SELECT eql_v2.ore_cllw_u64_8(encrypted_fie ld)` |
35+
| `eql_v2.ore_cllw_var_8(val)` | Extract variable CLLW ORE index from encrypted value | `SELECT eql_v2.ore_cllw_var_8( encrypted_field)` |
3636

3737
### Aggregate Functions
3838

@@ -90,19 +90,17 @@ The behaviour of EQL's encrypted `LIKE` operators is slightly different to the b
9090
In EQL, the `LIKE` operator can be used on `match` indexes.
9191
Case sensitivity is determined by the [index term configuration](./docs/reference/INDEX.md#options-for-match-indexes-opts) of `match` indexes.
9292
A `match` index term can be configured to enable case sensitive searches with token filters (for example, `downcase` and `upcase`).
93-
The data is encrypted based on the index term configuration.
94-
The `LIKE` operation is always the same, even if the data is tokenised differently.
95-
The different operators are kept to preserve the semantics of SQL statements in client applications.
93+
The data is encrypted based on the index term configurat ion.
94+
The `LIKE` operation is always the same, even if the data is----- tokenised differently.
95+
The different operators are kept to preserve the semantics of SQL statements in client applications.
9696

97-
### `ORDER BY`
97+
### `ORDER BY`
9898

99-
Ordering requires wrapping the ordered column in the `eql_v2.order_by` function, like this:
99+
Ordering requires wrapping the ordered column in the `eql_v2.order_by` function, lik e this:
100100

101101
```sql
102102
SELECT * FROM users ORDER BY eql_v2.order_by(encrypted_created_at) DESC
103-
```
104-
105-
PostgreSQL uses operators when handling `ORDER BY` operations. The `eql_v2.order_by` function behaves in the same way as the comparison operators, using the appropriate index type (ore_64_8_v2, ore_cllw_u64_8, or ore_cllw_var_8) to determine the ordering.
103+
`` ` PostgreSQL uses operators when handling `ORDER BY` operations. The `eql_v2.order_by` function behaves in the same way as the comparison operators, using the appropriate index type (ore_block_u64_8_256 , ore_cllw_u64_8, or ore_cllw_var_8) to determine the ordering.
106104
107105
### JSONB Support
108106

docs/reference/INDEX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The default match index options are:
4949
```json
5050
{
5151
"k": 6,
52-
"m": 2048,
52+
"bf": 2048,
5353
"include_original": true,
5454
"tokenizer": {
5555
"kind": "ngram",

docs/tutorials/GETTINGSTARTED.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ For ordering or comparison queries we add an `ore` index:
193193

194194
```sql
195195
SELECT cs_add_index_v2('users', 'email_encrypted', 'ore', 'text');
196-
CREATE INDEX ON users (cs_ore_64_8_v2(email_encrypted));
196+
CREATE INDEX ON users (ore_block_u64_8_256(email_encrypted));
197197
```
198198

199199
After adding these indexes, our `eql_v2_configuration` table will look like this:
200200

201201
```bash
202202
id | 1
203203
state | pending
204-
data | {"v": 1, "tables": {"users": {"email_encrypted": {"cast_as": "text", "indexes": {"ore": {}, "match": {"k": 6, "m": 2048, "tokenizer": {"kind": "ngram", "token_length": 3}, "token_filters": [{"kind": "downcase"}], "include_original": true}, "unique": {"token_filters": [{"kind": "downcase"}]}}}}}}
204+
data | {"v": 1, "tables": {"users": {"email_encrypted": {"cast_as": "text", "indexes": {"ore": {}, "match": {"k": 6, "bf": 2048, "tokenizer": {"kind": "ngram", "token_length": 3}, "token_filters": [{"kind": "downcase"}], "include_original": true}, "unique": {"token_filters": [{"kind": "downcase"}]}}}}}}
205205
```
206206

207207
The initial `state` will be set as pending.
@@ -218,7 +218,7 @@ The `cs_configured_v2` table will now have a state of `active`.
218218
```bash
219219
id | 1
220220
state | active
221-
data | {"v": 1, "tables": {"users": {"email_encrypted": {"cast_as": "text", "indexes": {"ore": {}, "match": {"k": 6, "m": 2048, "tokenizer": {"kind": "ngram", "token_length": 3}, "token_filters": [{"kind": "downcase"}], "include_original": true}, "unique": {"token_filters": [{"kind": "downcase"}]}}}}}}
221+
data | {"v": 1, "tables": {"users": {"email_encrypted": {"cast_as": "text", "indexes": {"ore": {}, "match": {"k": 6, "bf": 2048, "tokenizer": {"kind": "ngram", "token_length": 3}, "token_filters": [{"kind": "downcase"}], "include_original": true}, "unique": {"token_filters": [{"kind": "downcase"}]}}}}}}
222222
```
223223

224224
### Encrypting existing plaintext data
@@ -325,9 +325,9 @@ It creates an EQL payload that looks similar to this and inserts this into the e
325325
"t": "users", // Table
326326
"c": "email_encrypted" // Encrypted column
327327
},
328-
"m": [42], // The ciphertext used for free text queries i.e match index
328+
"bf": [42], // The ciphertext used for free text queries i.e match index
329329
"u": "unique ciphertext", // The ciphertext used for unique queries. i.e unique index
330-
"o": ["a", "b", "c"], // The ciphertext used for order or comparison queries. i.e ore index
330+
"ob": ["a", "b", "c"], // The ciphertext used for order or comparison queries. i.e ore index
331331
"v": 1
332332
}
333333
```
@@ -386,9 +386,9 @@ The json stored in the database looks similar to this:
386386
"t": "users", // Table
387387
"c": "email_encrypted" // Encrypted column
388388
},
389-
"m": [42], // The ciphertext used for free text queries i.e match index
389+
"bf": [42], // The ciphertext used for free text queries i.e match index
390390
"u": "unique ciphertext", // The ciphertext used for unique queries. i.e unique index
391-
"o": ["a", "b", "c"], // The ciphertext used for order or comparison queries. i.e ore index
391+
"ob": ["a", "b", "c"], // The ciphertext used for order or comparison queries. i.e ore index
392392
"v": 1
393393
}
394394
```
@@ -509,7 +509,7 @@ Prerequsites:
509509

510510
- An [ore index](#adding-indexes) is needed on the encrypted column to support this operation.
511511

512-
EQL function to use: `cs_ore_64_8_v2(val JSONB)`.
512+
EQL function to use: `ore_block_u64_8_256(val JSONB)`.
513513

514514
A plaintext query order by email looks like this:
515515

@@ -520,7 +520,7 @@ SELECT * FROM users ORDER BY email ASC;
520520
The EQL equivalent of this query is:
521521

522522
```sql
523-
SELECT * FROM users ORDER BY cs_ore_64_8_v2(email_encrypted) ASC;
523+
SELECT * FROM users ORDER BY ore_block_u64_8_256(email_encrypted) ASC;
524524
```
525525

526526
This query returns:
@@ -538,7 +538,7 @@ Prerequsites:
538538

539539
- A [unique index](#adding-indexes) is needed on the encrypted column to support this operation.
540540

541-
EQL function to use: `cs_ore_64_8_v2(val JSONB)`.
541+
EQL function to use: `ore_block_u64_8_256(val JSONB)`.
542542

543543
EQL query payload for a comparison query:
544544

@@ -564,7 +564,7 @@ SELECT * FROM users WHERE email > 'gracehopper@test.com';
564564
The EQL equivalent of this query is:
565565

566566
```sql
567-
SELECT * FROM users WHERE cs_ore_64_8_v2(email_encrypted) > cs_ore_64_8_v2(
567+
SELECT * FROM users WHERE ore_block_u64_8_256(email_encrypted) > ore_block_u64_8_256(
568568
'{"v":1,"k":"pt","p":"gracehopper@test.com","i":{"t":"users","c":"email_encrypted"},"q":"ore"}'
569569
);
570570
```

src/blake3/functions.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55
-- extracts blake3 index from a jsonb value
66

7+
78
CREATE FUNCTION eql_v2.blake3(val jsonb)
89
RETURNS eql_v2.blake3
910
IMMUTABLE STRICT PARALLEL SAFE
1011
AS $$
1112
BEGIN
1213

13-
IF NOT (val ? 'b') NULL THEN
14-
RAISE 'Expected a blake3 index (b) value in json: %', val;
14+
IF NOT (val ? 'b3') NULL THEN
15+
RAISE 'Expected a blake3 index (b3) value in json: %', val;
1516
END IF;
1617

17-
IF val->>'b' IS NULL THEN
18+
IF val->>'b3' IS NULL THEN
1819
RETURN NULL;
1920
END IF;
2021

21-
RETURN val->>'b';
22+
RETURN val->>'b3';
2223
END;
2324
$$ LANGUAGE plpgsql;
2425

src/bloom_filter/functions.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- REQUIRE: src/schema.sql
2+
3+
4+
-- extracts match index from an emcrypted column
5+
6+
CREATE FUNCTION eql_v2.bloom_filter(val jsonb)
7+
RETURNS eql_v2.bloom_filter
8+
IMMUTABLE STRICT PARALLEL SAFE
9+
AS $$
10+
BEGIN
11+
IF val ? 'bf' THEN
12+
RETURN ARRAY(SELECT jsonb_array_elements(val->'bf'))::eql_v2.bloom_filter;
13+
END IF;
14+
RAISE 'Expected a match index (bf) value in json: %', val;
15+
END;
16+
$$ LANGUAGE plpgsql;
17+
18+
19+
-- extracts unique index from an encrypted column
20+
21+
CREATE FUNCTION eql_v2.bloom_filter(val eql_v2_encrypted)
22+
RETURNS eql_v2.bloom_filter
23+
IMMUTABLE STRICT PARALLEL SAFE
24+
AS $$
25+
BEGIN
26+
RETURN (SELECT eql_v2.bloom_filter(val.data));
27+
END;
28+
$$ LANGUAGE plpgsql;

src/match/functions_test.sql renamed to src/bloom_filter/functions_test.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ DO $$
44
BEGIN
55
PERFORM assert_result(
66
'Extract match index term from encrypted',
7-
'SELECT eql_v2.match(''{"m": []}''::jsonb)');
7+
'SELECT eql_v2.bloom_filter(''{"bf": []}''::jsonb)');
88

99
PERFORM assert_exception(
1010
'Missing match index term in encrypted raises exception',
11-
'SELECT eql_v2.match(''{}''::jsonb)');
11+
'SELECT eql_v2.bloom_filter(''{}''::jsonb)');
1212

1313
END;
1414
$$ LANGUAGE plpgsql;

src/bloom_filter/types.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- REQUIRE: src/schema.sql
2+
3+
CREATE DOMAIN eql_v2.bloom_filter AS smallint[];
4+

src/config/functions_private.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ LANGUAGE sql STRICT PARALLEL SAFE
8888
BEGIN ATOMIC
8989
SELECT jsonb_build_object(
9090
'k', 6,
91-
'm', 2048,
91+
'bf', 2048,
9292
'include_original', true,
9393
'tokenizer', json_build_object('kind', 'ngram', 'token_length', 3),
9494
'token_filters', json_build_array(json_build_object('kind', 'downcase')));

0 commit comments

Comments
 (0)