{"id":20315297,"url":"https://github.com/madebypixel02/abe-scalability","last_synced_at":"2026-02-25T08:39:43.569Z","repository":{"id":109077695,"uuid":"484702866","full_name":"madebypixel02/ABE-Scalability","owner":"madebypixel02","description":"[Uc3m] Cybersecurity practice to measure the scalability and complexity of Attribute-Based Encryption","archived":false,"fork":false,"pushed_at":"2022-12-04T15:48:57.000Z","size":6688,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T12:51:47.317Z","etag":null,"topics":["abe","attribute","attribute-based-encryption","c","cpabe","cybersecurity","data","data-protection","makefile","protection","uc3m"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madebypixel02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-23T09:27:06.000Z","updated_at":"2025-01-11T15:28:53.000Z","dependencies_parsed_at":"2023-03-25T01:36:04.957Z","dependency_job_id":null,"html_url":"https://github.com/madebypixel02/ABE-Scalability","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madebypixel02%2FABE-Scalability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madebypixel02%2FABE-Scalability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madebypixel02%2FABE-Scalability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madebypixel02%2FABE-Scalability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madebypixel02","download_url":"https://codeload.github.com/madebypixel02/ABE-Scalability/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241818872,"owners_count":20025210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abe","attribute","attribute-based-encryption","c","cpabe","cybersecurity","data","data-protection","makefile","protection","uc3m"],"created_at":"2024-11-14T18:18:41.944Z","updated_at":"2026-02-25T08:39:38.548Z","avatar_url":"https://github.com/madebypixel02.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- *********************************************************************** --\u003e\n\u003c!--                                                                         --\u003e\n\u003c!--                                +###****.                                --\u003e\n\u003c!--                                =***@@@+                                 --\u003e\n\u003c!--            *%*   -%%:  -*%%%#     :@@@=:   #%##%%#=-*%%%*:              --\u003e\n\u003c!--            %@%   =@@: #@@*=+*.    -==*@@+  @@@*=+@@@%+=#@@=             --\u003e\n\u003c!--            %@%   -@@:-@@-     .==.    *@@. %@#   =@@:   %@#             --\u003e\n\u003c!--            +@@+-=%@@..%@@+--+..%@@+--*@@*  @@#   +@@:   @@#             --\u003e\n\u003c!--             -*%@@#+.   =#%@@%.  -*%@@%*-   %@*   =@@:   %@*             --\u003e\n\u003c!--                                                                         --\u003e\n\u003c!-- README.md                                                               --\u003e\n\u003c!--                                                                         --\u003e\n\u003c!-- By: aperez-b \u003c100429952@alumnos.uc3m.es\u003e                                --\u003e\n\u003c!--                                                                         --\u003e\n\u003c!-- Created: 2022/04/25 07:29:22 by aperez-b                                --\u003e\n\u003c!-- Updated: 2022/12/04 16:48:11 by aperez-b                                --\u003e\n\u003c!--                                                                         --\u003e\n\u003c!-- *********************************************************************** --\u003e\n\n# ABE Scalability | uc3m\n\n*Cybersecurity practice to measure the scalability and complexity of Attribute-Based Encryption 🔧*\n\nBy Alejandro Pérez Bueno (100429952@alumnos.uc3m.es)\n\n### Table of Contents\n\n- [Introduction](#introduction)\n- [Code Implementation](#code-implementation)\n- [Testing the Algorithm](#testing-the-algorithm)\n\t- [Graph](#graph)\n- [How to Run the Program](#how-to-run-the-program)\n\t- [Example](#example)\n- [Summary](#summary)\n\n## Introduction\n\nThe goal for this project is to get familiar with the ``cpabe`` tools for attribute-based encryption. We are asked to code an algorithm that creates various users and their secret keys made from a set of attributes, and later encrypts and decrypts a 5MB pdf file several times. In this practice we will try different combinations of the number of users, attributes and repetitions. The idea is to measure how long it takes to encrypt and decrypt the pdf file depending on these values.\n\n## Code Implementation\n\nI implemented the algorithm for encryption in ``C``, since it is what I'm most comfortable coding in. The project includes a ``Makefile`` with the necessary compliation rules. It will create the executable file ``cp_abe`` inside a ``bin/`` folder. This program always takes three arguments:\n\n\n```\nusage: cp_abe \u003cn_users\u003e \u003cn_attributes\u003e \u003cn_repetitions\u003e\n```\n\nHere is a quick overview of the functions I created:\n\n| Function | Description |\n| :------: | :---------: |\n| ``parse_args`` | Reads arguments from ``argv`` and saves number of users, attributes and repetitions |\n| ``create_dirs`` | Creates ``tests/`` folder where all users' folders will be, and runs ``cpabe-setup`` in ``tests/master/`` |\n| ``config_dirs`` | Creates folder for every user and creates attributes for all of them |\n| ``get_time`` | Returns current ``epoch`` time (seconds since 1970) |\n| ``get_str`` | Adds given index to provided string (eg ``\"user_1\"``, ``\"attr_3\"``, ``\"file_n\"``) |\n| ``wrap_cmd`` | Joins up to three strings together (used to create command strings) |\n| ``crypt_pdf`` | For every ``n_repeat``, encrypts the pdf and then every user decrypts it |\n| ``encrypt_pdf`` | Encrypts pdf file ``file.pdf`` with all attributes as ``file-enc.pdf.cpabe`` |\n| ``decrypt_pdf`` | Decrypts pdf for a given user and saves it to the user's folder |\n| ``ft_putstr_fd`` | Writes a custom string to a file descriptor with ``write`` |\n| ``ft_atoi`` | Converts ascii to int. Reads a string and obtains the equivalent integer value |\n| ``ft_itoa`` | Converts int to ascii. Reads an int and obtains the equivalent string value |\n| ``ft_strdup`` | Returns allocated copy of a string |\n| ``ft_strjoin`` | Joins two strings together in an allocated string |\n| ``ft_substr`` | Returns allocated substring (copies n bytes from ``start`` of the given string) |\n| ``ft_strlen`` | Returns length of a string |\n| ``ft_nbrlen`` | Returns length of a number |\n| ``ft_strlcat`` | Copies ``n - 1`` bytes of a string into another one |\n| ``ft_isspace`` | Returns ``1`` if char is a form of space (same as ``isspace``) |\n| ``ft_putchar_fd`` | Writes a char to a file descriptor |\n| ``ft_putnbr_fd`` | Writes int to a file descriptor |\n\nHere are the builtin functions I used and a quick description of what they do. Check their manpages for more information\n\n| Function | Description |\n| :------: | :---------: |\n| ``system`` | Runs a command from the system (used mainly for cpabe commands) |\n| ``gettimeofday`` | Returns ``epoch`` in a ``timeval`` struct |\n| ``open`` | Opens a file to a file descriptor |\n| ``close`` | Closes a file descriptor |\n| ``write`` | Writes n bytes of memory to a file descriptor |\n| ``printf`` | Prints string to ``stdout`` |\n| ``malloc`` | Allocates bytes of memory to a given pointer |\n| ``free`` | Frees allocated memory from a pointer |\n| ``chdir`` | Changes the system's current working directory (same as ``cd`` in a shell) |\n\n* General Code description\n\nThe code of this practice is hopefully easy to read, but it is actually pretty straightforward. Here is a rough list of the instructions it goes over:\n\n1. Reads arguments from ``argv`` (argument list) to save ``n_usrs``, ``n_attrs`` and ``n_rep``.\n2. Deletes ``tests/`` folder (if present), creates ``tests/master/`` folder, runs ``cpabe-setup`` in it.\n3. In the ``tests/`` folder, creates folder for every user (``user_1``, ``...``, ``user_n``), copies ``pub_key`` and creates ``priv`` key with their attributes (``attr_1``, ``...``, ``attr_n``) using ``cpabe-keygen``.\n4. Opens log file ``log.txt`` in the ``tests/`` folder where basic logging information will be saved.\n5. Stores current time before starting encryption.\n6. Repeats ``n_rep`` times the process of encrypting the file ``file.pdf`` with all attributes and then decrypting it for every user in their user folder as (``file_1.pdf``, ``...``, ``file_n.pdf``)\n7. Stores current time after encryption.\n8. Prints ``end_time`` - ``start_time``, closes ``log.txt`` and exits\n\n\n## Testing the Algorithm\n\nFor this part, we will take a look at the time it takes to encrypt and decrypt a file. We retrieve 20 measurements and compute an average (mean). Then we'll make a graph to better visualize the results.\n\n| No. of Users | No. of Attributes | Avg. Execution Time (s) | Total Execution Time (s) |\n| :----------: | :---------------: | :---------------------: | :----------------------: |\n| 5 | 5 | 0.518 | 11 |\n| 5 | 20 | 0.849 | 17 |\n| 20 | 5 | 1.664 | 35 |\n| 20 | 20 | 2.603 | 54 |\n\nNote: these values are highly dependant on the processing power of the device running the program. It is only interesting to see the variations in time relative to each other, rather than the actual numbers.\n\n* Key Sizes\n\nTo view the key sizes, I thought I'd use something like the following:\n\n```\ncat -e tests/master/master_key | wc -c\n```\n\nMaster Key Size (bytes): 325\n\n| No. of Attributes | Secret Key Size |\n| :---------------: | :-------------: |\n| 5 | 3288 |\n| 20 | 12340 |\n| 50 | 30771 |\n\nAs we can see, the key size increases very fast as the number of attributes goes up.\n\n### Graph\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=https://user-images.githubusercontent.com/40824677/165148450-84626023-6012-4ec9-9b38-32140598ae0d.png /\u003e\n\u003c/div\u003e\n\nNote: I added a few extra rows of data to the graph for better visualization.\n\nFrom the graph we can see a clear pattern. As expected, the more users and attributes, the longer it will take to encrypt and decrypt the file. However, we can see that changing the number of attributes doesn't affect the performance of the encryption nearly as much as increasing the number of users does. This is easily seen with the case of 5 users and 50 attributes, which roughly takes 30 (1.469s on average) seconds to finish. However, the inverse case of 50 users and 5 attributes per user takes more than double the time, taking almost 90 seconds (3.94s on average) to complete.\n\nThus, we can confidently say that it will be computationally less feasible to have 1k users than having 1k attributes per user.\n\n## How to Run the Program\n\n* Installation\n\nIn order to run this practice, you must install some packages on your system. To build the packages, you must first install these dependencies:\n\n```shell\nsudo apt -y install make gcc g++ autoconf libc6 libpcre3 flex bison libgmp-dev libssl-dev libglib2.0-dev help2man\n```\n\nOnce those dependencies are satisfied, follow these steps to build the required packages on your system (needs root/sudo)\n\n```shell\n# pbc\nwget https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz\ntar zxvf pbc-0.5.14.tar.gz; cd pbc-0.5.14\nautoconf\n./configure\nmake\nsudo make install\ncd ..\n\n# libbswabe\nwget http://acsc.cs.utexas.edu/cpabe/libbswabe-0.9.tar.gz\ntar zxvf libbswabe-0.9.tar.gz; cd libbswabe-0.9\n./configure\nmake\nsudo make install\ncd ..\n\n# cpabe\nwget http://acsc.cs.utexas.edu/cpabe/cpabe-0.11.tar.gz\ntar zxvf cpabe-0.11.tar.gz; cd cpabe-0.11\n./configure --with-pbc-include=/usr/local/include/pbc --with-pbc-lib=/usr/local/lib\nsed -e '67 s/\\$1/\\$1;/' policy_lang.y \u003e temp\nmv temp policy_lang.y\nsed -e '89 s/help2man/help2man --no-discard-stderr/' Makefile \u003e temp\nmv temp Makefile\nmake LDFLAGS=\"-lgmp -lpbc -lcrypto -L/usr/lib/x86_64-linux-gnu -lglib-2.0 -lbswabe -lgmp\"\nsudo make LDFLAGS=\"-lgmp -lpbc -lcrypto -L/usr/lib/x86_64-linux-gnu -lglib-2.0 -lbswabe -lgmp\" install\ncd ..\n```\n\nTo make things work, you might need to specify the proper path for the ``LD_LIBRARY_PATH`` environment variable:\n\n```shell\nexport LD_LIBRARY_PATH=/usr/local/lib\necho \"export LD_LIBRARY_PATH=/usr/local/lib\" \u003e\u003e ~/.bashrc\necho \"export LD_LIBRARY_PATH=/usr/local/lib\" \u003e\u003e ~/.zshrc\n```\n\n\n* Usage\n\nAs previously mentioned, this project includes a Makefile with all the needed instructions, here's an overview of the commands you can use:\n\n```\nmake/make all\t\tcompiles executable cp_abe to bin/ directory\nmake clean\t\tcleans object files in obj/ directory\nmake fclean\t\tcalls clean rule and deletes cp_abe executable\nmake re\t\t\tcleans up everything and compiles again\nmake norminette\t\tRuns C linter (norminette) on all required files\n```\n\nThe Makefile compliles the executable ``cp_abe`` to a folder called ``bin/``. To run the file, specify the path to the executable:\n\n```\n./bin/cp_abe 5 5 20\n```\nNote: if you get an error saying permission denied, enter ``chmod +x ./bin/cp_abe`` and try again\n\n### Example\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=https://user-images.githubusercontent.com/40824677/165149048-a2af70c0-5b18-45d0-92d7-2e1039fa5012.png /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=https://user-images.githubusercontent.com/40824677/165149061-8266a32b-3a61-41db-8968-ac92cf6c0a8b.png /\u003e\n\u003c/div\u003e\n\n## Summary\n\nAll in all, this project was fun to code and it helped me understand the basics of attribute-based encryption and how it scales with larger users and attributes per user :)\n\nApril 25th, 2022\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadebypixel02%2Fabe-scalability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadebypixel02%2Fabe-scalability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadebypixel02%2Fabe-scalability/lists"}