Skip to content

Instantly share code, notes, and snippets.

@larshp
Last active April 9, 2024 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larshp/22ed18c0c704cdbd8ed73c0dc90279ed to your computer and use it in GitHub Desktop.
Save larshp/22ed18c0c704cdbd8ed73c0dc90279ed to your computer and use it in GitHub Desktop.
Mask generation function in ABAP
METHOD mgf1.
* https://en.wikipedia.org/wiki/Mask_generation_function
DATA lv_counter TYPE i.
DATA lv_sha1 TYPE xstring.
DATA lv_xstr TYPE xstring.
DATA lv_c TYPE x LENGTH 4.
WHILE xstrlen( rv_mask ) < iv_length.
* Convert counter to an octet string C of length 4
lv_c = lv_counter.
CONCATENATE iv_seed lv_c INTO lv_xstr IN BYTE MODE.
cl_abap_message_digest=>calculate_hash_for_raw(
EXPORTING
if_data = lv_xstr
IMPORTING
ef_hashxstring = lv_sha1 ).
* Concatenate the hash of the seed Z and C to the octet string
CONCATENATE rv_mask lv_sha1 INTO rv_mask IN BYTE MODE.
lv_counter = lv_counter + 1.
ENDWHILE.
rv_mask = rv_mask(iv_length).
ENDMETHOD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment