Skip to content

Policy and Attribute Syntax

Claudio Lucisano edited this page Sep 22, 2026 · 1 revision

Policy and Attribute Syntax

OpenABE parses two kinds of input, both with the grammar in src/zparser.yy:

Input CP-ABE KP-ABE
Attribute list keygen(...) encrypt(...)
Policy encrypt(...) keygen(...)

Attributes

An attribute is a single word. There are no spaces inside an attribute, and names are case-sensitive, so Doctor ≠ doctor.

  • It must start with a letter or one of / \ . [ ] $ ~.
  • After that it may contain letters, digits and _ / \ , . * - : ! ~ [ ] & $ # @ % ^ { }.
  • The words and, AND, or, OR, in, IN are keywords, and anything containing expint is reserved.

Namespaces: type:value

The colon has no special meaning to the parser, but by convention it separates a type (namespace) from a value:

system:admin      dept:cardiology      From:Alice

Use it to keep attributes from different domains from colliding.

Attribute lists

Attributes are separated by |. Leading and trailing bars are allowed and ignored:

Doctor|Floor=3|dept:cardiology
|attr1|attr2|

Policies

A policy is a boolean formula over attributes:

Doctor
Doctor and Floor >= 3
(Doctor or Nurse) and dept:cardiology
  • Operators: and / AND, or / OR, with parentheses for grouping. When mixing and and or, always use parentheses; don't rely on precedence.
  • An attribute in a policy is satisfied if the attribute list contains exactly that string.

Numbers

Attribute lists can carry numeric attributes with name=value, and policies can compare them:

In the attribute list In a policy
Floor=3 Floor == 3, Floor < 5, Floor > 2, Floor <= 5, Floor >= 2

Note the difference: the list uses a single = and the policy uses == for equality.

Numbers are unsigned integers of up to 32 bits. Internally, a comparison becomes a small formula over the bits of the value, so a numeric attribute is represented by as many hidden attributes as it has bits.

Fewer bits: value#bits

If you know a value is small, declare its width to get smaller keys and ciphertexts and faster operations:

Level=5#4               attribute list: Level is a 4-bit number
Level >= 3#4            policy

The width must be between 4 and 32, and the value must fit into it. Both sides of a comparison should use the same width.

Ranges

Syntax Meaning
Floor in (2-5) Floor > 2 and Floor < 5 (exclusive)
Floor in {2-5} Floor >= 2 and Floor <= 5 (inclusive)

The minimum must not exceed the maximum (error 52, INVALID_RANGE_NUMBERS), and both ends must have the same bit width (error 53, INVALID_MISMATCH_BITS).

Dates

Dates are written Month Day, Year. The month can be the full English name or its three-letter abbreviation (January/Jan … December/Dec; May has only one form). Years before 1970 are rejected (error 56).

In the attribute list In a policy
Date = March 7, 2017 Date = March 7, 2017 (that exact day)
Date = March 1-14, 2017 (a range of days within one month)
Date > March 7, 2017, Date < …, Date >= …, Date <= …

The dates are validated, including leap years, so February 30, 2020 is rejected (error 55).

A key policy that combines several periods:

From:Alice and (Date = March 1-14, 2017 or Date = February 22-28, 2017)

Cheat sheet

# attribute lists
Doctor|Nurse|dept:icu
Floor=3|Level=5#4
From:Alice|Date = March 7, 2017

# policies
Doctor and dept:icu
(Doctor or Nurse) and Floor in {2-5}
Level >= 3#4
Date >= January 1, 2024 and Date <= December 31, 2024

When parsing fails

An invalid policy or attribute list makes the crypto box throw ZCryptoBoxException. The CLI exits with the corresponding code. The most common ones are 20 (INVALID_POLICY), 42 (SYNTAX_ERROR_IN_PARSER) and 51 (INVALID_ATTRIBUTE_LIST); the full list is in Error Codes.

Clone this wiki locally