') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); cipher: add encrypt/decrypt-only block cipher traits by tarcieri · Pull Request #352 · RustCrypto/traits · GitHub
Skip to content

cipher: add encrypt/decrypt-only block cipher traits - #352

Merged
tarcieri merged 3 commits into
masterfrom
cipher/encrypt-and-decrypt-only-block-cipher-traits
Nov 24, 2020
Merged

cipher: add encrypt/decrypt-only block cipher traits#352
tarcieri merged 3 commits into
masterfrom
cipher/encrypt-and-decrypt-only-block-cipher-traits

Conversation

@tarcieri

@tarcieritarcieri commented Nov 1, 2020

Copy link
Copy Markdown
Member

Closes#349

Adds BlockEncrypt and BlockDecrypt traits which can be used in cases where e.g. only the encryption portion of a block cipher is used, as in CTR mode.

This PR does not otherwise attempt to add things like a blanket impl.

@tarcieri

tarcieri commented Nov 1, 2020

Copy link
Copy Markdown
MemberAuthor

Note: I used the new suggested method names here: *_block, *_par_blocks, *_blocks.

Perhaps it would make more sense to leave them the same for consistency for now, then change them all in the next breaking release.

Comment threadcipher/src/block.rs Outdated
Comment threadcipher/src/block.rs Outdated
@tarcieri
tarcieriforce-pushed the cipher/encrypt-and-decrypt-only-block-cipher-traits branch from 0bf6fd0 to 59097ccCompareNovember 1, 2020 16:30
@tarcieri

Copy link
Copy Markdown
MemberAuthor

After a few attempts at eliminating the redundancy, I think it might make more sense to transform the BlockCipher trait (via a breaking change) into a marker trait for the case where a type impls both Encrypt and Decrypt with compatible BlockSize/ParBlocks.

@newpavlovnewpavlov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't Encrypt/Decrypt too generic? It could be worth to use something like BlockEncrypt instead of block::Encrypt. Such naming would also allow us to simplify the crate structure by removing stream and block modules.

Comment threadcipher/src/block.rs Outdated
@tarcieri

Copy link
Copy Markdown
MemberAuthor

It could be worth to use something like BlockEncrypt instead of block::Encrypt. Such naming would also allow us to simplify the crate structure by removing stream and block modules.

That's a potential alternative, yes. I think it makes sense for the code to still be factored into two modules, but we could re-export everything at the toplevel rather than using modules.

@tarcieri

Copy link
Copy Markdown
MemberAuthor

In 5096a41 I renamed the traits to BlockEncrypt and BlockDecrypt, and added a BlockSizeMarker trait for carrying the BlockSize associated type/constant.

@newpavlov

Copy link
Copy Markdown
Member

I think it makes sense for the code to still be factored into two modules

I agree, I meant how API will look on outside.

@tarcieri

Copy link
Copy Markdown
MemberAuthor

@newpavlov does this look ok now, or would you rather hold off until cipher v0.3?

@newpavlov

Copy link
Copy Markdown
Member

I think it will be better to release these changes in v0.3.

Closes#349
Adds `Encrypt` and `Decrypt` traits which can be used in cases where
e.g. only the encryption portion of a block cipher is used, as in
CTR mode.
This PR does not otherwise attempt to add things like a blanket impl.
Adds a single trait for carrying the `BlockSize` associated
type/constant.
Prefixes `Encrypt` and `Decrypt` traits with `Block*`, i.e.
`BlockEncrypt` and `BlockDecrypt`.
@tarcieri
tarcieriforce-pushed the cipher/encrypt-and-decrypt-only-block-cipher-traits branch from 5096a41 to 2c61ca2CompareNovember 23, 2020 15:34
@tarcieri

tarcieri commented Nov 23, 2020

Copy link
Copy Markdown
MemberAuthor

@newpavlov I've gone ahead and made the discussed breaking changes (targeting cipher v0.3) in 2c61ca2, including splitting BlockCipherMut into BlockEncryptMut and BlockDecryptMut which require the given type impls BlockCipher.

This had the added benefit of eliminating the need for a stream::FromBlockCipherMut trait.

@tarcieri
tarcieriforce-pushed the cipher/encrypt-and-decrypt-only-block-cipher-traits branch from 2c61ca2 to 72593c0CompareNovember 24, 2020 14:23
@tarcieri
tarcieri merged commit 590f545 into masterNov 24, 2020
@tarcieri
tarcieri deleted the cipher/encrypt-and-decrypt-only-block-cipher-traits branch November 24, 2020 14:28
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 24, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 24, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 24, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 25, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 25, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
@tarcieritarcieri mentioned this pull request Dec 9, 2020
2 tasks
@tarcieritarcieri mentioned this pull request Apr 28, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cipher: traits for encrypt-only (and decrypt-only) block ciphers?

2 participants

@tarcieri@newpavlov